eth

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 31 Imported by: 5

Documentation

Index

Constants

View Source
const (
	// ERC20  交易method
	ERC20_METHOD_TRANSFER = "transfer"
	ERC20_METHOD_APPROVE  = "approve"
)
View Source
const (
	DEFAULT_CONTRACT_GAS_LIMIT = "63000"
	DEFAULT_ETH_GAS_LIMIT      = "21000"
	// 当前网络 standard gas price
	DEFAULT_ETH_GAS_PRICE = "20000000000"
)

默认gas limit估算失败后,21000 * 3 = 63000

View Source
const (
	RPAMethodCreate = "create"
	RPAMethodOpen   = "open"
	RPAMethodClose  = "close"
)
View Source
const (
	// 合约 ABI json文件,查询ERC20 相关代币信息需要使用 ABI 文件
	Erc20AbiStr = `` /* 4592-byte string literal not displayed */
)
View Source
const RedPacketABI = `` /* 4896-byte string literal not displayed */

Variables

This section is empty.

Functions

func DecodeAddressToPublicKey added in v0.2.0

func DecodeAddressToPublicKey(address string) (string, error)

Warning: eth cannot support decode address to public key

func EncodeAbiData added in v0.2.6

func EncodeAbiData(abiString, method string, params ...interface{}) ([]byte, error)

func EncodeErc20Approve added in v0.2.6

func EncodeErc20Approve(spender string, amount *big.Int) ([]byte, error)

func EncodeErc20Transfer added in v0.2.4

func EncodeErc20Transfer(toAddress, amount string) ([]byte, error)

Encode erc20 transfer data

func EncodePublicKeyToAddress added in v0.2.0

func EncodePublicKeyToAddress(publicKey string) (string, error)

func GetChainId

func GetChainId(e *EthChain) (string, error)

获取链ID

func IsValidAddress added in v0.1.2

func IsValidAddress(address string) bool

Check if address is 40 hexadecimal characters

func IsValidEIP55Address added in v0.2.5

func IsValidEIP55Address(address string) bool

It will check based on eip55 rules

func PrivateKeyToAddress

func PrivateKeyToAddress(privateKey string) (string, error)

私钥转地址

func SignHashForMsg added in v0.2.3

func SignHashForMsg(data string) []byte

以太坊的 hash 专门在数据前面加上了一段话

func TransformEIP55Address added in v0.2.0

func TransformEIP55Address(address string) (string, error)

func VerifySignature added in v0.2.4

func VerifySignature(pubkey, message, signedMsg string) bool

Types

type Account added in v0.2.0

type Account struct {
	*Util
	// contains filtered or unexported fields
}

func EthAccountWithPrivateKey added in v0.2.6

func EthAccountWithPrivateKey(privateKey string) (*Account, error)

We cannot use name `NewAccountWithPrivateKey`, because android not support.

func NewAccountWithMnemonic added in v0.2.0

func NewAccountWithMnemonic(mnemonic string) (*Account, error)

func (*Account) Address added in v0.2.0

func (a *Account) Address() string

The ethereum address is same as public key in coming

func (*Account) PrivateKey added in v0.2.0

func (a *Account) PrivateKey() ([]byte, error)

@return privateKey data

func (*Account) PrivateKeyHex added in v0.2.0

func (a *Account) PrivateKeyHex() (string, error)

@return privateKey string that will start with 0x.

func (*Account) PublicKey added in v0.2.0

func (a *Account) PublicKey() []byte

Is deocde from address @return publicKey data

func (*Account) PublicKeyHex added in v0.2.0

func (a *Account) PublicKeyHex() string

The ethereum public key is same as address in coming @return publicKey string that will start with 0x.

func (*Account) Sign added in v0.2.0

func (a *Account) Sign(message []byte, password string) ([]byte, error)

func (*Account) SignHex added in v0.2.0

func (a *Account) SignHex(messageHex string, password string) (*base.OptionalString, error)

type BuildTxResult

type BuildTxResult struct {
	SignedTx *types.Transaction
	TxHex    string
}

type CallMethodOpts

type CallMethodOpts struct {
	Nonce                int64
	Value                string
	GasPrice             string // MaxFeePerGas
	GasLimit             string
	IsPredictError       bool
	MaxPriorityFeePerGas string
}

type CallMethodOptsBigInt

type CallMethodOptsBigInt struct {
	Nonce                uint64
	Value                *big.Int
	GasPrice             *big.Int // MaxFeePerGas
	GasLimit             uint64
	IsPredictError       bool
	MaxPriorityFeePerGas *big.Int
}

