ethereum

package
v0.0.0-...-ddfbed8 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrLogNotFound is returned by GetDeposit when the log
	// with the given block index cannot be found
	ErrLogNotFound = fmt.Errorf("log not found")
	// ErrLogNotFromBridge is returned by GetDeposit when the log
	// with the given block index is not emitted from the bridge contract
	ErrLogNotFromBridge = fmt.Errorf("log is not from bridge")
	// ErrLogNotDepositEvent is returned by GetDeposit when the log
	// with the given block index is not a DepositETH or DepositERC20 event
	ErrLogNotDepositEvent = fmt.Errorf("log is not a deposit event")
	// ErrTxHashNotFound is returned by GetDeposit when the given transaction
	// hash is not found
	ErrTxHashNotFound = fmt.Errorf("deposit tx hash not found")
)

Functions

func DepositID

func DepositID(txHash string, logIndex uint) string

DepositID returns a globally unique id for a given deposit

func IsInvalidGetDepositRequest

func IsInvalidGetDepositRequest(err error) bool

IsInvalidGetDepositRequest returns true if the given error from GetDeposit indicates that the provided transaction hash or log index is invalid

Types

type Block

type Block struct {
	// Number is the sequence number of the block
	Number uint64
	// Time is the timestamp when the block was executed
	Time time.Time
}

Block represents an ethereum block

type Deposit

type Deposit struct {
	// Token is the address (0x0 in the case that eth was deposited)
	// of the tokens which were deposited to the bridge
	Token common.Address
	// Sender is the address of the account which deposited the tokens
	Sender common.Address
	// Destination is the intended recipient of the bridge transfer
	Destination *big.Int
	// Amount is the amount of tokens which were deposited to the bridge
	// contract
	Amount *big.Int
	// TxHash is the hash of the transaction containing the deposit
	TxHash common.Hash
	// LogIndex is the log index within the ethereum block of the deposit event
	// emitted by the bridge contract
	LogIndex uint
	// BlockNumber is the sequence number of the block containing the deposit
	// transaction
	BlockNumber uint64
	// Time is the timestamp of the deposit
	Time time.Time
}

Deposit is a deposit to the bridge smart contract

type Observer

type Observer struct {
	// contains filtered or unexported fields
}

Observer is used to inspect the ethereum blockchain to for all information relevant to bridge interactions

func NewObserver

func NewObserver(client *ethclient.Client, bridgeAddress string) (Observer, error)

NewObserver constructs a new Observer instance

func (Observer) GetBlockByNumber

func (o Observer) GetBlockByNumber(ctx context.Context, blockNumber uint64) (Block, error)

GetBlockByNumber finds an ethereum block by its sequence number

func (Observer) GetDeposit

func (o Observer) GetDeposit(
	ctx context.Context, txHash string, logIndex uint,
) (Deposit, error)

GetDeposit returns a Deposit instance identified by the given transaction hash and log index

func (Observer) GetLatestBlock

func (o Observer) GetLatestBlock(ctx context.Context) (Block, error)

GetLatestBlock returns the latest ethereum block

func (Observer) GetRequestStatus

func (o Observer) GetRequestStatus(ctx context.Context, requestID common.Hash) (RequestStatus, error)

GetRequestStatus calls the requestStatus() view function on the bridge contract to determine the status of a bridge withdrawal

type RequestStatus

type RequestStatus struct {
	// Fulfilled is true if the withdrawal was executed
	Fulfilled bool
	// BlockNumber is the latst block at the time the
	// request status was queried
	BlockNumber uint64
}

RequestStatus is the status of a withdrawal on the bridge contract

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

Signer represents an ethereum validator account which is authorized to approve withdrawals from the bridge smart contract.

func NewSigner

func NewSigner(privateKey string, bridgeConfigVersion uint32) (Signer, error)

NewSigner constructs a new Signer instance

func (Signer) Address

func (s Signer) Address() common.Address

Address returns the ethereum address corresponding to the public key of the signer

func (Signer) SignWithdrawal

func (s Signer) SignWithdrawal(
	id common.Hash,
	expiration int64,
	recipient,
	token common.Address,
	amount *big.Int,
) ([]byte, error)

SignWithdrawal returns a signature for the given withdrawal request

Jump to

Keyboard shortcuts

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