Skip to content

Commit

Permalink
Merge PR: add eth_multiCall (#998)
Browse files Browse the repository at this point in the history
* add eth_multiCall

* add FlagEnableMultiCall

Co-authored-by: Zhong Qiu <[email protected]>
  • Loading branch information
ylsGit and zhongqiuwood authored Aug 31, 2021
1 parent 55a0bed commit d7f76b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/rpc/namespaces/eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import (

const (
CacheOfEthCallLru = 40960

FlagEnableMultiCall = "rpc.enable-multi-call"
)

// PublicEthereumAPI is the eth_ prefixed set of APIs in the Web3 JSON-RPC spec.
Expand Down Expand Up @@ -330,7 +332,7 @@ func (api *PublicEthereumAPI) GetBalance(address common.Address, blockNum rpctyp
return (*hexutil.Big)(val), nil
}

// GetBalance returns the provided account's balance up to the provided block number.
// GetAccount returns the provided account's balance up to the provided block number.
func (api *PublicEthereumAPI) GetAccount(address common.Address) (*ethermint.EthAccount, error) {
acc, err := api.wrappedBackend.MustGetAccount(address.Bytes())
if err == nil {
Expand Down Expand Up @@ -390,7 +392,7 @@ func (api *PublicEthereumAPI) GetStorageAt(address common.Address, key string, b
return api.getStorageAt(address, common.HexToHash(key).Bytes(), blockNum, false)
}

// GetStorageAt returns the contract storage at the given address, block number, and key.
// GetStorageAtInternal returns the contract storage at the given address, block number, and key.
func (api *PublicEthereumAPI) GetStorageAtInternal(address common.Address, key []byte) (hexutil.Bytes, error) {
return api.getStorageAt(address, key, 0, true)
}
Expand Down Expand Up @@ -521,7 +523,7 @@ func (api *PublicEthereumAPI) GetCode(address common.Address, blockNumber rpctyp
return out.Code, nil
}

// GetCode returns the contract code at the given address and block number.
// GetCodeByHash returns the contract code at the given address and block number.
func (api *PublicEthereumAPI) GetCodeByHash(hash common.Hash) (hexutil.Bytes, error) {
code, err := api.wrappedBackend.GetCodeByHash(hash.Bytes())
if err == nil {
Expand Down Expand Up @@ -725,6 +727,26 @@ func (api *PublicEthereumAPI) Call(args rpctypes.CallArgs, blockNr rpctypes.Bloc
return data.Ret, nil
}

// MultiCall performs multiple raw contract call.
func (api *PublicEthereumAPI) MultiCall(args []rpctypes.CallArgs, blockNr rpctypes.BlockNumber, _ *map[common.Address]rpctypes.Account) ([]hexutil.Bytes, error) {
if !viper.GetBool(FlagEnableMultiCall) {
return nil, errors.New("the method is not allowed")
}

monitor := monitor.GetMonitor("eth_multiCall", api.logger, api.Metrics).OnBegin()
defer monitor.OnEnd("args", args, "block number", blockNr)

rets := make([]hexutil.Bytes, 0, len(args))
for _, arg := range args {
ret, err := api.Call(arg, blockNr, nil)
if err != nil {
return rets, err
}
rets = append(rets, ret)
}
return rets, nil
}

// DoCall performs a simulated call operation through the evmtypes. It returns the
// estimated gas used on the operation or an error if fails.
func (api *PublicEthereumAPI) doCall(
Expand Down
1 change: 1 addition & 0 deletions cmd/client/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func RegisterAppFlag(cmd *cobra.Command) {
cmd.Flags().String(rpc.FlagDisableAPI, "", "Set the RPC API to be disabled, such as \"eth_getLogs,eth_newFilter,eth_newBlockFilter,eth_newPendingTransactionFilter,eth_getFilterChanges\"")
cmd.Flags().Int(config.FlagDynamicGpWeight, 80, "The recommended weight of dynamic gas price [1,100])")
cmd.Flags().Bool(config.FlagEnableDynamicGp, true, "Enable node to dynamic support gas price suggest")
cmd.Flags().Bool(eth.FlagEnableMultiCall, false, "Enable node to support the eth_multiCall RPC API")

cmd.Flags().Bool(token.FlagOSSEnable, false, "Enable the function of exporting account data and uploading to oss")
cmd.Flags().String(token.FlagOSSEndpoint, "", "The OSS datacenter endpoint such as http://oss-cn-hangzhou.aliyuncs.com")
Expand Down

0 comments on commit d7f76b5

Please sign in to comment.