evm

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2025 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COMPONENT_NAME = "EvmClient"
	RETRY_INTERVAL = time.Second * 12 // Initial retry interval
)

Variables

Functions

func AbiUnpack

func AbiUnpack(data []byte, types ...string) ([]interface{}, error)

func AbiUnpackIntoMap

func AbiUnpackIntoMap(v map[string]interface{}, data []byte, types ...byte) error

func CreateEvmAuth

func CreateEvmAuth(evmConfig *EvmNetworkConfig) (*bind.TransactOpts, error)

func CreateGateway

func CreateGateway(networName string, gwAddr string, client *ethclient.Client) (*contracts.IScalarGateway, *common.Address, error)

func GetMissingEvents

func GetMissingEvents[T ValidEvmEvent](c *EvmClient, eventName string, lastCheckpoint *scalarnet.EventCheckPoint, fnCreateEventData func(types.Log) T) ([]*parser.EvmEvent[T], error)

Get missing events from the last checkpoint block number to the current block number In query we filter out the event with index equal to the last checkpoint log index

func RecoverEvent

func RecoverEvent[T ValidEvmEvent](c *EvmClient, ctx context.Context, eventName string, fnCreateEventData func(types.Log) T) error

Try to recover missing events from the last checkpoint block number to the current block number

func WatchForEvent

func WatchForEvent[T ValidWatchEvent](c *EvmClient, ctx context.Context, eventName string) error

Types

type ApproveContractCall

type ApproveContractCall struct {
	ChainId    uint64
	CommandIds [][32]byte
	Commands   []string
	Params     [][]byte
}

func DecodeApproveContractCall

func DecodeApproveContractCall(input []byte) (*ApproveContractCall, error)

type Byte32

type Byte32 [32]uint8

type Bytes

type Bytes []byte

type DecodedExecuteData

type DecodedExecuteData struct {
	//Data
	ChainId    uint64
	CommandIds [][32]byte
	Commands   []string
	Params     [][]byte
	//Proof
	Operators  []common.Address
	Weights    []uint64
	Threshold  uint64
	Signatures []string
	//Input
	Input []byte
}

func DecodeExecuteData

func DecodeExecuteData(executeData string) (*DecodedExecuteData, error)

func DecodeInput

func DecodeInput(input []byte) (*DecodedExecuteData, error)

type DeployToken

type DeployToken struct {
	//Data
	Name         string
	Symbol       string
	Decimals     uint8
	Cap          uint64
	TokenAddress common.Address
	MintLimit    uint64
}

func DecodeDeployToken

func DecodeDeployToken(input []byte) (*DeployToken, error)

type EvmClient

type EvmClient struct {
	EvmConfig      *EvmNetworkConfig
	Client         *ethclient.Client
	ScalarClient   *scalar.Client
	ChainName      string
	GatewayAddress common.Address
	Gateway        *contracts.IScalarGateway

	MissingLogs MissingLogs
	// contains filtered or unexported fields
}

func NewEvmClient

func NewEvmClient(globalConfig *config.Config, evmConfig *EvmNetworkConfig, dbAdapter *db.DatabaseAdapter, eventBus *events.EventBus, scalarClient *scalar.Client) (*EvmClient, error)

func NewEvmClients

func NewEvmClients(globalConfig *config.Config, dbAdapter *db.DatabaseAdapter, eventBus *events.EventBus, scalarClient *scalar.Client) ([]*EvmClient, error)

func (*EvmClient) AddPendingTx

func (c *EvmClient) AddPendingTx(txHash string, timestamp time.Time)

func (*EvmClient) AppendLogs

func (c *EvmClient) AppendLogs(logs []types.Log)

func (*EvmClient) CommandExecutedEvent2Model

func (c *EvmClient) CommandExecutedEvent2Model(event *contracts.IScalarGatewayExecuted) chains.CommandExecuted

func (*EvmClient) ConnectWithRetry

func (c *EvmClient) ConnectWithRetry(ctx context.Context)

func (*EvmClient) ContractCallApprovedEvent2Model

func (c *EvmClient) ContractCallApprovedEvent2Model(event *contracts.IScalarGatewayContractCallApproved) (scalarnet.ContractCallApproved, error)

func (*EvmClient) ContractCallEvent2Model

func (c *EvmClient) ContractCallEvent2Model(event *contracts.IScalarGatewayContractCall) (chains.ContractCall, error)

func (*EvmClient) ContractCallWithToken2Model

func (*EvmClient) ExecuteDestinationCall

func (ec *EvmClient) ExecuteDestinationCall(
	contractAddress common.Address,
	commandId [32]byte,
	sourceChain string,
	sourceAddress string,
	payload []byte,
) (*ethtypes.Transaction, error)

func (*EvmClient) GetTokenContractAddressFromSymbol

func (c *EvmClient) GetTokenContractAddressFromSymbol(chainId string, symbol string) string

Todo: Implement this function

func (*EvmClient) HandleCommandExecuted

func (ec *EvmClient) HandleCommandExecuted(event *contracts.IScalarGatewayExecuted) error

func (*EvmClient) HandleContractCallApproved