func OptsTobigInt

func OptsTobigInt(opts *CallMethodOpts) *CallMethodOptsBigInt

将MethodOpts 进行转化,由于端的限制,只能传入string字符

type CallMsg added in v0.2.0

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

CallMsg contains parameters for contract calls.

func NewCallMsg added in v0.2.0

func NewCallMsg() *CallMsg

NewCallMsg creates an empty contract call parameter list.

func (*CallMsg) GetData added in v0.2.0

func (msg *CallMsg) GetData() []byte

func (*CallMsg) GetDataHex added in v0.2.1

func (msg *CallMsg) GetDataHex() string

func (*CallMsg) GetFrom added in v0.2.0

func (msg *CallMsg) GetFrom() string

func (*CallMsg) GetGasLimit added in v0.2.5

func (msg *CallMsg) GetGasLimit() string

func (*CallMsg) GetGasPrice added in v0.2.0

func (msg *CallMsg) GetGasPrice() string

func (*CallMsg) GetTo added in v0.2.0

func (msg *CallMsg) GetTo() string

func (*CallMsg) GetValue added in v0.2.0

func (msg *CallMsg) GetValue() string

func (*CallMsg) SetData added in v0.2.0

func (msg *CallMsg) SetData(data []byte)

func (*CallMsg) SetDataHex added in v0.2.1

func (msg *CallMsg) SetDataHex(hex string)

func (*CallMsg) SetFrom added in v0.2.0

func (msg *CallMsg) SetFrom(address string)

func (*CallMsg) SetGasLimit added in v0.2.5

func (msg *CallMsg) SetGasLimit(gas string)

func (*CallMsg) SetGasPrice added in v0.2.0

func (msg *CallMsg) SetGasPrice(price string)

func (*CallMsg) SetTo added in v0.2.0

func (msg *CallMsg) SetTo(address string)

func (*CallMsg) SetValue added in v0.2.0

func (msg *CallMsg) SetValue(value string)

Set amount with decimal number

func (*CallMsg) SetValueHex added in v0.2.3

func (msg *CallMsg) SetValueHex(hex string)

Set amount with hexadecimal number

func (*CallMsg) TransferToTransaction added in v0.2.6

func (msg *CallMsg) TransferToTransaction() *Transaction

type Chain added in v0.2.0

type Chain struct {
	RpcUrl string
}

func NewChainWithRpc added in v0.2.0

func NewChainWithRpc(rpcUrl string) *Chain

func (*Chain) BalanceOfAccount added in v0.2.0

func (c *Chain) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Chain) BalanceOfAddress added in v0.2.0

func (c *Chain) BalanceOfAddress(address string) (*base.Balance, error)

func (*Chain) BalanceOfPublicKey added in v0.2.0

func (c *Chain) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Chain) BatchErc20TokenBalance added in v0.2.0

func (c *Chain) BatchErc20TokenBalance(contractList []string, address string) ([]string, error)

批量请求代币余额 @param contractList 批量查询的代币的合约地址数组 @param address 用户的钱包地址 @return 余额数组,顺序与传入的 contractList 是保持一致的 @throw 如果任意一个代币请求余额出错时,会抛出错误

func (*Chain) BatchFetchErc20TokenBalance added in v0.2.0

func (c *Chain) BatchFetchErc20TokenBalance(contractListString, address string) (string, error)

SDK 批量请求代币余额,因为 golang 导出的方法不支持数组,因此传参和返回都只能用字符串 @param contractListString 批量查询的代币的合约地址字符串,用逗号隔开,例如: "add1,add2,add3" @param address 用户的钱包地址 @return 余额列表,顺序与传入合约顺序是保持一致的,例如: "b1,b2,b3" @throw 如果任意一个代币请求余额出错时,会抛出错误

func (*Chain) BatchFetchTransactionStatus added in v0.2.0

func (c *Chain) BatchFetchTransactionStatus(hashListString string) string

Batch fetch the transaction status, the hash list and the return value, which can only be passed as strings separated by "," @param hashListString The hash of the transactions to be queried in batches, a string concatenated with ",": "hash1,hash2,hash3" @return Batch transaction status, its order is consistent with hashListString: "status1,status2,status3"

func (*Chain) BuildTransferTx added in v0.2.6

func (c *Chain) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)

func (*Chain) BuildTransferTxWithAccount added in v0.2.6

func (c *Chain) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)

func (*Chain) CallContract added in v0.2.0

