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
- type AssetBackend
- func (be *AssetBackend) AccountBalance(addrStr string) (uint64, error)
- func (be *AssetBackend) BlockChannel(size int) <-chan *asset.BlockUpdate
- func (eth AssetBackend) CheckSwapAddress(addr string) bool
- func (be *AssetBackend) Contract(coinID, contractData []byte) (*asset.Contract, error)
- func (eth AssetBackend) FeeRate(ctx context.Context) (uint64, error)
- func (AssetBackend) Info() *asset.BackendInfo
- func (be *AssetBackend) InitTxSize() uint64
- func (be *AssetBackend) RedeemSize() uint64
- func (be *AssetBackend) Redemption(redeemCoinID, _, contractData []byte) (asset.Coin, error)
- func (eth AssetBackend) Synced() (bool, error)
- func (eth AssetBackend) TxData(coinID []byte) ([]byte, error)
- func (eth AssetBackend) ValidateCoinID(coinID []byte) (string, error)
- func (eth AssetBackend) ValidateFeeRate(coin asset.Coin, reqFeeRate uint64) bool
- func (eth AssetBackend) ValidateSecret(secret, contractData []byte) bool
- func (eth AssetBackend) ValidateSignature(addr string, pubkey, msg, sig []byte) error
- type ContextCaller
- type Driver
- type DriverBase
- type ETHBackend
- func (eth ETHBackend) CheckSwapAddress(addr string) bool
- func (eth *ETHBackend) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (eth ETHBackend) FeeRate(ctx context.Context) (uint64, error)
- func (ETHBackend) Info() *asset.BackendInfo
- func (eth ETHBackend) Synced() (bool, error)
- func (eth *ETHBackend) TokenBackend(assetID uint32, configPath string) (asset.Backend, error)
- func (eth ETHBackend) TxData(coinID []byte) ([]byte, error)
- func (eth ETHBackend) ValidateCoinID(coinID []byte) (string, error)
- func (eth *ETHBackend) ValidateContract(contractData []byte) error
- func (eth ETHBackend) ValidateFeeRate(coin asset.Coin, reqFeeRate uint64) bool
- func (eth ETHBackend) ValidateSecret(secret, contractData []byte) bool
- func (eth ETHBackend) ValidateSignature(addr string, pubkey, msg, sig []byte) error
- type RPCTransaction
- type TokenBackend
- func (eth TokenBackend) CheckSwapAddress(addr string) bool
- func (eth *TokenBackend) Connect(ctx context.Context) (*sync.WaitGroup, error)
- func (eth TokenBackend) FeeRate(ctx context.Context) (uint64, error)
- func (TokenBackend) Info() *asset.BackendInfo
- func (eth TokenBackend) Synced() (bool, error)
- func (eth TokenBackend) TxData(coinID []byte) ([]byte, error)
- func (eth TokenBackend) ValidateCoinID(coinID []byte) (string, error)
- func (eth *TokenBackend) ValidateContract(contractData []byte) error
- func (eth TokenBackend) ValidateFeeRate(coin asset.Coin, reqFeeRate uint64) bool
- func (eth TokenBackend) ValidateSecret(secret, contractData []byte) bool
- func (eth TokenBackend) ValidateSignature(addr string, pubkey, msg, sig []byte) error
- type TokenDriver
- type VersionedToken
Constants ¶
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 ¶
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) 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) ValidateCoinID ¶
ValidateCoinID attempts to decode the coinID.
func (AssetBackend) ValidateFeeRate ¶
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 ¶
ValidateSecret checks that the secret satisfies the secret hash.
func (AssetBackend) ValidateSignature ¶
ValidateSignature checks that the pubkey is correct for the address and that the signature shows ownership of the associated private key.
type ContextCaller ¶
type DriverBase ¶ added in v1.0.0
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 ¶
CheckSwapAddress checks that the given address is parseable.
func (*ETHBackend) Connect ¶
Connect connects to the node RPC server and initializes some variables.
func (ETHBackend) Info ¶
func (ETHBackend) Info() *asset.BackendInfo
Info provides some general information about the backend.
func (*ETHBackend) TokenBackend ¶
TokenBackend creates an *AssetBackend for a token. Part of the asset.TokenBacker interface. Do not call TokenBackend concurrently for the same asset.
func (ETHBackend) ValidateCoinID ¶
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 ¶
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 ¶
ValidateSecret checks that the secret satisfies the secret hash.
func (ETHBackend) ValidateSignature ¶
ValidateSignature checks that the pubkey is correct for the address and that the signature shows ownership of the associated private key.
type RPCTransaction ¶
type TokenBackend ¶
type TokenBackend struct { *AssetBackend *VersionedToken }
TokenBackend implements some token-specific methods.
func (TokenBackend) CheckSwapAddress ¶
CheckSwapAddress checks that the given address is parseable.
func (*TokenBackend) Connect ¶
Connect for TokenBackend just waits for context cancellation and closes the WaitGroup.
func (TokenBackend) Info ¶
func (TokenBackend) Info() *asset.BackendInfo
Info provides some general information about the backend.
func (TokenBackend) ValidateCoinID ¶
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 ¶
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 ¶
ValidateSecret checks that the secret satisfies the secret hash.
func (TokenBackend) ValidateSignature ¶
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.