func (ec *EvmClient) HandleContractCallApproved(event *contracts.IScalarGatewayContractCallApproved) error

func (*EvmClient) HandleContractCallWithToken

func (ec *EvmClient) HandleContractCallWithToken(event *contracts.IScalarGatewayContractCallWithToken) error

func (*EvmClient) HandleTokenDeployed

func (ec *EvmClient) HandleTokenDeployed(event *contracts.IScalarGatewayTokenDeployed) error

func (*EvmClient) HandleTokenSent

func (ec *EvmClient) HandleTokenSent(event *contracts.IScalarGatewayTokenSent) error

func (*EvmClient) ListenToEvents

func (c *EvmClient) ListenToEvents(ctx context.Context) error

func (*EvmClient) PollTxForEvents

func (c *EvmClient) PollTxForEvents(pendingTx pending.PendingTx) (*parser.AllEvmEvents, error)

func (*EvmClient) ProcessMissingLogs

func (c *EvmClient) ProcessMissingLogs()

Go routine for process missing logs

func (*EvmClient) RecoverAllEvents

func (c *EvmClient) RecoverAllEvents(ctx context.Context) error

func (*EvmClient) RecoverApprovedEvents

func (c *EvmClient) RecoverApprovedEvents(ctx context.Context) error

func (*EvmClient) RecoverEvents

func (c *EvmClient) RecoverEvents(ctx context.Context, eventNames []string) error

func (*EvmClient) RecoverExecutedEvents

func (c *EvmClient) RecoverExecutedEvents(ctx context.Context) error

func (*EvmClient) RecoverInitiatedEvents

func (c *EvmClient) RecoverInitiatedEvents(ctx context.Context) error

* Recover initiated events

func (*EvmClient) SetAuth

func (c *EvmClient) SetAuth(auth *bind.TransactOpts)

func (*EvmClient) Start

func (c *EvmClient) Start(ctx context.Context) error

func (*EvmClient) SubmitTx

func (ec *EvmClient) SubmitTx(signedTx *ethtypes.Transaction, retryAttempt int) (*ethtypes.Receipt, error)

func (*EvmClient) TokenDeployedEvent2Model

func (c *EvmClient) TokenDeployedEvent2Model(event *contracts.IScalarGatewayTokenDeployed) chains.TokenDeployed

func (*EvmClient) TokenSentEvent2Model

func (c *EvmClient) TokenSentEvent2Model(event *contracts.IScalarGatewayTokenSent) (chains.TokenSent, error)

func (*EvmClient) UpdateLastCheckPoint

func (c *EvmClient) UpdateLastCheckPoint(events map[string]abi.Event, logs []types.Log, lastBlock uint64)

func (*EvmClient) VerifyDeployTokens

func (c *EvmClient) VerifyDeployTokens(ctx context.Context) error

func (*EvmClient) WaitForTransaction

func (ec *EvmClient) WaitForTransaction(hash string) (*ethtypes.Receipt, error)

type EvmNetworkConfig

type EvmNetworkConfig struct {
	ChainID      uint64        `mapstructure:"chain_id"`
	ID           string        `mapstructure:"id"`
	Name         string        `mapstructure:"name"`
	RPCUrl       string        `mapstructure:"rpc_url"`
	Gateway      string        `mapstructure:"gateway"`
	Finality     int           `mapstructure:"finality"`
	LastBlock    uint64        `mapstructure:"last_block"`
	PrivateKey   string        `mapstructure:"private_key"`
	GasLimit     uint64        `mapstructure:"gas_limit"`
	BlockTime    time.Duration `mapstructure:"blockTime"` //Timeout im ms for pending txs
	MaxRetry     int
	RecoverRange uint64 `mapstructure:"recover_range"` //Max block range to recover events in single query
	RetryDelay   time.Duration
	TxTimeout    time.Duration `mapstructure:"tx_timeout"` //Timeout for send txs (~3s)
}

func (*EvmNetworkConfig) GetChainId

func (c *EvmNetworkConfig) GetChainId() uint64

func (*EvmNetworkConfig) GetFamily

func (c *EvmNetworkConfig) GetFamily() string

func (*EvmNetworkConfig) GetId

func (c *EvmNetworkConfig) GetId() string

func (*EvmNetworkConfig) GetName

func (c *EvmNetworkConfig) GetName() string

type ExecuteData

type ExecuteData[T any] struct {
	//Data
	Data T
	//Proof
	Operators  []common.Address
	Weights    []uint64
	Threshold  uint64
	Signatures []string
	//Input
	Input []byte
}

type MissingLogs

type MissingLogs struct {
	Recovered atomic.Bool //True if logs are recovered
	// contains filtered or unexported fields
}

func (*MissingLogs) AppendLogs

func (m *MissingLogs) AppendLogs(logs []ethTypes.Log)

func (*MissingLogs) GetLogs

func (m *MissingLogs) GetLogs(count int) []ethTypes.Log

func (*MissingLogs) IsRecovered

func (m *MissingLogs) IsRecovered() bool

func (*MissingLogs) SetRecovered

func (m *MissingLogs) SetRecovered(recovered bool)

Directories

Path Synopsis
contracts

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL