ethcli

package module
v0.0.0-...-5984528 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: MIT Imports: 14 Imported by: 1

README

ethcli

使用类ethereum的 golang client(sdk),包括以下功能:

  • 包装go-ethereum ethclient.Client,提供内置的web3 JSON RPC方法
  • 封装离线签名交易接口(BuildTxSignTxSendTx),封装高级别的SendMondoTx接口
  • 封装ORC20/ERC20接口
  • 封装ORC721/ERC721接口,封装自定义ORC721/ERC721 mint接口
  • 提供地址生成GenKey、校验ValidAddress、资产精度转换方法ToWei,ToEther,十六进制数据转换HexToBytes BytesToHex BytesToHexWith0x方法

方法的使用参考test文件。

数据差异

  • 无叔块
  • Mondo只有statedb,和区块数据
  • 无receipts tree,交易回执hash与交易hash相同
  • 区块hash:区块浏览器中区块hash无0x前缀

ORC721 相关方法说明

  • 实现openzeppelin-contract/contracts/token/ERC721openzeppelin-contract/contracts/token/ERC721/extensions 相关接口
  • 实现自定义uint256 mint(address to)uint256 mint(address to,string memory _tokenURI) 接口
  • string tokenURI(uint256 tokenId)方法由ERC721URIStorageERC721Metadata共用,mint返回的tokenId只能通过hash查询交易结果,从交易事件中获取

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToHex

func BytesToHex(bz []byte) string

func BytesToHexWith0x

func BytesToHexWith0x(bz []byte) string

func GenKey

func GenKey() (string, string, string, error)

GenKey 本地生成mondo链格式的账户 返回:公钥,地址,私钥,mondo采用压缩公钥

func HashToAddress

func HashToAddress(hx common.Hash) common.Address

func HashToBigInt

func HashToBigInt(hx common.Hash) *big.Int

func HexToBytes

func HexToBytes(str string) []byte

func ToEther

func ToEther(v *big.Int) *big.Int

func ToWei

func ToWei(v *big.Int) *big.Int

func ValidAddress

func ValidAddress(address string) bool

Types

type ETHCli

type ETHCli struct {
	*ethclient.Client
	// contains filtered or unexported fields
}

func New

func New(rawurl string) (*ETHCli, error)

func (*ETHCli) BuildTx

func (cli *ETHCli) BuildTx(nonce uint64, gasPrice *big.Int,
	gas uint64, to *common.Address, value *big.Int, data []byte) *types.Transaction

BuildTx 生成交易 nonce:from 的nonce,通过PendingNonceAt查询 gasPrice 小数位18位,最小为1*1e10,可通过SuggestGasPrice查询建议值 gas OLO普通转账21000,合约执行可通过EstimateGas先估算 to nil时部署合约 value OLO金额,小数位18位,最小为1*1e10 data 合约执行字节码

func (*ETHCli) ID

func (cli *ETHCli) ID() *big.Int

ID return chainId

func (*ETHCli) ORC1155BalanceOf

func (cli *ETHCli) ORC1155BalanceOf(token string, owner string, tokenId *big.Int, blockNumber *big.Int) (*big.Int, error)

func (*ETHCli) ORC1155BalanceOfBatch

func (cli *ETHCli) ORC1155BalanceOfBatch(token string, owners []string, tokenIds []*big.Int, blockNumber *big.Int) ([]*big.Int, error)

func (*ETHCli) ORC1155Burn

func (cli *ETHCli) ORC1155Burn(key string, token string, to string, id *big.Int, amount *big.Int) (string, error)

func (*ETHCli) ORC1155BurnBatch

func (cli *ETHCli) ORC1155BurnBatch(key string, token string, to string, ids []*big.Int, amounts []*big.Int) (string, error)

func (*ETHCli) ORC1155IsApprovedForAll

func (cli *ETHCli) ORC1155IsApprovedForAll(token string, owner string, operator string, blockNumber *big.Int) (bool, error)

func (*ETHCli) ORC1155Mint

func (cli *ETHCli) ORC1155Mint(key string, token string, to string, id *big.Int, amount *big.Int, data []byte) (string, error)

func (*ETHCli) ORC1155MintBatch