func (c *Chain) CallContract(msg *CallMsg, blockNumber int64) (string, error)

call eth_call method @param blockNumber Especially -2 is the latest block, -1 is pending block.

func (*Chain) ChainId added in v0.2.0

func (c *Chain) ChainId() (string, error)

func (*Chain) Erc20Token added in v0.2.0

func (c *Chain) Erc20Token(contractAddress string) TokenProtocol

func (*Chain) EstimateGasLimit added in v0.2.4

func (c *Chain) EstimateGasLimit(msg *CallMsg) (gas *base.OptionalString, err error)

func (*Chain) FetchTransactionDetail added in v0.2.0

func (c *Chain) FetchTransactionDetail(hash string) (*base.TransactionDetail, error)

Fetch transaction details through transaction hash

func (*Chain) FetchTransactionStatus added in v0.2.0

func (c *Chain) FetchTransactionStatus(hash string) base.TransactionStatus

Fetch transaction status through transaction hash

func (*Chain) LatestBlockNumber added in v0.2.1

func (c *Chain) LatestBlockNumber() (s string, err error)

func (*Chain) LatestCallContract added in v0.2.1

func (c *Chain) LatestCallContract(msg *CallMsg) (string, error)

func (*Chain) MainEthToken added in v0.2.0

func (c *Chain) MainEthToken() TokenProtocol

func (*Chain) MainToken added in v0.2.0

func (c *Chain) MainToken() base.Token

func (*Chain) NonceOfAddress added in v0.2.0

func (c *Chain) NonceOfAddress(address string) (string, error)

获取交易的 nonce

func (*Chain) PendingCallContract added in v0.2.0

func (c *Chain) PendingCallContract(msg *CallMsg) (string, error)

func (*Chain) SendRawTransaction added in v0.2.0

func (c *Chain) SendRawTransaction(signedTx string) (string, error)

Send the raw transaction on-chain @return the hex hash string

func (*Chain) SignTransaction added in v0.2.3

func (c *Chain) SignTransaction(privateKey string, transaction *Transaction) (*base.OptionalString, error)

Sign a transaction @return signed tx hash

func (*Chain) SignTransactionWithAccount added in v0.2.3

func (c *Chain) SignTransactionWithAccount(account base.Account, transaction *Transaction) (*base.OptionalString, error)

func (*Chain) SignWithPrivateKeyData added in v0.2.3

func (c *Chain) SignWithPrivateKeyData(privateKeyData []byte, transaction *Transaction) (o *base.OptionalString, err error)

func (*Chain) SuggestGasPrice added in v0.2.0

func (c *Chain) SuggestGasPrice() (*base.OptionalString, error)

func (*Chain) SuggestGasPriceEIP1559 added in v0.2.3

func (c *Chain) SuggestGasPriceEIP1559() (*GasPrice, error)

The gas price use average grade default.

type CoinUtil deprecated added in v0.1.2

type CoinUtil struct {
	// 链的 RPC 地址
	RpcUrl string
	// 币种的合约地址,如果为 nil,表示是主网的币
	ContractAddress string
	// 用户的钱包地址
	WalletAddress string
}

Deprecated: CoinUtil is deprecated. Please Use EthChain instead.

func NewCoinUtilWithRpc deprecated added in v0.1.2

func NewCoinUtilWithRpc(rpcUrl, contractAddress, walletAddress string) *CoinUtil

Deprecated: CoinUtil is deprecated. Please Use NewChainWithRpc() instead.

func (*CoinUtil) BuildTransferTx deprecated added in v0.1.2

func (u *CoinUtil) BuildTransferTx(privateKey, receiverAddress, nonce, gasPrice, gasLimit, amount string) (*base.OptionalString, error)

Deprecated: BuildTransferTx is deprecated. Please Use Chain.Token().BuildTransferTx() instead.

func (*CoinUtil) CoinInfo deprecated added in v0.1.2

func (u *CoinUtil) CoinInfo() (*Erc20TokenInfo, error)

Deprecated: CoinInfo is deprecated.

func (*CoinUtil) EstimateGasLimit deprecated added in v0.1.2

func (u *CoinUtil) EstimateGasLimit(receiverAddress, gasPrice, amount string) (string, error)

Deprecated: Nonce is deprecated. Please Use Chain.Token().EstimateGasLimit() instead.

func (*CoinUtil) FetchTransactionDetail deprecated added in v0.1.2

func (u *CoinUtil) FetchTransactionDetail(hashString string) (*base.TransactionDetail, error)

