eth

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: BlueOak-1.0.0 Imports: 34 Imported by: 0

Documentation

Overview

Package eth implements methods to work with ethereum swap contracts and transactions. The LGPL is a more restrictive license that may be more of a burden for closed source software.

Index

Constants

View Source
const (
	BipID = 60
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetBackend

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

AssetBackend is an asset backend for Ethereum. It has methods for fetching output information and subscribing to block updates. AssetBackend implements asset.Backend, so provides exported methods for DEX-related blockchain info.

func (*AssetBackend) AccountBalance

func (be *AssetBackend) AccountBalance(addrStr string) (uint64, error)

AccountBalance retrieves the current account balance, including the effects of known unmined transactions.

func (*AssetBackend) BlockChannel

func (be *AssetBackend) BlockChannel(size int) <-chan *asset.BlockUpdate

BlockChannel creates and returns a new channel on which to receive block updates. If the returned channel is ever blocking, there will be no error logged from the eth package. Part of the asset.Backend interface.

func (AssetBackend) CheckSwapAddress

func (eth AssetBackend) CheckSwapAddress(addr string) bool

CheckSwapAddress checks that the given address is parseable.

func (*AssetBackend) Contract

func (be *AssetBackend) Contract(coinID, contractData []byte) (*asset.Contract, error)

Contract is part of the asset.Backend interface. The contractData bytes encodes both the contract version targeted and the secret hash.

func (AssetBackend) FeeRate

func (eth AssetBackend) FeeRate(ctx context.Context) (uint64, error)

FeeRate returns the current optimal fee rate in gwei / gas.

func (AssetBackend) Info

func (AssetBackend) Info() *asset.BackendInfo

Info provides some general information about the backend.

func (*AssetBackend) InitTxSize

func (be *AssetBackend) InitTxSize() uint64

InitTxSize is an upper limit on the gas used for an initiation.

func (*AssetBackend) RedeemSize

func (be *AssetBackend) RedeemSize() uint64

RedeemSize is the same as (dex.Asset).RedeemSize for the asset.

func (*AssetBackend) Redemption

func (be *AssetBackend) Redemption(redeemCoinID, _, contractData []byte) (asset.Coin, error)

Redemption returns a coin that represents a contract redemption. redeemCoinID should be the transaction that sent a redemption, while contractCoinID is the swap contract this redemption redeems.

func (AssetBackend) Synced

func (eth AssetBackend) Synced() (bool, error)

Synced is true if the blockchain is ready for action.

func (AssetBackend) TxData

func (eth AssetBackend) TxData(coinID []byte) ([]byte, error)

TxData fetches the raw transaction data.

func (AssetBackend) ValidateCoinID

func (eth AssetBackend) ValidateCoinID(coinID []byte) (string, error)

ValidateCoinID attempts to decode the coinID.

func (AssetBackend) ValidateFeeRate

func (eth AssetBackend) ValidateFeeRate(coin asset.Coin, reqFeeRate uint64) bool

ValidateFeeRate checks that the transaction fees used to initiate the contract are sufficient. For most assets only the contract.FeeRate() cannot be less than reqFeeRate, but for Eth, the gasTipCap must also be checked.

func (AssetBackend) ValidateSecret

func (eth AssetBackend) ValidateSecret(secret, contractData []byte) bool

ValidateSecret checks that the secret satisfies the secret hash.

func (AssetBackend) ValidateSignature

func (eth AssetBackend) ValidateSignature(addr string, pubkey, msg, sig []byte) error

ValidateSignature checks that the pubkey is correct for the address and that the signature shows ownership of the associated private key.

type ContextCaller

type ContextCaller interface {
	CallContext(ctx context.Context, result any, method string, args ...any) error
}

type Driver

type Driver struct {
	DriverBase
}

Driver implements asset.Driver.

func (*Driver) Setup

func (d *Driver) Setup(cfg *asset.BackendConfig) (asset.Backend, error)

Setup creates the ETH backend. Start the backend with its Run method.

type DriverBase added in v1.0.0

type DriverBase struct {
	UI  dex.UnitInfo
	Ver uint32
	Nam string
}

func (*DriverBase) DecodeCoinID added in v1.0.0

func (d *DriverBase) DecodeCoinID(coinID []byte) (string, error)

DecodeCoinID creates a human-readable representation of a coin ID for Ethereum. This must be a transaction hash.

func (*DriverBase) Name added in v1.0.0

func (d *DriverBase) Name() string

Name is the asset's name.

func (*DriverBase) UnitInfo added in v1.0.0

func (d *DriverBase) UnitInfo() dex.UnitInfo

UnitInfo returns the dex.UnitInfo for the asset.

func (*DriverBase) Version added in v1.0.0

func (d *DriverBase) Version() uint32

Version returns the Backend implementation's version number.

type ETHBackend

type ETHBackend struct {
	*AssetBackend
}

ETHBackend implements some Ethereum-specific methods.

func NewEVMBackend added in v1.0.0

func NewEVMBackend(
	cfg *asset.BackendConfig,
	chainID uint64,
	contractAddrs map[uint32]map[dex.Network]common.Address,
	vTokens map[uint32]*VersionedToken,
) (*ETHBackend, error)

NewEVMBackend is the exported constructor by which the DEX will import the Backend.

func (ETHBackend) CheckSwapAddress

func (eth ETHBackend) CheckSwapAddress(addr string) bool

CheckSwapAddress checks that the given address is parseable.

func (*ETHBackend) Connect

func (eth *ETHBackend) Connect(ctx context.Context) (*sync.WaitGroup, error)

Connect connects to the node RPC server and initializes some variables.

func (ETHBackend) FeeRate

func (eth ETHBackend) FeeRate(ctx context.Context) (uint64, error)

FeeRate returns the current optimal fee rate in gwei / gas.

func (ETHBackend) Info

func (ETHBackend) Info() *asset.BackendInfo

Info provides some general information about the backend.

func (ETHBackend) Synced

func (eth ETHBackend) Synced() (bool, error)

Synced is true if the blockchain is ready for action.

func (*ETHBackend) TokenBackend

func (eth *ETHBackend) TokenBackend(assetID uint32, configPath string) (asset.Backend, error)

TokenBackend creates an *AssetBackend for a token. Part of the asset.TokenBacker interface. Do not call TokenBackend concurrently for the same asset.

func (ETHBackend) TxData

func (eth ETHBackend) TxData(coinID []byte) ([]byte, error)

TxData fetches the raw transaction data.

func (ETHBackend) ValidateCoinID

func (eth ETHBackend) ValidateCoinID(coinID []byte) (string, error)

ValidateCoinID attempts to decode the coinID.

func (*ETHBackend) ValidateContract

func (eth *ETHBackend) ValidateContract(contractData []byte) error

ValidateContract ensures that contractData encodes both the expected contract version and a secret hash.

func (ETHBackend) ValidateFeeRate

func (eth ETHBackend) ValidateFeeRate(coin asset.Coin, reqFeeRate uint64) bool

ValidateFeeRate checks that the transaction fees used to initiate the contract are sufficient. For most assets only the contract.FeeRate() cannot be less than reqFeeRate, but for Eth, the gasTipCap must also be checked.

func (ETHBackend) ValidateSecret

func (eth ETHBackend) ValidateSecret(secret, contractData []byte) bool

ValidateSecret checks that the secret satisfies the secret hash.

func (ETHBackend) ValidateSignature

func (eth ETHBackend) ValidateSignature(addr string, pubkey, msg, sig []byte) error

ValidateSignature checks that the pubkey is correct for the address and that the signature shows ownership of the associated private key.

type RPCTransaction

type RPCTransaction struct {
	Value     *hexutil.Big    `json:"value"`
	Gas       hexutil.Uint64  `json:"gas"`
	GasPrice  *hexutil.Big    `json:"gasPrice"`
	GasFeeCap *hexutil.Big    `json:"maxFeePerGas,omitempty"`
	Hash      common.Hash     `json:"hash"`
	To        *common.Address `json:"to"`
	Input     hexutil.Bytes   `json:"input"`
}

type TokenBackend

type TokenBackend struct {
	*AssetBackend
	*VersionedToken
}

TokenBackend implements some token-specific methods.

func (TokenBackend) CheckSwapAddress

func (eth TokenBackend) CheckSwapAddress(addr string) bool

CheckSwapAddress checks that the given address is parseable.

func (*TokenBackend) Connect

func (eth *TokenBackend) Connect(ctx context.Context) (*sync.WaitGroup, error)

Connect for TokenBackend just waits for context cancellation and closes the WaitGroup.

func (TokenBackend) FeeRate

func (eth TokenBackend) FeeRate(ctx context.Context) (uint64, error)

FeeRate returns the current optimal fee rate in gwei / gas.

func (TokenBackend) Info

func (TokenBackend) Info() *asset.BackendInfo

Info provides some general information about the backend.

func (TokenBackend) Synced

func (eth TokenBackend) Synced() (bool, error)

Synced is true if the blockchain is ready for action.

func (TokenBackend) TxData

func (eth TokenBackend) TxData(coinID []byte) ([]byte, error)

TxData fetches the raw transaction data.

func (TokenBackend) ValidateCoinID

func (eth TokenBackend) ValidateCoinID(coinID []byte) (string, error)

ValidateCoinID attempts to decode the coinID.

func (*TokenBackend) ValidateContract

func (eth *TokenBackend) ValidateContract(contractData []byte) error

ValidateContract ensures that contractData encodes both the expected swap contract version and a secret hash.

func (TokenBackend) ValidateFeeRate

func (eth TokenBackend) ValidateFeeRate(coin asset.Coin, reqFeeRate uint64) bool

ValidateFeeRate checks that the transaction fees used to initiate the contract are sufficient. For most assets only the contract.FeeRate() cannot be less than reqFeeRate, but for Eth, the gasTipCap must also be checked.

func (TokenBackend) ValidateSecret

func (eth TokenBackend) ValidateSecret(secret, contractData []byte) bool

ValidateSecret checks that the secret satisfies the secret hash.

func (TokenBackend) ValidateSignature

func (eth TokenBackend) ValidateSignature(addr string, pubkey, msg, sig []byte) error

ValidateSignature checks that the pubkey is correct for the address and that the signature shows ownership of the associated private key.

type TokenDriver

type TokenDriver struct {
	DriverBase
	Token *dex.Token
}

func (*TokenDriver) TokenInfo

func (d *TokenDriver) TokenInfo() *dex.Token

TokenInfo returns details for a token asset.

type VersionedToken added in v1.0.0

type VersionedToken struct {
	*dexeth.Token
	Ver uint32
}

Jump to

Keyboard shortcuts

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