func (cli *ETHCli) ORC1155MintBatch(key string, token string, to string, ids []*big.Int, amounts []*big.Int, data []byte) (string, error)

func (*ETHCli) ORC1155SafeBatchTransferFrom

func (cli *ETHCli) ORC1155SafeBatchTransferFrom(key string, token string, owner string, to string, ids []*big.Int, amounts []*big.Int) (string, error)

func (*ETHCli) ORC1155SafeTransferFrom

func (cli *ETHCli) ORC1155SafeTransferFrom(key string, token string, owner string, to string, id *big.Int, amount *big.Int, data []byte) (string, error)

func (*ETHCli) ORC1155SetApprovalForAll

func (cli *ETHCli) ORC1155SetApprovalForAll(key string, token string, owner string, operator string, id *big.Int) (string, error)

func (*ETHCli) ORC1155SupportsInterface

func (cli *ETHCli) ORC1155SupportsInterface(token string, interfaceId [4]byte, blockNumber *big.Int) (bool, error)

func (*ETHCli) ORC1155Uri

func (cli *ETHCli) ORC1155Uri(token string, tokenId *big.Int, blockNumber *big.Int) (string, error)

func (*ETHCli) ORC20Allowance

func (cli *ETHCli) ORC20Allowance(token, owner, spender string, blockNumber *big.Int) (*big.Int, error)

func (*ETHCli) ORC20Approve

func (cli *ETHCli) ORC20Approve(token, key, spender, value string) (string, error)

func (*ETHCli) ORC20BalanceOf

func (cli *ETHCli) ORC20BalanceOf(token string, address string, blockNumber *big.Int) (*big.Int, error)

func (*ETHCli) ORC20Burn

func (cli *ETHCli) ORC20Burn(token, key, value string) (string, error)

func (*ETHCli) ORC20BurnFrom

func (cli *ETHCli) ORC20BurnFrom(token, key, owner, value string) (string, error)

func (*ETHCli) ORC20Decimals

func (cli *ETHCli) ORC20Decimals(token string, blockNumber *big.Int) (uint8, error)

func (*ETHCli) ORC20Mint

func (cli *ETHCli) ORC20Mint(token, key, to, value string) (string, error)

func (*ETHCli) ORC20Name

func (cli *ETHCli) ORC20Name(token string, blockNumber *big.Int) (string, error)

func (*ETHCli) ORC20Symbol

func (cli *ETHCli) ORC20Symbol(token string, blockNumber *big.Int) (string, error)

func (*ETHCli) ORC20TotalSupply

func (cli *ETHCli) ORC20TotalSupply(token string, blockNumber *big.Int) (*big.Int, error)

func (*ETHCli) ORC20Transfer

func (cli *ETHCli) ORC20Transfer(token, key, to, value string) (string, error)

func (*ETHCli) ORC20TransferFrom

func (cli *ETHCli) ORC20TransferFrom(token, key, from, to, value string) (string, error)

func (*ETHCli) ORC721Approve

func (cli *ETHCli) ORC721Approve(token string, key, to string, tokenId *big.Int) (string, error)

func (*ETHCli) ORC721BalanceOf

func (cli *ETHCli) ORC721BalanceOf(token string, owner string, blockNumber *big.Int) (*big.Int, error)

func (*ETHCli) ORC721Burn

func (cli *ETHCli) ORC721Burn(token string, key string, tokenId *big.Int) (string, error)

func (*ETHCli) ORC721Exists

func (cli *ETHCli) ORC721Exists(token string, tokenId *big.Int, blockNumber *big.Int) (bool, error)

func (*ETHCli) ORC721GetApproved

func (cli *ETHCli) ORC721GetApproved(token string, tokenId *big.Int, blockNumber *big.Int) (string, error)

func (*ETHCli) ORC721IsApprovedForAll

func (cli *ETHCli) ORC721IsApprovedForAll(token string, owner, operator string, blockNumber *big.Int) (bool, error)

func (*ETHCli) ORC721Mint

func (cli *ETHCli) ORC721Mint(token string, key string, to string) (string, error)

func (*ETHCli) ORC721MintWithTokenIdAndURI

func (cli *ETHCli) ORC721MintWithTokenIdAndURI(token string, key string, to string, tokenId *big.Int, uri string) (string, error)

func (*ETHCli) ORC721MintWithTokenURI

