forked from cerc-io/laconicd-deprecated
Minor fixes (#94)
- Updates RPC return types
- Removes custom query types in favour of default eth
- This is largely to allow for proper hexadecimal formatting (provided by `hexutil`), as the API is very specific about formatting.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -42,7 +43,7 @@ func GetCmdGetBlockNumber(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
return nil
|
||||
}
|
||||
|
||||
var out types.QueryResBlockNumber
|
||||
var out *hexutil.Big
|
||||
cdc.MustUnmarshalJSON(res, &out)
|
||||
return cliCtx.PrintOutput(out)
|
||||
},
|
||||
@@ -67,7 +68,7 @@ func GetCmdGetStorageAt(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
fmt.Printf("could not resolve: %s\n", err)
|
||||
return nil
|
||||
}
|
||||
var out types.QueryResStorage
|
||||
var out hexutil.Bytes
|
||||
cdc.MustUnmarshalJSON(res, &out)
|
||||
return cliCtx.PrintOutput(out)
|
||||
},
|
||||
@@ -91,9 +92,9 @@ func GetCmdGetCode(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
fmt.Printf("could not resolve: %s\n", err)
|
||||
return nil
|
||||
}
|
||||
var out types.QueryResCode
|
||||
var out []byte
|
||||
cdc.MustUnmarshalJSON(res, &out)
|
||||
return cliCtx.PrintOutput(out)
|
||||
return cliCtx.PrintOutput(hexutil.Bytes(out))
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -115,7 +116,7 @@ func GetCmdGetNonce(queryRoute string, cdc *codec.Codec) *cobra.Command {
|
||||
fmt.Printf("could not resolve: %s\n", err)
|
||||
return nil
|
||||
}
|
||||
var out types.QueryResNonce
|
||||
var out hexutil.Uint64
|
||||
cdc.MustUnmarshalJSON(res, &out)
|
||||
return cliCtx.PrintOutput(out)
|
||||
},
|
||||
|
||||
+16
-24
@@ -1,12 +1,9 @@
|
||||
package evm
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/ethermint/version"
|
||||
"github.com/cosmos/ethermint/x/evm/types"
|
||||
ethcmn "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
@@ -47,7 +44,8 @@ func NewQuerier(keeper Keeper) sdk.Querier {
|
||||
func queryProtocolVersion(keeper Keeper) ([]byte, sdk.Error) {
|
||||
vers := version.ProtocolVersion
|
||||
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, vers)
|
||||
bigRes := hexutil.Uint(vers)
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, bigRes)
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
}
|
||||
@@ -58,16 +56,9 @@ func queryProtocolVersion(keeper Keeper) ([]byte, sdk.Error) {
|
||||
func queryBalance(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Error) {
|
||||
addr := ethcmn.BytesToAddress([]byte(path[1]))
|
||||
balance := keeper.GetBalance(ctx, addr)
|
||||
hBalance := &hexutil.Big{}
|
||||
err := hBalance.UnmarshalText(balance.Bytes())
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, balance)
|
||||
if err != nil {
|
||||
panic("could not marshal big.Int to hexutil.Big")
|
||||
}
|
||||
|
||||
bRes := types.QueryResBalance{Balance: hBalance}
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, bRes)
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
panic("could not marshal result to JSON: ")
|
||||
}
|
||||
|
||||
return res, nil
|
||||
@@ -75,10 +66,12 @@ func queryBalance(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Er
|
||||
|
||||
func queryBlockNumber(ctx sdk.Context, keeper Keeper) ([]byte, sdk.Error) {
|
||||
num := ctx.BlockHeight()
|
||||
bnRes := types.QueryResBlockNumber{Number: big.NewInt(num)}
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, bnRes)
|
||||
hexUint := hexutil.Uint64(num)
|
||||
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, hexUint)
|
||||
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
panic("could not marshal result to JSON: " + err.Error())
|
||||
}
|
||||
|
||||
return res, nil
|
||||
@@ -88,10 +81,10 @@ func queryStorage(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Er
|
||||
addr := ethcmn.BytesToAddress([]byte(path[1]))
|
||||
key := ethcmn.BytesToHash([]byte(path[2]))
|
||||
val := keeper.GetState(ctx, addr, key)
|
||||
bRes := types.QueryResStorage{Value: val.Bytes()}
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, bRes)
|
||||
bRes := hexutil.Bytes(val.Bytes())
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, &bRes)
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
panic("could not marshal result to JSON: " + err.Error())
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@@ -99,10 +92,9 @@ func queryStorage(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Er
|
||||
func queryCode(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Error) {
|
||||
addr := ethcmn.BytesToAddress([]byte(path[1]))
|
||||
code := keeper.GetCode(ctx, addr)
|
||||
cRes := types.QueryResCode{Code: code}
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, cRes)
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, code)
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
panic("could not marshal result to JSON: " + err.Error())
|
||||
}
|
||||
|
||||
return res, nil
|
||||
@@ -111,10 +103,10 @@ func queryCode(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Error
|
||||
func queryNonce(ctx sdk.Context, path []string, keeper Keeper) ([]byte, sdk.Error) {
|
||||
addr := ethcmn.BytesToAddress([]byte(path[1]))
|
||||
nonce := keeper.GetNonce(ctx, addr)
|
||||
nRes := types.QueryResNonce{Nonce: nonce}
|
||||
nRes := hexutil.Uint64(nonce)
|
||||
res, err := codec.MarshalJSONIndent(keeper.cdc, nRes)
|
||||
if err != nil {
|
||||
panic("could not marshal result to JSON")
|
||||
panic("could not marshal result to JSON: " + err.Error())
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
)
|
||||
|
||||
// QueryResProtocolVersion is response type for protocol version query
|
||||
type QueryResProtocolVersion struct {
|
||||
Version string `json:"result"`
|
||||
}
|
||||
|
||||
func (q QueryResProtocolVersion) String() string {
|
||||
return q.Version
|
||||
}
|
||||
|
||||
// QueryResBalance is response type for balance query
|
||||
type QueryResBalance struct {
|
||||
Balance *hexutil.Big `json:"result"`
|
||||
}
|
||||
|
||||
func (q QueryResBalance) String() string {
|
||||
return q.Balance.String()
|
||||
}
|
||||
|
||||
// QueryResBlockNumber is response type for block number query
|
||||
type QueryResBlockNumber struct {
|
||||
Number *big.Int `json:"result"`
|
||||
}
|
||||
|
||||
func (q QueryResBlockNumber) String() string {
|
||||
return q.Number.String()
|
||||
}
|
||||
|
||||
// QueryResStorage is response type for storage query
|
||||
type QueryResStorage struct {
|
||||
Value []byte `json:"value"`
|
||||
}
|
||||
|
||||
func (q QueryResStorage) String() string {
|
||||
return string(q.Value)
|
||||
}
|
||||
|
||||
// QueryResCode is response type for code query
|
||||
type QueryResCode struct {
|
||||
Code []byte
|
||||
}
|
||||
|
||||
func (q QueryResCode) String() string {
|
||||
return string(q.Code)
|
||||
}
|
||||
|
||||
// QueryResNonce is response type for Nonce query
|
||||
type QueryResNonce struct {
|
||||
Nonce uint64 `json:"result"`
|
||||
}
|
||||
|
||||
func (q QueryResNonce) String() string {
|
||||
return string(q.Nonce)
|
||||
}
|
||||
Reference in New Issue
Block a user