eth

package
v0.6.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: BlueOak-1.0.0 Imports: 31 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) CheckAddress

func (eth AssetBackend) CheckAddress(addr string) bool

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) 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() 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) 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(contract *asset.Contract, 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 interface{}, method string, args ...interface{}) error
}

type Driver

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

Driver implements asset.Driver.

func (*Driver) DecodeCoinID

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

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.

func (*Driver) UnitInfo

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

UnitInfo returns the dex.UnitInfo for the asset.

func (*Driver) Version

func (d *Driver) Version() uint32

Version returns the Backend implementation's version number.

type ETHBackend

type ETHBackend struct {
	*AssetBackend
}

ETHBackend implements some Ethereum-specific methods.

func NewBackend

func NewBackend(configPath string, log dex.Logger, net dex.Network) (*ETHBackend, error)

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

func (ETHBackend) CheckAddress

func (eth ETHBackend) CheckAddress(addr string) bool

CheckAddress 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(contract *asset.Contract, 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
}

TokenBackend implements some token-specific methods.

func (TokenBackend) CheckAddress

func (eth TokenBackend) CheckAddress(addr string) bool

CheckAddress 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(contract *asset.Contract, 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 {
	// contains filtered or unexported fields
}

func (*TokenDriver) DecodeCoinID

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

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.

func (*TokenDriver) UnitInfo

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

UnitInfo returns the dex.UnitInfo for the asset.

func (*TokenDriver) Version

func (d *TokenDriver) Version() uint32

Version returns the Backend implementation's version number.

Jump to

Keyboard shortcuts

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