Deprecated: FetchTransactionDetail is deprecated. Please Use Chain.FetchTransactionDetail() instead.

func (*CoinUtil) FetchTransactionStatus deprecated added in v0.1.2

func (u *CoinUtil) FetchTransactionStatus(hashString string) base.TransactionStatus

Deprecated: FetchTransactionStatus is deprecated. Please Use Chain.FetchTransactionStatus() instead.

func (*CoinUtil) IsMainCoin added in v0.1.2

func (u *CoinUtil) IsMainCoin() bool

是否是主币

func (*CoinUtil) Nonce deprecated added in v0.1.2

func (u *CoinUtil) Nonce() (string, error)

Deprecated: Nonce is deprecated. Please Use Chain.NonceOfAddress() instead.

func (*CoinUtil) QueryBalance deprecated added in v0.1.2

func (u *CoinUtil) QueryBalance() (string, error)

Deprecated: QueryBalance is deprecated. Please Use Chain.Token().BalanceOfAddress() instead.

func (*CoinUtil) SdkBatchTransactionStatus deprecated added in v0.1.5

func (u *CoinUtil) SdkBatchTransactionStatus(hashListString string) (string, error)

Deprecated: SdkBatchTransactionStatus is deprecated. Please Use Chain.SdkBatchTransactionStatus() instead.

func (*CoinUtil) SendRawTransaction deprecated added in v0.1.2

func (u *CoinUtil) SendRawTransaction(txHex string) (string, error)

Deprecated: SendRawTransaction is deprecated. Please Use Chain.SendRawTransaction() instead.

type Erc20Token

type Erc20Token struct {
	*Token

	ContractAddress string
}

func NewErc20Token added in v0.2.0

func NewErc20Token(chain *Chain, contractAddress string) *Erc20Token

func (*Erc20Token) Allowance added in v0.2.6

func (t *Erc20Token) Allowance(owner, spender string) (*big.Int, error)

func (*Erc20Token) Approve added in v0.2.6

func (t *Erc20Token) Approve(account *Account, spender string, amount *big.Int) (string, error)

func (*Erc20Token) BalanceOfAddress added in v0.2.0

func (t *Erc20Token) BalanceOfAddress(address string) (*base.Balance, error)

func (*Erc20Token) BuildTransferTx added in v0.2.0

func (t *Erc20Token) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)

func (*Erc20Token) BuildTransferTxWithAccount added in v0.2.3

func (t *Erc20Token) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)

func (*Erc20Token) Decimal

func (t *Erc20Token) Decimal() (int16, error)

func (*Erc20Token) Erc20TokenInfo added in v0.2.0

func (t *Erc20Token) Erc20TokenInfo() (*Erc20TokenInfo, error)

cannot get balance

func (*Erc20Token) EstimateGasFeeLayer2 added in v0.2.5

func (t *Erc20Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)

func (*Erc20Token) EstimateGasLimit added in v0.2.0

func (t *Erc20Token) EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)

func (*Erc20Token) TokenInfo added in v0.2.0

func (t *Erc20Token) TokenInfo() (*base.TokenInfo, error)

type Erc20TokenInfo added in v0.2.0

type Erc20TokenInfo struct {
	*base.TokenInfo

	ContractAddress string
	ChainId         string
	TokenIcon       string

	// Deprecated: Balance is not a token's info.
	Balance string
}

type Erc20TxParams

type Erc20TxParams struct {
	ToAddress string `json:"toAddress"`
	Amount    string `json:"amount"`
	Method    string `json:"method"`
}

type EthChain

type EthChain struct {
	RemoteRpcClient *ethclient.Client
	RpcClient       *rpc.Client
	// contains filtered or unexported fields
}

func GetConnection added in v0.1.2

func GetConnection(rpcUrl string) (*EthChain, error)

通过 rpcUrl, 获取 eth 的连接对象

func NewEthChain

func NewEthChain() *EthChain

func (*EthChain) Balance

func (e *EthChain) Balance(address string) (string, error)

@title 主网代币余额查询 @description 返回主网代币余额,decimal为代币精度 @auth 清欢 @param (walletAddress) (string) 合约名称,钱包地址 @return (string,error) 代币余额,错误信息

func (*EthChain) BatchTransactionStatus added in v0.1.2

func (e *EthChain) BatchTransactionStatus(hashList []string) []string

批量获取交易的转账状态 @param hashList 要批量查询的交易的 hash 数组 @return 交易状态数组,它的顺序和 hashList 是保持一致的

func (*EthChain) BuildCallMethodTx

