evm

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 11 Imported by: 0

README

EVM module

Usage

(Tx) Send coin
sendCoinMsg := types.SendCoinMsg{
    Amount: "10000",
    FromAddress: "0x6577385b5d959644ae31263208a88E921273C774",
    ToAddress: "0xF9AC4736D8034F2CB3BFF22A977CD8759934F090",
}

txbytes, err := xplac.EvmSendCoin(sendCoinMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Deploy solidity contract
// Select input type of ABI and bytecode.
// It is also possible to input the entire abi and bytecode as a string type, but you can also enter a file path.
// ABI type must be json and bytecode file must be compiled file on Remix IDE.

// Constructor input arguments
var args []interface{}
owner := []common.Address{
    common.HexToAddress("0xC9F0A2b814d389088a508E31fBa483E8C4372CC2"),
    common.HexToAddress("0x41776240700C033A75A2872EF0AD32b4911e13B1"),
    common.HexToAddress("0xaaC4758A943B2692F2daE0DE8d402aD7045A8DfB"),
}
required := big.NewInt(2)

args = append(args, owner)
args = append(args, required)

deploySolContractMsg := types.DeploySolContractMsg{
    //ABI: `{ ABI json string type }`
    ABIJsonFilePath: "./abi.json",
    // Bytecode: "60806040523480156100......",
    BytecodeJsonFilePath: "./bytecode.json",
    Args: args,
}

txbytes, err := xplac.DeploySolidityContract(deploySolContractMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Invoke(execute) solidity contract
// When invoked, the arguments to be entered into the solidity contract are listed as []interface{}.
var args []interface{}
args = append(a, big.NewInt(2))

// Need contract address and invoke function name.
// Also, same as deployment, need ABI and bytecode.
invokeSolContractMsg := types.InvokeSolContractMsg{
    ContractAddress: "0xBe0AE9A424771C0D68D942A04994a97f928b0821",
    ContractFuncCallName: "store",
    Args: args,
    ABIJsonFilePath: "./abi.json",
    BytecodeJsonFilePath: "./bytecode.json",
}

txbytes, err := xplac.InvokeSolidityContract(invokeSolContractMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Query) Call solidity contract
callSolContractMsg := types.CallSolContractMsg{
    ContractAddress: "0x80E123317190cAf36292A04776b0De020136526F",
    ContractFuncCallName: "retrieve",
    // Args: nil, // input params if needed to call
    ABIJsonFilePath: "./abi.json",
    BytecodeJsonFilePath: "./bytecode.json",
    FromByteAddress: "0xC9F0A2b814d389088a508E31fBa483E8C4372CC2"
}

res, err := xplac.CallSolidityContract(callSolContractMsg).Query()
(Query) Get transaction by hash
getTransactionByHashMsg := types.GetTransactionByHashMsg {
    TxHash: "556c60576f9af3e4ae7d7fb28f8376e96803c4d9ff02eda6aacb86925f170d09",
}

res, err := xplac.GetTransactionByHash(getTransactionByHashMsg).Query()
(Query) Get Block by hash or height
// Query block by hash
getBlockByHashHeightMsg := types.GetBlockByHashHeightMsg {
    BlockHash: "0xe083b9b3a8b5df69394f55d34cfdfa46e70743a812d7433aba0adf3b7fcecd21",
}

// Query block by height
getBlockByHashHeightMsg := types.GetBlockByHashHeightMsg {
    BlockHeight: "8",
}

res, err := xplac.GetBlockByHashOrHeight(getBlockByHashHeightMsg).Query()
(Query) Account info
// Query account info of user account or contract
// Response of query includes account address(Hex and Bech32), balances and etc. 
// Including Info list
//   - "account" : account address
//   - "bech32_account" : account address of Bech32
//   - "balance" : balances of the account (eth_getBalance)
//   - "nonce" : account nonce as sequence of tendermint based blockchain (eth_getTransactionCount)
//   - "storage" : the storage address for a given account (eth_getStorageAt)
//   - "code" : the contract code of the given account (eth_getCode)
//   - "pending_balance" : the axpla balance of the given account in the pending state (eth_getBalance of the pending state)
//   - "pending_nonce" : the account nonce of the given account in the pending state (eth_getTransactionCount of the pending state)
//   - "pending_storage" : the value of key in the contract storage of the given account in the pending state (eth_getStorageAt of the pending state)
//   - "pending_code" : the contract code of the given account in the pending state (eth_getCode of the pending state)
//   - "pending_transaction_count" : the total number of transactions in the pending state (eth_getBlockTransactionCountByNumber of the pending state)

// so, the xpla.go would not support some RPC APIs as "eth_getBalance", "eth_getTransactionCount", "eth_getStorageAt" and "eth_getCode" because the function is AccountInfo includes these.

accountInfoMsg := types.AccountInfoMsg{
    Account: "0xCa8582862B82867C4Bb9E926682dD75820dE6013",
}

res, err := xplac.AccountInfo(accountInfoMsg).Query()
(Query) Suggest gas price
res, err := xplac.SuggestGasPrice().Query()
(Query) ETH chain ID
res, err := xplac.EthChainID().Query()
(Query) Latest block number
res, err := xplac.EthBlockNumber().Query()
(Query) Web3 client version
res, err = xplac.Web3ClientVersion().Query()
(Query) Web3 SHA3 (return Keccak-256)
web3Sha3Msg := types.Web3Sha3Msg{
    InputParam: "web3-sha3-test",
}

res, err = xplac.Web3Sha3(web3Sha3Msg).Query()
(Query) Network ID
res, err = xplac.NetVersion().Query()
(Query) Network peer count
res, err = xplac.NetPeerCount().Query()
(Query) Network listening
res, err = xplac.NetListening().Query()
(Query) Ethereum protocol version
res, err = xplac.EthProtocolVersion().Query()
(Query) Ethereum syncing
res, err = xplac.EthSyncing().Query()
(Query) Eth accounts
res, err = xplac.EthAccounts().Query()
(Query) The number of transactions in a given block
// using block height(=number)
e := types.EthGetBlockTransactionCountMsg{
    BlockHeight: "5440",
}

// using block hash
e := types.EthGetBlockTransactionCountMsg{
    BlockHeight: "0x46b3031b22f065f933331dc032ccd34404282ccf7e4fcd54e02d1f808abc112c"
}

res, err = xplac.EthGetBlockTransactionCount(e).Query()
(Query) Estimate gas to contract
var args []interface{}
args = append(args, big.NewInt(6151212))

// invoke message to estimate
invokeSolContractMsg := types.InvokeSolContractMsg{
    ContractAddress:      c.ContractAddress,
    ContractFuncCallName: "store",
    Args:                 args,
    ABIJsonFilePath:      "./testfiles/abi.json",
    BytecodeJsonFilePath: "./testfiles/bytecode.json",
}

res, err = xplac.EstimateGas(invokeSolContractMsg).Query()
(Query) Get transaction by block hash and index
getTransactionByBlockHashAndIndexMsg := types.GetTransactionByBlockHashAndIndexMsg{
    BlockHash: "0x7f562573c1b0ca6fc3a83246372a5d57f917a4c654c91b65ebd756dec4989d0f",
    Index:     "0",
}

res, err = xplac.EthGetTransactionByBlockHashAndIndex(getTransactionByBlockHashAndIndexMsg).Query()
(Query) Get transaction receipt
getTransactionReceiptMsg := types.GetTransactionReceiptMsg{
    TransactionHash: "0x20ec56d16231c4d7f761c2533885619489fface85cf6c478868ef1d531b93177",
}

res, err = xplac.EthGetTransactionReceipt(getTransactionReceiptMsg).Query()
(Query) New filter
ethNewFilterMsg := types.EthNewFilterMsg{
    Topics:    []string{"0x20ec56d16231c4d7f761c2533885619489fface85cf6c478868ef1d531b93177"},
    Address:   []string{"0xf7777b36a51fb0b33dd0c5118361AfC94ff7f967"},
    ToBlock:   "latest",
    FromBlock: "earliest",
}

res, err = xplac.EthNewFilter(ethNewFilterMsg).Query()
(Query) New block filter
res, err = xplac.EthNewBlockFilter().Query()
(Query) New pending transaction filter
res, err = xplac.EthNewPendingTransactionFilter().Query()
(Query) Uninstall filter
ethUninsatllFilterMsg := types.EthUninsatllFilterMsg{
    FilterId: "0x168b9d421ecbffa1ac706926c2203454",
}

res, err = xplac.EthUninstallFilter(ethUninsatllFilterMsg).Query()
(Query) Get filter changes
ethGetFilterChangesMsg := types.EthGetFilterChangesMsg{
    FilterId: "0x9852d91813fb44da471436722e02965e",
}

res, err = xplac.EthGetFilterChanges(ethGetFilterChangesMsg).Query()
(Query) Get logs
ethGetLogsMsg := types.EthGetLogsMsg{
    Topics:  []string{"0x20ec56d16231c4d7f761c2533885619489fface85cf6c478868ef1d531b93177"},
    Address: []string{"0xf7777b36a51fb0b33dd0c5118361AfC94ff7f967"},
    ToBlock: "latest",
    FromBlock: "latest",
    // BlockHash: "0x46b3031b22f065f933331dc032ccd34404282ccf7e4fcd54e02d1f808abc112c",
}

res, err = xplac.EthGetLogs(ethGetLogsMsg).Query()
(Query) Coinbase
res, err = xplac.EthCoinbase().Query()

Documentation

Index

Constants

View Source
const (
	EvmModule                                   = "evm"
	EvmSendCoinMsgType                          = "evm-send-coin"
	EvmDeploySolContractMsgType                 = "deploy-sol-contract"
	EvmInvokeSolContractMsgType                 = "invoke-sol-contract"
	EvmCallSolContractMsgType                   = "call-sol-contract"
	EvmGetTransactionByHashMsgType              = "evm-get-transaction-by-hash"
	EvmGetBlockByHashHeightMsgType              = "evm-get-block"
	EvmQueryAccountInfoMsgType                  = "evm-query-account-info"
	EvmSuggestGasPriceMsgType                   = "suggest-gas-price"
	EvmQueryChainIdMsgType                      = "evm-chain-id"
	EvmQueryCurrentBlockNumberMsgType           = "current-block-number"
	EvmWeb3ClientVersionMsgType                 = "web3-client-version"
	EvmWeb3Sha3MsgType                          = "web3-sha"
	EvmNetVersionMsgType                        = "net-version"
	EvmNetPeerCountMsgType                      = "net-peer-count"
	EvmNetListeningMsgType                      = "net-listening"
	EvmEthProtocolVersionMsgType                = "eth-protocol-version"
	EvmEthSyncingMsgType                        = "eth-syncing"
	EvmEthAccountsMsgType                       = "eth-accounts"
	EvmEthGetBlockTransactionCountMsgType       = "eth-get-block-transaction-count"
	EvmEthEstimateGasMsgType                    = "eth-estimate-gas"
	EvmGetTransactionByBlockHashAndIndexMsgType = "eth-get-transaction-by-block-hash-and-index"
	EvmGetTransactionReceiptMsgType             = "eth-get-transaction-receipt"
	EvmEthNewFilterMsgType                      = "eth-new-filter"
	EvmEthNewBlockFilterMsgType                 = "eth-new-block-filter"
	EvmEthNewPendingTransactionFilterMsgType    = "eth-new-pending-transaction-filter"
	EvmEthUninstallFilterMsgType                = "eth-uninstall-filter"
	EvmEthGetFilterChangesMsgType               = "eth-get-filter-changes"
	EvmEthGetFilterLogsMsgType                  = "eth-get-filter-logs"
	EvmEthGetLogsMsgType                        = "eth-get-logs"
	EvmEthCoinbaseMsgType                       = "eth-coinbase"
)

Variables

View Source
var Args []interface{}

Functions

func MakeEthGetBlockTransactionCountMsg

func MakeEthGetBlockTransactionCountMsg(ethGetBlockTransactionCountMsg types.EthGetBlockTransactionCountMsg) (types.EthGetBlockTransactionCountMsg, error)

(Query) make msg - get transaction count of the block number

func MakeEthGetFilterChangesMsg

func MakeEthGetFilterChangesMsg(ethGetFilterChangesMsg types.EthGetFilterChangesMsg) (types.EthGetFilterChangesMsg, error)

(Query) make msg - eth get filter changes

func MakeEthGetFilterLogsMsg

func MakeEthGetFilterLogsMsg(ethGetFilterLogsMsg types.EthGetFilterLogsMsg) (types.EthGetFilterLogsMsg, error)

(Query) make msg - eth get filter logs

func MakeEthUninstallFilterMsg

func MakeEthUninstallFilterMsg(ethUninstallFilter types.EthUninstallFilterMsg) (types.EthUninstallFilterMsg, error)

(Query) make msg - eth uninstall filter

func MakeGetBlockByHashHeightMsg

func MakeGetBlockByHashHeightMsg(getBlockByHashHeightMsg types.GetBlockByHashHeightMsg) (types.GetBlockByHashHeightMsg, error)

(Query) make msg - block by hash or height

func MakeGetTransactionByBlockHashAndIndexMsg

func MakeGetTransactionByBlockHashAndIndexMsg(getTransactionByBlockHashAndIndexMsg types.GetTransactionByBlockHashAndIndexMsg) (types.GetTransactionByBlockHashAndIndexMsg, error)

(Query) make msg - get transaction by block hash and index

func MakeGetTransactionByHashMsg

func MakeGetTransactionByHashMsg(getTransactionByHashMsg types.GetTransactionByHashMsg) (types.GetTransactionByHashMsg, error)

(Query) make msg - transaction by hash

func MakeGetTransactionReceiptMsg

func MakeGetTransactionReceiptMsg(getTransactionReceiptMsg types.GetTransactionReceiptMsg) (types.GetTransactionReceiptMsg, error)

(Query) make msg - get transaction receipt

func MakeInvokeSolContractMsg

func MakeInvokeSolContractMsg(InvokeSolContractMsg types.InvokeSolContractMsg) (types.InvokeSolContractMsg, error)

(Tx) make msg - invoke solidity contract

func MakeQueryAccountInfoMsg

func MakeQueryAccountInfoMsg(accountInfoMsg types.AccountInfoMsg) (types.AccountInfoMsg, error)

(Query) make msg - account info

func MakeSendCoinMsg

func MakeSendCoinMsg(sendCoinMsg types.SendCoinMsg) (types.SendCoinMsg, error)

(Tx) make msg - send coin

func MakeWeb3Sha3Msg

func MakeWeb3Sha3Msg(web3Sha3Msg types.Web3Sha3Msg) (types.Web3Sha3Msg, error)

(Query) make msg - web3 sha3

func NewCoreModule added in v0.1.2

func NewCoreModule() core.CoreModule

func QueryEvm

func QueryEvm(i core.QueryClient) (string, error)

Query client for evm module.

Types

type CallSolContractParseMsg

type CallSolContractParseMsg struct {
	CallMsg  ethereum.CallMsg
	CallName string
	ABI      string
	Bytecode string
}

func MakeCallSolContractMsg

func MakeCallSolContractMsg(callSolContractMsg types.CallSolContractMsg) (CallSolContractParseMsg, error)

(Query) make msg - call solidity contract

func MakeEstimateGasSolMsg

func MakeEstimateGasSolMsg(invokeSolContractMsg types.InvokeSolContractMsg) (CallSolContractParseMsg, error)

(Query) make msg - sol contract estimate gas

type ContractInfo

type ContractInfo struct {
	Abi      string
	Bytecode string
}

func MakeDeploySolContractMsg

func MakeDeploySolContractMsg(deploySolContractMsg types.DeploySolContractMsg) (ContractInfo, error)

(Tx) make msg - deploy solidity contract

type DeploySolTx

type DeploySolTx struct {
	ChainId  *big.Int
	Nonce    *big.Int
	Value    *big.Int
	GasLimit uint64
	GasPrice *big.Int
	ABI      string
	Bytecode string
}

type EthNewFilterParseMsg

type EthNewFilterParseMsg struct {
	BlockHash *common.Hash     `json:"blockHash,omitempty"`
	FromBlock *rpc.BlockNumber `json:"fromBlock"`
	ToBlock   *rpc.BlockNumber `json:"toBlock"`
	Addresses interface{}      `json:"address"`
	Topics    []interface{}    `json:"topics"`
}

func MakeEthGetLogsMsg

func MakeEthGetLogsMsg(ethGetLogsMsg types.EthGetLogsMsg) (EthNewFilterParseMsg, error)

(Query) make msg - eth get logs

func MakeEthNewFilterMsg

func MakeEthNewFilterMsg(ethNewFilterMsg types.EthNewFilterMsg) (EthNewFilterParseMsg, error)

(Query) make msg - eth new filter

type EvmExternal added in v0.1.2

type EvmExternal struct {
	Xplac provider.XplaClient
}

func NewEvmExternal added in v0.1.2

func NewEvmExternal(xplac provider.XplaClient) (e EvmExternal)

func (EvmExternal) AccountInfo added in v0.1.2

func (e EvmExternal) AccountInfo(accountInfoMsg types.AccountInfoMsg) provider.XplaClient

Query a account information which includes account address(hex and bech32), balance and etc.

func (EvmExternal) CallSolidityContract added in v0.1.2

func (e EvmExternal) CallSolidityContract(callSolContractMsg types.CallSolContractMsg) provider.XplaClient

Call(as query) solidity contract.

func (EvmExternal) DeploySolidityContract added in v0.1.2

func (e EvmExternal) DeploySolidityContract(deploySolContractMsg types.DeploySolContractMsg) provider.XplaClient

Deploy soldity contract.

func (EvmExternal) EstimateGas added in v0.1.2

func (e EvmExternal) EstimateGas(invokeSolContractMsg types.InvokeSolContractMsg) provider.XplaClient

Query estimate gas.

func (EvmExternal) EthAccounts added in v0.1.2

func (e EvmExternal) EthAccounts() provider.XplaClient

Query all eth accounts.

func (EvmExternal) EthBlockNumber added in v0.1.2

func (e EvmExternal) EthBlockNumber() provider.XplaClient

Query latest block height(as number)

func (EvmExternal) EthChainID added in v0.1.2

func (e EvmExternal) EthChainID() provider.XplaClient

Query chain ID of ethereum type.

func (EvmExternal) EthCoinbase added in v0.1.2

func (e EvmExternal) EthCoinbase() provider.XplaClient

Query coinbase.

func (EvmExternal) EthGetBlockTransactionCount added in v0.1.2

func (e EvmExternal) EthGetBlockTransactionCount(ethGetBlockTransactionCountMsg types.EthGetBlockTransactionCountMsg) provider.XplaClient

Query the number of transaction a given block.

func (EvmExternal) EthGetFilterChanges added in v0.1.2

func (e EvmExternal) EthGetFilterChanges(ethGetFilterChangesMsg types.EthGetFilterChangesMsg) provider.XplaClient

Query filter changes.

func (EvmExternal) EthGetFilterLogs added in v0.1.2

func (e EvmExternal) EthGetFilterLogs(ethGetFilterLogsMsg types.EthGetFilterLogsMsg) provider.XplaClient

Query filter logs.

func (EvmExternal) EthGetLogs added in v0.1.2

func (e EvmExternal) EthGetLogs(ethGetLogsMsg types.EthGetLogsMsg) provider.XplaClient

Get logs.

func (EvmExternal) EthGetTransactionByBlockHashAndIndex added in v0.1.2

func (e EvmExternal) EthGetTransactionByBlockHashAndIndex(getTransactionByBlockHashAndIndexMsg types.GetTransactionByBlockHashAndIndexMsg) provider.XplaClient

Query transaction by block hash and index.

func (EvmExternal) EthGetTransactionReceipt added in v0.1.2

func (e EvmExternal) EthGetTransactionReceipt(getTransactionReceiptMsg types.GetTransactionReceiptMsg) provider.XplaClient

Query transaction receipt.

func (EvmExternal) EthNewBlockFilter added in v0.1.2

func (e EvmExternal) EthNewBlockFilter() provider.XplaClient

Query filter ID by eth new block filter.

func (EvmExternal) EthNewFilter added in v0.1.2

func (e EvmExternal) EthNewFilter(ethNewFilterMsg types.EthNewFilterMsg) provider.XplaClient

Query filter ID by eth new filter.

func (EvmExternal) EthNewPendingTransactionFilter added in v0.1.2

func (e EvmExternal) EthNewPendingTransactionFilter() provider.XplaClient

Query filter ID by eth new pending transaction filter.

func (EvmExternal) EthProtocolVersion added in v0.1.2

func (e EvmExternal) EthProtocolVersion() provider.XplaClient

ethereum protocol version.

func (EvmExternal) EthSyncing added in v0.1.2

func (e EvmExternal) EthSyncing() provider.XplaClient

Query the sync status object depending on the details of tendermint's sync protocol.

func (EvmExternal) EthUninstallFilter added in v0.1.2

func (e EvmExternal) EthUninstallFilter(ethUninstallFilterMsg types.EthUninstallFilterMsg) provider.XplaClient

Uninstall filter.

func (EvmExternal) EvmSendCoin added in v0.1.2

func (e EvmExternal) EvmSendCoin(sendCoinMsg types.SendCoinMsg) provider.XplaClient

Send coind by using evm client.

func (EvmExternal) GetBlockByHashOrHeight added in v0.1.2

func (e EvmExternal) GetBlockByHashOrHeight(getBlockByHashHeightMsg types.GetBlockByHashHeightMsg) provider.XplaClient

Query a block which is ethereum type information by retrieving hash or block height(as number).

func (EvmExternal) GetTransactionByHash added in v0.1.2

func (e EvmExternal) GetTransactionByHash(getTransactionByHashMsg types.GetTransactionByHashMsg) provider.XplaClient

Query a transaction which is ethereum type information by retrieving hash.

func (EvmExternal) InvokeSolidityContract added in v0.1.2

func (e EvmExternal) InvokeSolidityContract(invokeSolContractMsg types.InvokeSolContractMsg) provider.XplaClient

Invoke (as execute) solidity contract.

func (EvmExternal) NetListening added in v0.1.2

func (e EvmExternal) NetListening() provider.XplaClient

actively listening for network connections.

func (EvmExternal) NetPeerCount added in v0.1.2

func (e EvmExternal) NetPeerCount() provider.XplaClient

Query the number of peers currently connected to the client.

func (EvmExternal) NetVersion added in v0.1.2

func (e EvmExternal) NetVersion() provider.XplaClient

Query current network ID.

func (EvmExternal) SuggestGasPrice added in v0.1.2

func (e EvmExternal) SuggestGasPrice() provider.XplaClient

Query suggested gas price.

func (EvmExternal) Web3ClientVersion added in v0.1.2

func (e EvmExternal) Web3ClientVersion() provider.XplaClient

Query web3 client version.

func (EvmExternal) Web3Sha3 added in v0.1.2

func (e EvmExternal) Web3Sha3(web3Sha3Msg types.Web3Sha3Msg) provider.XplaClient

Query web3 sha3.

Jump to

Keyboard shortcuts

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