forked from cerc-io/laconicd-deprecated
evm: add parameter check for evm query func (#746)
* add parameter check for evm query func * update changelog Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
parent
bfa9a733e0
commit
f0bf151176
@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
### Bug Fixes
|
||||
|
||||
* (evm) [\#747](https://github.com/cosmos/ethermint/issues/747) Fix format errors in String() of QueryETHLogs
|
||||
* (evm) [\#742](https://github.com/cosmos/ethermint/issues/742) Add parameter check for evm query func.
|
||||
* (evm) [\#687](https://github.com/cosmos/ethermint/issues/687) Fix nonce check to explicitly check for the correct nonce, rather than a simple 'greater than' comparison.
|
||||
* (api) [\#687](https://github.com/cosmos/ethermint/issues/687) Returns error for a transaction with an incorrect nonce.
|
||||
* (evm) [\#674](https://github.com/cosmos/ethermint/issues/674) Reset all cache after account data has been committed in `EndBlock` to make sure every node state consistent.
|
||||
|
@ -19,6 +19,11 @@ import (
|
||||
// NewQuerier is the module level router for state queries
|
||||
func NewQuerier(keeper Keeper) sdk.Querier {
|
||||
return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) {
|
||||
if len(path) < 1 {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
|
||||
"Insufficient parameters, at least 1 parameter is required")
|
||||
}
|
||||
|
||||
switch path[0] {
|
||||
case types.QueryBalance:
|
||||
return queryBalance(ctx, path, keeper)
|
||||
@ -45,6 +50,11 @@ func NewQuerier(keeper Keeper) sdk.Querier {
|
||||
}
|
||||
|
||||
func queryBalance(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
|
||||
if len(path) < 2 {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
|
||||
"Insufficient parameters, at least 2 parameters is required")
|
||||
}
|
||||
|
||||
addr := ethcmn.HexToAddress(path[1])
|
||||
balance := keeper.GetBalance(ctx, addr)
|
||||
balanceStr, err := utils.MarshalBigInt(balance)
|
||||
@ -73,6 +83,11 @@ func queryBlockNumber(ctx sdk.Context, keeper Keeper) ([]byte, error) {
|
||||
}
|
||||
|
||||
func queryStorage(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
|
||||
if len(path) < 3 {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
|
||||
"Insufficient parameters, at least 3 parameters is required")
|
||||
}
|
||||
|
||||
addr := ethcmn.HexToAddress(path[1])
|
||||
key := ethcmn.HexToHash(path[2])
|
||||
val := keeper.GetState(ctx, addr, key)
|
||||
@ -85,6 +100,11 @@ func queryStorage(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error)
|
||||
}
|
||||
|
||||
func queryCode(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
|
||||
if len(path) < 2 {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
|
||||
"Insufficient parameters, at least 2 parameters is required")
|
||||
}
|
||||
|
||||
addr := ethcmn.HexToAddress(path[1])
|
||||
code := keeper.GetCode(ctx, addr)
|
||||
res := types.QueryResCode{Code: code}
|
||||
@ -97,6 +117,11 @@ func queryCode(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
|
||||
}
|
||||
|
||||
func queryHashToHeight(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
|
||||
if len(path) < 2 {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
|
||||
"Insufficient parameters, at least 2 parameters is required")
|
||||
}
|
||||
|
||||
blockHash := ethcmn.FromHex(path[1])
|
||||
blockNumber, found := keeper.GetBlockHash(ctx, blockHash)
|
||||
if !found {
|
||||
@ -113,6 +138,11 @@ func queryHashToHeight(ctx sdk.Context, path []string, keeper Keeper) ([]byte, e
|
||||
}
|
||||
|
||||
func queryBlockBloom(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
|
||||
if len(path) < 2 {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
|
||||
"Insufficient parameters, at least 2 parameters is required")
|
||||
}
|
||||
|
||||
num, err := strconv.ParseInt(path[1], 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal block height: %w", err)
|
||||
@ -133,6 +163,11 @@ func queryBlockBloom(ctx sdk.Context, path []string, keeper Keeper) ([]byte, err
|
||||
}
|
||||
|
||||
func queryTransactionLogs(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
|
||||
if len(path) < 2 {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
|
||||
"Insufficient parameters, at least 2 parameters is required")
|
||||
}
|
||||
|
||||
txHash := ethcmn.HexToHash(path[1])
|
||||
|
||||
logs, err := keeper.GetLogs(ctx, txHash)
|
||||
@ -161,6 +196,11 @@ func queryLogs(ctx sdk.Context, keeper Keeper) ([]byte, error) {
|
||||
}
|
||||
|
||||
func queryAccount(ctx sdk.Context, path []string, keeper Keeper) ([]byte, error) {
|
||||
if len(path) < 2 {
|
||||
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
|
||||
"Insufficient parameters, at least 2 parameters is required")
|
||||
}
|
||||
|
||||
addr := ethcmn.HexToAddress(path[1])
|
||||
so := keeper.GetOrNewStateObject(ctx, addr)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user