func (e *EthChain) BuildCallMethodTx(
	privateKey, contractAddress, abiStr, methodName string,
	opts *CallMethodOpts,
	erc20JsonParams string) (*BuildTxResult, error)

对合约进行调用

func (*EthChain) BuildCallMethodTxWithPayload

func (e *EthChain) BuildCallMethodTxWithPayload(
	privateKey, contractAddress, payload string, opts *CallMethodOpts) (*BuildTxResult, error)

func (*EthChain) BuildTransferTx

func (e *EthChain) BuildTransferTx(privateKey, toAddress string, opts *CallMethodOpts) (*BuildTxResult, error)

创建ETH转账交易

func (*EthChain) CallContractConstant

func (e *EthChain) CallContractConstant(out interface{}, contractAddress, abiStr, methodName string, opts *bind.CallOpts, params ...interface{}) (err error)

func (*EthChain) CallContractConstantWithPayload

func (e *EthChain) CallContractConstantWithPayload(out interface{}, contractAddress, payload string, outputTypes abi.Arguments, opts *bind.CallOpts) (err error)

func (*EthChain) Close

func (e *EthChain) Close()

func (*EthChain) ConnectRemote added in v0.1.2

func (e *EthChain) ConnectRemote(rpcUrl string) error

func (*EthChain) CreateRemote

func (e *EthChain) CreateRemote(rpcUrl string) (chain *EthChain, err error)

func (*EthChain) CreateRemoteWithTimeout added in v0.2.5

func (e *EthChain) CreateRemoteWithTimeout(rpcUrl string, timeout int64) (chain *EthChain, err error)

@param timeout time unit millsecond. 0 means use chain's default: 60000ms.

func (*EthChain) Erc20TokenInfo deprecated

func (e *EthChain) Erc20TokenInfo(contractAddress string, walletAddress string) (*Erc20TokenInfo, error)

Deprecated: Erc20TokenInfo is deprecated. Please Use Chain.Erc20Token().Erc20TokenInfo() @title Erc20代币基础信息 @description 返回代币基础信息 @auth 清欢 @param (contractAddress, walletAddress) (string,string) 合约名称,钱包地址 @return (*Erc20Token,error) Erc20Token,错误信息

func (*EthChain) EstimateContractGasLimit

func (e *EthChain) EstimateContractGasLimit(

	fromAddress,
	contractAddress,
	abiStr,
	methodName string,
	erc20JsonParams string) (gas string, err error)

erc20 代币 Transfer,Approve GasLimit 估计 var erc20TxParams Erc20TxParams

func (*EthChain) EstimateGasLimit

func (e *EthChain) EstimateGasLimit(fromAddress string, receiverAddress string, gasPrice string, amount string) (gas string, err error)

Estimated gasLimit @param fromAddress The address where the transfer originated @param receiverAddress The address where the transfer will received @param gasPrice Previously acquired or entered by the user @param amount The amount transferred @return Estimate gasLimit, is a `String` converted from `Uint64`

func (*EthChain) FetchTransactionDetail added in v0.1.2

func (e *EthChain) FetchTransactionDetail(hashString string) (detail *base.TransactionDetail, err error)

获取交易的详情 @param hashString 交易的 hash @return 详情对象,该对象无法提供 CID 信息

func (*EthChain) FetchTransactionStatus added in v0.1.2

func (e *EthChain) FetchTransactionStatus(hashString string) base.TransactionStatus

获取交易的状态 @param hashString 交易的 hash

func (*EthChain) LatestBlockNumber

func (e *EthChain) LatestBlockNumber() (int64, error)

获取最新区块高度

func (*EthChain) MethodFromPayload

func (e *EthChain) MethodFromPayload(abiStr string, payloadStr string) (*abi.Method, error)

func (*EthChain) MethodIdFromMethodStr

func (e *EthChain) MethodIdFromMethodStr(methodStr string) string

func (*EthChain) Nonce

func (e *EthChain) Nonce(spenderAddressHex string) (string, error)

获取账户nonce

func (*EthChain) PackParams

func (e *EthChain) PackParams(inputs abi.Arguments, args ...interface{}) (string, error)

不带 0x 前缀

func (*EthChain) RecoverSignerAddress

func (e *EthChain) RecoverSignerAddress(msg, sig string) (*common.Address, error)

func (*EthChain) RecoverSignerAddressFromMsgHash

func (e *EthChain) RecoverSignerAddressFromMsgHash(msgHash, sig string) (*common.Address, error)

