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) CheckAddress(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() uint32
- func (be *AssetBackend) InitTxSizeBase() uint32
- 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(contract *asset.Contract, 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 ETHBackend
- func (eth ETHBackend) CheckAddress(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(contract *asset.Contract, 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) CheckAddress(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(contract *asset.Contract, reqFeeRate uint64) bool
- func (eth TokenBackend) ValidateSecret(secret, contractData []byte) bool
- func (eth TokenBackend) ValidateSignature(addr string, pubkey, msg, sig []byte) error
- type TokenDriver
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) CheckAddress ¶
CheckAddress 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() uint32
InitTxSize is an upper limit on the gas used for an initiation.
func (*AssetBackend) InitTxSizeBase ¶
func (be *AssetBackend) InitTxSizeBase() uint32
InitTxSizeBase is the same as (dex.Asset).SwapSize for asset.
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 Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver implements asset.Driver.
func (*Driver) DecodeCoinID ¶
DecodeCoinID creates a human-readable representation of a coin ID for Ethereum. This must be a transaction hash.
func (*Driver) Setup ¶
func (d *Driver) Setup(configPath string, logger dex.Logger, network dex.Network) (asset.Backend, error)
Setup creates the ETH backend. Start the backend with its Run method.
type ETHBackend ¶
type ETHBackend struct {
*AssetBackend
}
ETHBackend implements some Ethereum-specific methods.
func NewBackend ¶
NewBackend is the exported constructor by which the DEX will import the Backend.
func (ETHBackend) CheckAddress ¶
CheckAddress 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
}
TokenBackend implements some token-specific methods.
func (TokenBackend) CheckAddress ¶
CheckAddress 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 {
// contains filtered or unexported fields
}
func (*TokenDriver) DecodeCoinID ¶
DecodeCoinID creates a human-readable representation of a coin ID for Ethereum. This must be a transaction hash.
func (*TokenDriver) TokenInfo ¶
func (d *TokenDriver) TokenInfo() *dex.Token
TokenInfo returns details for a token asset.