ethRPCExecShells

package
v0.0.0-...-5495d05 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ETHAccounts = &EthRPCExecShell{
	name:   Method_eth_accounts,
	defRet: []types.Address{},
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.Accounts()
	},
}
View Source
var ETHBlockNumber = &EthRPCExecShell{
	name:   Method_eth_blockNumber,
	defRet: "0",
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.BlockNumber()
	},
}
View Source
var ETHCall = &EthRPCExecShell{
	name:        Method_eth_call,
	minParamLen: 1,
	maxParamLen: 2,
	execFn: func(params []any) (any, *RPCProviderError) {
		tx, blk, err := getETHCallParam(params)
		if err != nil {
			return nil, err
		}
		return rpcProvider.Call(*tx, *blk)
	},
}
View Source
var ETHChainId = &EthRPCExecShell{
	name: Method_eth_chainId,
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.ChainId()
	},
}
View Source
var ETHCoinbase = &EthRPCExecShell{
	name:   Method_eth_coinbase,
	defRet: types.Address{},
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.Coinbase()
	},
}
View Source
var ETHEstimateGas = &EthRPCExecShell{
	name:        Method_eth_estimateGas,
	minParamLen: 1,
	maxParamLen: 2,
	execFn: func(params []any) (any, *RPCProviderError) {
		tx, blk, err := getETHCallParam(params)
		if err != nil {
			return nil, err
		}
		return rpcProvider.EstimateGas(*tx, *blk)
	},
}
View Source
var ETHGasPrice = &EthRPCExecShell{
	name:   Method_eth_gasPrice,
	defRet: "0",
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.GasPrice()
	},
}
View Source
var ETHGetBalance = &EthRPCExecShell{
	name:        Method_eth_getBalance,
	minParamLen: 2,
	maxParamLen: 2,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		addr, blk, err := extractAddressAndBlock(params[0], params[1])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.Balance(*addr, *blk)
	},
}
View Source
var ETHGetBlockByHash = &EthRPCExecShell{
	name:        Method_eth_getBlockByHash,
	minParamLen: 2,
	maxParamLen: 2,
	execFn: func(params []any) (any, *RPCProviderError) {
		blkHash, err := extractHash(params[0])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		txFlag, flagOk := params[1].(bool)
		if !flagOk {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.BlockByHash(*blkHash, txFlag)
	},
}
View Source
var ETHGetBlockByNumber = &EthRPCExecShell{
	name:        Method_eth_getBlockByNumber,
	minParamLen: 2,
	maxParamLen: 2,
	execFn: func(params []any) (any, *RPCProviderError) {
		var blk EthBlockNumString

		if !blk.FromAny(params[0]) {
			return nil, ProviderInvalidParams
		}

		txFlag, flagOk := params[1].(bool)
		if !flagOk {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.BlockByNumber(blk, txFlag)
	},
}
View Source
var ETHGetBlockTransactionCountByHash = &EthRPCExecShell{
	name:        Method_eth_getBlockTransactionCountByHash,
	minParamLen: 1,
	maxParamLen: 1,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		blkHash, err := extractHash(params[0])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.BlockTransactionCountByHash(*blkHash)
	},
}
View Source
var ETHGetBlockTransactionCountByNumber = &EthRPCExecShell{
	name:        Method_eth_getBlockTransactionCountByNumber,
	minParamLen: 1,
	maxParamLen: 1,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		var blk EthBlockNumString

		if !blk.FromAny(params[0]) {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.BlockTransactionCountByNumber(blk)
	},
}
View Source
var ETHGetCode = &EthRPCExecShell{
	name:        Method_eth_getCode,
	minParamLen: 2,
	maxParamLen: 2,
	defRet:      "0x",
	execFn: func(params []any) (any, *RPCProviderError) {
		addr, blk, err := extractAddressAndBlock(params[0], params[1])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.Code(*addr, *blk)
	},
}
View Source
var ETHGetLogs = &EthRPCExecShell{
	name:        Method_eth_getLogs,
	minParamLen: 1,
	maxParamLen: 1,
	defRet:      []EthLog{},
	execFn: func(params []any) (any, *RPCProviderError) {
		logParam := &EthGetLogsParam{}
		paramJSON, _ := json.Marshal(params[0])

		err := json.Unmarshal(paramJSON, logParam)
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.Logs(*logParam)
	},
}
View Source
var ETHGetStorageAt = &EthRPCExecShell{
	name:        Method_eth_getStorageAt,
	minParamLen: 3,
	maxParamLen: 3,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		var addr types.Address
		err := addr.FromParam(params[0])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		var pos types.Key
		err = pos.FromParam(params[1])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		var blk EthBlockNumString
		if !blk.FromAny(params[2]) {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.StorageAt(addr, pos, blk)
	},
}
View Source
var ETHGetTransactionByBlockHashAndIndex = &EthRPCExecShell{
	name:        Method_eth_getTransactionByBlockHashAndIndex,
	minParamLen: 2,
	maxParamLen: 2,
	execFn: func(params []any) (any, *RPCProviderError) {
		blkHash, idx, err := extractHashAndInt(params[0], params[1])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.TransactionByBlockHashAndIndex(*blkHash, idx)
	},
}
View Source
var ETHGetTransactionByBlockNumberAndIndex = &EthRPCExecShell{
	name:        Method_eth_getTransactionByBlockNumberAndIndex,
	minParamLen: 2,
	maxParamLen: 2,
	execFn: func(params []any) (any, *RPCProviderError) {
		blk, idx, err := extractBlkNumAndInt(params[0], params[1])

		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.TransactionByBlockNumberAndIndex(*blk, idx)
	},
}
View Source
var ETHGetTransactionByHash = &EthRPCExecShell{
	name:        Method_eth_getTransactionByHash,
	minParamLen: 1,
	maxParamLen: 1,
	execFn: func(params []any) (any, *RPCProviderError) {
		txHash, err := extractHash(params[0])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.TransactionByHash(*txHash)
	},
}
View Source
var ETHGetTransactionCount = &EthRPCExecShell{
	name:        Method_eth_getTransactionCount,
	minParamLen: 2,
	maxParamLen: 2,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		addr, blk, err := extractAddressAndBlock(params[0], params[1])
		if err != nil {
			return nil, ProviderInvalidParams
		}
		return rpcProvider.TransactionCount(*addr, *blk)
	},
}
View Source
var ETHGetTransactionReceipt = &EthRPCExecShell{
	name:        Method_eth_getTransactionReceipt,
	minParamLen: 1,
	maxParamLen: 1,
	execFn: func(params []any) (any, *RPCProviderError) {
		txHash, err := extractHash(params[0])

		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.TransactionReceipt(*txHash)
	},
}
View Source
var ETHGetUncleByBlockHashAndIndex = &EthRPCExecShell{
	name:        Method_eth_getUncleByBlockHashAndIndex,
	minParamLen: 2,
	maxParamLen: 2,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		blkHash, err := extractHash(params[0])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		idx, err := utils.HexParamToUint64(params[1])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.UncleByBlockHashAndIndex(*blkHash, idx)
	},
}
View Source
var ETHGetUncleByBlockNumberAndIndex = &EthRPCExecShell{
	name:        Method_eth_getUncleByBlockNumberAndIndex,
	minParamLen: 2,
	maxParamLen: 2,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		var blk EthBlockNumString
		if !blk.FromAny(params[0]) {
			return nil, ProviderInvalidParams
		}

		idx, err := utils.HexParamToUint64(params[1])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.UncleByBlockNumberAndIndex(blk, idx)
	},
}
View Source
var ETHGetUncleCountByBlockHash = &EthRPCExecShell{
	name:        Method_eth_getUncleCountByBlockHash,
	minParamLen: 1,
	maxParamLen: 1,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		txHash, err := extractHash(params[0])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.UncleCountByBlockHash(*txHash)
	},
}
View Source
var ETHGetUncleCountByBlockNumber = &EthRPCExecShell{
	name:        Method_eth_getUncleCountByBlockNumber,
	minParamLen: 1,
	maxParamLen: 1,
	defRet:      "0x0",
	execFn: func(params []any) (any, *RPCProviderError) {
		var blk EthBlockNumString

		if !blk.FromAny(params[0]) {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.UncleCountByBlockNumber(blk)
	},
}
View Source
var ETHHashRate = &EthRPCExecShell{
	name:   Method_eth_hashrate,
	defRet: "0",
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.HashRate()
	},
}
View Source
var ETHMining = &EthRPCExecShell{
	name:   Method_eth_mining,
	defRet: false,
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.Mining()
	},
}
View Source
var ETHSendRawTransaction = &EthRPCExecShell{
	name:        Method_eth_sendRawTransaction,
	minParamLen: 1,
	maxParamLen: 1,
	execFn: func(params []any) (any, *RPCProviderError) {
		var txData types.Data
		err := txData.FromParam(params[0])
		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.SendRawTransaction(txData)
	},
}
View Source
var ETHSendTransaction = &EthRPCExecShell{
	name:        Method_eth_sendTransaction,
	minParamLen: 1,
	maxParamLen: 1,
	execFn: func(params []any) (any, *RPCProviderError) {
		txJSON, _ := json.Marshal(params[0])
		tx := &EthBasicTransaction{}
		err := json.Unmarshal(txJSON, tx)

		if err != nil {
			return nil, ProviderInvalidParams
		}

		return rpcProvider.SendTransaction(*tx)
	},
}
View Source
var ETHSyncing = &EthRPCExecShell{
	name:   Method_eth_syncing,
	defRet: false,
	execFn: func([]any) (any, *RPCProviderError) {
		status, data, err := rpcProvider.Syncing()
		if err != nil {
			return nil, err
		}

		if data != nil {
			return data, nil
		}

		return status, err
	},
}
View Source
var NetVersion = &EthRPCExecShell{
	name:   Method_net_version,
	defRet: "unknown",
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.NetVersion()
	},
}
View Source
var Web3ClientVersion = &EthRPCExecShell{
	name:   Method_web3_clientVersion,
	defRet: "unknown",
	execFn: func([]any) (any, *RPCProviderError) {
		return rpcProvider.Web3ClientVersion()
	},
}

Functions

func RegisterProvider

func RegisterProvider(provider ethereumRPCProvider.IEthereumRPCProvider)

Types

type EthRPCExecShell

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

func GenUnsupportedShell

func GenUnsupportedShell(name string) *EthRPCExecShell

func NewEthRPCExecShell

func NewEthRPCExecShell(
	name string,
	minParamLen int,
	maxParamLen int,
	defRet any,
	execFun RPCExecuteFunc,
) *EthRPCExecShell

func (EthRPCExecShell) Execute

func (e EthRPCExecShell) Execute(req *EthRPCRequest) (*EthRPCResult, *EthRPCError)

func (EthRPCExecShell) Name

func (e EthRPCExecShell) Name() string

type RPCExecuteFunc

type RPCExecuteFunc func(param []any) (any, *RPCProviderError)

Jump to

Keyboard shortcuts

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