func (*EthChain) SdkBatchTokenBalance deprecated added in v0.1.2

func (e *EthChain) SdkBatchTokenBalance(contractListString, address string) (string, error)

Deprecated: SdkBatchTokenBalance is deprecated. Please Use Chain.BatchFetchErc20TokenBalance() instead.

func (*EthChain) SdkBatchTransactionStatus added in v0.1.2

func (e *EthChain) SdkBatchTransactionStatus(hashListString string) string

SDK 批量获取交易的转账状态,hash 列表和返回值,都只能用字符串,逗号隔开传递 @param hashListString 要批量查询的交易的 hash,用逗号拼接的字符串:"hash1,hash2,hash3" @return 批量的交易状态,它的顺序和 hashListString 是保持一致的: "status1,status2,status3"

func (*EthChain) SendRawTransaction

func (e *EthChain) SendRawTransaction(txHex string) (string, error)

对交易进行广播

func (*EthChain) SignHashForMsg

func (e *EthChain) SignHashForMsg(data string) (string, error)

以太坊的 hash 专门在数据前面加上了一段话

func (*EthChain) SignMsg

func (e *EthChain) SignMsg(privateKey string, data string) (string, error)

使用私钥对信息进行签名

func (*EthChain) SignTransaction

func (e *EthChain) SignTransaction(tx *types.Transaction, privateKey string) (*BuildTxResult, error)

@title SignTransaction @description 对交易进行签名 @auth 清欢 @param (tx, privateKey) (*types.Transaction,string) 合约名称,钱包地址 @return (*BuildTxResult,error) 签名结果,失败

func (*EthChain) SuggestGasPrice

func (e *EthChain) SuggestGasPrice() (string, error)

获取标准gas价格

func (*EthChain) TokenBalance

func (e *EthChain) TokenBalance(contractAddress, address string) (string, error)

@title Erc20代币余额 @description 返回erc20代币余额 @auth 清欢 @param (contractAddress,walletAddress) 合约地址,钱包地址 @return (string,error) 余额,错误信息

func (*EthChain) TokenDecimal

func (e *EthChain) TokenDecimal(contractAddress string) (int16, error)

@title Erc20代币精度 @description 返回代币精度 @auth 清欢 @param (contractAddress) 合约地址 @return (string,error) 代币精度,错误信息

func (*EthChain) TokenName

func (e *EthChain) TokenName(contractAddress string) (string, error)

@title Erc20代币名称 @description 返回代币名称 @auth 清欢 @param (contractAddress) 合约地址 @return (string,error) 名称,错误信息

func (*EthChain) TokenSymbol

func (e *EthChain) TokenSymbol(contractAddress string) (string, error)

@title Erc20代币符号 @description 返回代币符号 @auth 清欢 @param (contractAddress) 合约地址 @return (string,error) 符号,错误信息

func (*EthChain) TransactionByHash

func (e *EthChain) TransactionByHash(txHash string) (*TransactionByHashResult, error)

根据交易hash查询交易状态 TO-DO 返回更详细的信息,解析交易余额,交易动作

func (*EthChain) TransactionReceiptByHash

func (e *EthChain) TransactionReceiptByHash(txHash string) (*Receipt, error)

TransactionReceipt 是指交易的收据,每笔交易执行完 会产生一个收据,收据中包含交易的状态,交易的gas使用情况,交易执行是否成功的状态码等信息 交易收据属性列表: gasUsed: 交易执行时使用的gas数量 bloomFilter:交易信息日志检索 logInfoList: 交易日志集合 postTxState: 交易执行后的状态,1 表示成功,0表示失败

func (*EthChain) UnpackParams

func (e *EthChain) UnpackParams(out interface{}, inputs abi.Arguments, paramsStr string) error

func (*EthChain) WaitConfirm

func (e *EthChain) WaitConfirm(txHash string, interval time.Duration) *Receipt

type GasPrice added in v0.2.3

type GasPrice struct {
	// Pending block baseFee in wei.
	BaseFee            string
	SuggestPriorityFee string

	MaxPriorityFee string
	MaxFee         string
}

func (*GasPrice) UseAverage added in v0.2.3

func (g *GasPrice) UseAverage() *GasPrice

MaxPriorityFee = SuggestPriorityFee * 1.5 MaxFee = (MaxPriorityFee + BaseFee) * 1.11

func (*GasPrice) UseHigh added in v0.2.3

func (g *GasPrice) UseHigh() *GasPrice

MaxPriorityFee = SuggestPriorityFee * 2.0 MaxFee = (MaxPriorityFee + BaseFee) * 1.5