func (cli *ETHCli) ORC721MintWithTokenURI(token string, key string, to string, uri string) (string, error)

func (*ETHCli) ORC721Name

func (cli *ETHCli) ORC721Name(token string, blockNumber *big.Int) (string, error)

func (*ETHCli) ORC721OwnerOf

func (cli *ETHCli) ORC721OwnerOf(token string, tokenId *big.Int, blockNumber *big.Int) (string, error)

func (*ETHCli) ORC721Pause

func (cli *ETHCli) ORC721Pause(token string, key string) (string, error)

func (*ETHCli) ORC721Paused

func (cli *ETHCli) ORC721Paused(token string, blockNumber *big.Int) (bool, error)

func (*ETHCli) ORC721SafeTransferFrom

func (cli *ETHCli) ORC721SafeTransferFrom(token string, key, from, to string, tokenId *big.Int) (string, error)

func (*ETHCli) ORC721SafeTransferFromWithData

func (cli *ETHCli) ORC721SafeTransferFromWithData(token string, key, from, to string, tokenId *big.Int, calldata []byte) (string, error)

func (*ETHCli) ORC721SetApprovalForAll

func (cli *ETHCli) ORC721SetApprovalForAll(token string, key, operator string, approved bool) (string, error)

func (*ETHCli) ORC721SupportsInterface

func (cli *ETHCli) ORC721SupportsInterface(token string, blockNumber *big.Int) (bool, error)

func (*ETHCli) ORC721Symbol

func (cli *ETHCli) ORC721Symbol(token string, blockNumber *big.Int) (string, error)

func (*ETHCli) ORC721TokenByIndex

func (cli *ETHCli) ORC721TokenByIndex(token string, index *big.Int, blockNumber *big.Int) (*big.Int, error)

func (*ETHCli) ORC721TokenOfOwnerByIndex

func (cli *ETHCli) ORC721TokenOfOwnerByIndex(token string, owner string, index *big.Int, blockNumber *big.Int) (*big.Int, error)

func (*ETHCli) ORC721TokenURI

func (cli *ETHCli) ORC721TokenURI(token string, tokenId *big.Int, blockNumber *big.Int) (string, error)

ORC721TokenURI for ERC721Metadata && ERC721URIStorage

func (*ETHCli) ORC721TotalSupply

func (cli *ETHCli) ORC721TotalSupply(token string, blockNumber *big.Int) (*big.Int, error)

func (*ETHCli) ORC721TransferFrom

func (cli *ETHCli) ORC721TransferFrom(token string, key, from, to string, tokenId *big.Int) (string, error)

func (*ETHCli) ORC721Unpause

func (cli *ETHCli) ORC721Unpause(token string, key string) (string, error)

func (*ETHCli) SendMondoTx

func (cli *ETHCli) SendMondoTx(key string, to *string, amount string, payload string, gasPrice string, gasLimit uint64) (string, error)

SendMondoTx 高级别的发送Mondo交易 key 私钥,无0x开头的hex格式 to 地址,为空或全0时为部署合约 amount 金额,十进制字符串,整数,小数位18,第9-18位小数将被忽略 payload 合约负载,0x开头、非0x开头的hex格式 gasPrice 可选,金额,十进制字符串,整数,小数位18,第9-18位小数将被忽略;为0或不填时从链上时建议price gasLimit 可选,为0时实时估算

func (*ETHCli) SendTx

func (cli *ETHCli) SendTx(ctx context.Context, signedTx *types.Transaction) error

SendTx 发送已签名交易

func (*ETHCli) SignTx

func (cli *ETHCli) SignTx(tx *types.Transaction, key string) (*types.Transaction, error)

SignTx 交易签名 tx 待签名交易 key 私钥,无0x开头的hex格式 返回已签名tx,tx.Hash返回交易hash

Directories

Path Synopsis
eth
ethclient
Package ethclient provides a client for the Ethereum RPC API.
Package ethclient provides a client for the Ethereum RPC API.
ethclient/gethclient
Package gethclient provides an RPC client for geth-specific APIs.
Package gethclient provides an RPC client for geth-specific APIs.
types
Package types contains data types related to Ethereum consensus.
Package types contains data types related to Ethereum consensus.

Jump to

Keyboard shortcuts

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