func (*GasPrice) UseLow added in v0.2.3

func (g *GasPrice) UseLow() *GasPrice

MaxPriorityFee = SuggestPriorityFee * 1.0 MaxFee = (MaxPriorityFee + BaseFee) * 1.0

func (*GasPrice) UseRate added in v0.2.3

func (g *GasPrice) UseRate(priorityRate, maxFeeRate float64) *GasPrice

MaxPriorityFee = SuggestPriorityFee * priorityRate MaxFee = (MaxPriorityFee + BaseFee) * maxFeeRate

type Jsonable

type Jsonable interface {
	// 将对象转为 json 字符串
	JsonString() string
}

支持 对象 和 json 字符串 相互转换

type OptimismLayer2Gas added in v0.2.5

type OptimismLayer2Gas struct {
	L1GasLimit string
	L1GasPrice string
	L2GasLimit string
	L2GasPrice string
}

func (*OptimismLayer2Gas) GasFee added in v0.2.5

func (g *OptimismLayer2Gas) GasFee() string

l1GasLimit * l1GasPrice + l2Gaslimit * l2GasPrice

type Receipt added in v0.2.5

type Receipt struct {
	types.Receipt

	// Optimism Layer2 gas info
	L1Fee *big.Int `json:"l1Fee"`

	// Arbitrum Layer2 gas info
	EffectiveGasPrice *big.Int `json:"effectiveGasPrice"`
}

customReceipt is inherit from eth/core types.Receipt, and added some necessary properties

func (*Receipt) UnmarshalJSON added in v0.2.5

func (r *Receipt) UnmarshalJSON(data []byte) error

type RedPacketAction added in v0.2.6

type RedPacketAction struct {
	Method string
	Params []interface{}
}

func NewRedPacketActionClose added in v0.2.6

func NewRedPacketActionClose(packetId int64, creator string) (*RedPacketAction, error)

结束红包领取 的操作

func NewRedPacketActionCreate added in v0.2.6

func NewRedPacketActionCreate(erc20TokenAddress string, count int, amount string) (*RedPacketAction, error)

用户发红包 的操作

func NewRedPacketActionOpen added in v0.2.6

func NewRedPacketActionOpen(packetId int64, addresses []string, amounts []string) (*RedPacketAction, error)

批量打开红包 的操作

func (*RedPacketAction) EnsureApprovedTokens added in v0.2.6

func (rpa *RedPacketAction) EnsureApprovedTokens(account *Account, chain *Chain, spender string, coins int) (string, error)

保证用户发 erc20 的红包时,红包合约可以有权限操作用户的资产 @param account 要发红包的用户的账号,也许需要用到私钥来发起授权交易 @param chain evm 链 @param erc20Contract 要用作发红包的币种 @param coins 如果需要发起新授权,指定要授权的币个数 default 10^6 @return 如果授权成功,不会返回错误,如果有新授权,会返回授权交易的 hash

func (*RedPacketAction) EstimateAmount added in v0.2.6

func (rpa *RedPacketAction) EstimateAmount() string

func (*RedPacketAction) TransactionFrom added in v0.2.6

func (rpa *RedPacketAction) TransactionFrom(fromAddress, contractAddress string, chain *Chain) (*Transaction, error)

@param fromAddress 要调用红包业务的操作者 @param contractAddress 红包合约地址 @param chain 要发红包的链

type RpcLatency added in v0.2.5

type RpcLatency struct {
	RpcUrl  string `json:"rpcUrl"`
	Latency int64  `json:"latency"`
	Height  int64  `json:"height"`
}

type RpcReachability added in v0.2.5

type RpcReachability struct {
	// The number of network connectivity tests to be performed per rpc. 0 means infinite, default is 1
	ReachCount int
	// Timeout for each connectivity test (ms). default 20000ms
	Timeout int64
	// Time interval between two network connectivity tests (ms). default 1500ms
	Delay int64
	// contains filtered or unexported fields
}

func NewRpcReachability added in v0.2.5

func NewRpcReachability() *RpcReachability

func (*RpcReachability) StartConnectivityDelegate added in v0.2.5

func (r *RpcReachability) StartConnectivityDelegate(rpcList string, delegate RpcReachabilityDelegate)

@param rpcList string of rpcs like "rpc1,rpc2,rpc3,..."

func (*RpcReachability) StartConnectivitySync added in v0.2.5

func (r *RpcReachability) StartConnectivitySync(rpcList string) string

@param rpcList string of rpcs like "rpc1,rpc2,rpc3,..." @return jsonString sorted array base of tatency like "[{rpcUrl:rpc1,latency:100}, {rpcUrl:rpc2, latency:111}, ...]" latency unit is ms. -1 means the connection failed

func (*RpcReachability) StopConnectivity added in v0.2.5

func (r *RpcReachability) StopConnectivity()

type RpcReachabilityDelegate added in v0.2.5

type RpcReachabilityDelegate interface {
	// A node has received a response
	ReachabilityDidReceiveNode(tester *RpcReachability, latency *RpcLatency)
	// A node request failed
	ReachabilityDidFailNode(tester *RpcReachability, latency *RpcLatency)
	// The entire network connection test task is over
	// @param overview Overview of the results of all connection tests
	ReachabilityDidFinish(tester *RpcReachability, overview string)
}

type Token added in v0.2.0

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

func NewToken added in v0.2.0

func NewToken(chain *Chain) *Token

func (*Token) BalanceOfAccount added in v0.2.0

func (t *Token) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Token) BalanceOfAddress added in v0.2.0

func (t *Token) BalanceOfAddress(address string) (*base.Balance, error)

func (*Token) BalanceOfPublicKey added in v0.2.0

func (t *Token) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Token) BuildTransferTx added in v0.2.0

func (t *Token) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)

func (*Token) BuildTransferTxWithAccount added in v0.2.0

func (t *Token) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)

func (*Token) Chain added in v0.2.0

func (t *Token) Chain() base.Chain

func (*Token) EstimateGasFeeLayer2 added in v0.2.5

func (t *Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)

func (*Token) EstimateGasLimit added in v0.2.0

func (t *Token) EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)

func (*Token) TokenInfo added in v0.2.0

func (t *Token) TokenInfo() (*base.TokenInfo, error)

Warning: Main token does not support

type TokenProtocol added in v0.2.0

type TokenProtocol interface {
	base.Token

	// need `fromAddress`, `receiverAddress`, `gasPrice`, `gasLimit`, `amount`
	EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)
	EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)
	BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)
	BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)
}

type Transaction added in v0.2.3

type Transaction struct {
	Nonce    string // nonce of sender account
	GasPrice string // wei per gas
	GasLimit string // gas limit
	To       string // receiver
	Value    string // wei amount
	Data     string // contract invocation input data

	// EIP1559, Default is ""
	MaxPriorityFeePerGas string
}

func NewTransaction added in v0.2.3

func NewTransaction(nonce, gasPrice, gasLimit, to, value, data string) *Transaction

func NewTransactionFromHex added in v0.2.6

func NewTransactionFromHex(hexData string) (*Transaction, error)

func (*Transaction) GetRawTx added in v0.2.3

func (tx *Transaction) GetRawTx() (*types.Transaction, error)

func (*Transaction) MaxFee added in v0.2.3

func (tx *Transaction) MaxFee() string

This is an alias property for GasPrice in order to support EIP1559

func (*Transaction) SetMaxFee added in v0.2.3

func (tx *Transaction) SetMaxFee(maxFee string)

This is an alias property for GasPrice in order to support EIP1559

func (*Transaction) TotalAmount added in v0.2.6

func (tx *Transaction) TotalAmount() string

@return gasPrice * gasLimit + value

func (*Transaction) TransformToErc20Transaction added in v0.2.3

func (tx *Transaction) TransformToErc20Transaction(contractAddress string) error

type TransactionByHashResult

type TransactionByHashResult struct {
	SignedTx    *types.Transaction
	From        common.Address
	IsPending   bool   // 交易是否处于Pending状态
	Status      string // 0: 交易失败, 1: 交易成功
	GasUsed     string // 实际花费gas
	BlockNumber string // 区块高度
}

type UrlParam

type UrlParam struct {
	RpcUrl string
	WsUrl  string
}

type Util added in v0.2.0

type Util struct {
}

func NewUtil added in v0.2.0

func NewUtil() *Util

func (*Util) DecodeAddressToPublicKey added in v0.2.0

func (u *Util) DecodeAddressToPublicKey(address string) (string, error)

Warning: eth cannot support decode address to public key

func (*Util) EncodePublicKeyToAddress added in v0.2.0

func (u *Util) EncodePublicKeyToAddress(publicKey string) (string, error)

func (*Util) IsValidAddress added in v0.2.0

func (u *Util) IsValidAddress(address string) bool

Check if address is 40 hexadecimal characters

Jump to

Keyboard shortcuts

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