Skip to content

Commit de050b7

Browse files
committed
minor improvement
1 parent 225268a commit de050b7

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ devd query debug_traceTransaction [0xHash] [--tracer callTracer] [--evm-rpc http
7676
# devd q trace 0xHash
7777
# devd q trace 0xHash --tracer callTracer
7878

79-
devd query eth_call 0xContractAddr 0xCallData [--evm-rpc http://localhost:8545] [--from 0xFromAddr] [--height 5m/0xHex/latest] [--gas 500k/hex] [--gas-prices 20e9/hex] [--value 1e18/hex]
79+
devd query eth_call 0xContractAddr 0xCallData [--evm-rpc http://localhost:8545] [--from 0xFromAddr/Bech32] [--height 5m/0xHex/latest] [--gas 500k/0xHex] [--gas-prices 20e9/0xHex] [--value 1e18/0xHex]
8080

8181
devd query eth_chainId [--evm-rpc http://localhost:8545]
8282
```

cmd/query/eth_call.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ func GetQueryEvmRpcEthCallCommand() *cobra.Command {
2121
cmd := &cobra.Command{
2222
Use: "eth_call [contract address] [call data]",
2323
Short: "Call `eth_call` of EVM RPC: executes a new EVM message call immediately without creating a transaction on the block chain",
24-
Args: cobra.ExactArgs(2),
24+
Long: `Call "eth_call" of EVM RPC: executes a new EVM message call immediately without creating a transaction on the block chain.
25+
Bech32 account address is accepted.`,
26+
Args: cobra.ExactArgs(2),
2527
Run: func(cmd *cobra.Command, args []string) {
2628
ethClient, _ := flags.MustGetEthClient(cmd)
2729

28-
contractAddress := common.HexToAddress(args[0])
30+
evmAddrs, err := utils.GetEvmAddressFromAnyFormatAddress(args[0])
31+
utils.ExitOnErr(err, "failed to parse contract address")
32+
contractAddress := evmAddrs[0]
2933
callData, err := hex.DecodeString(strings.TrimPrefix(strings.ToLower(args[1]), "0x"))
3034
utils.ExitOnErr(err, "failed to decode call data")
3135

@@ -44,7 +48,9 @@ func GetQueryEvmRpcEthCallCommand() *cobra.Command {
4448
if from == "" {
4549
return common.Address{}
4650
}
47-
fromAddr := common.HexToAddress(from)
51+
evmAddrs, err := utils.GetEvmAddressFromAnyFormatAddress(from)
52+
utils.ExitOnErr(err, fmt.Sprintf("failed to parse address of --%s", flagFrom))
53+
fromAddr := evmAddrs[0]
4854
utils.PrintfStdErr("INF: using from: %s\n", fromAddr)
4955
return fromAddr
5056
}(),
@@ -62,9 +68,9 @@ func GetQueryEvmRpcEthCallCommand() *cobra.Command {
6268
}(),
6369
GasPrice: func() *big.Int {
6470
gasPrice, err := flags.ReadFlagShortIntOrHexOrNil(cmd, flags.FlagGasPrices)
65-
utils.ExitOnErr(err, "failed to parse gas price")
71+
utils.ExitOnErr(err, "failed to parse gas prices")
6672
if gasPrice != nil && gasPrice.Sign() == 1 {
67-
utils.PrintfStdErr("INF: using gas-price: %s\n", gasPrice)
73+
utils.PrintfStdErr("INF: using gas-prices: %s\n", gasPrice)
6874
}
6975
return gasPrice
7076
}(),
@@ -88,7 +94,7 @@ func GetQueryEvmRpcEthCallCommand() *cobra.Command {
8894
}
8995

9096
cmd.Flags().String(flags.FlagEvmRpc, "", flags.FlagEvmRpcDesc)
91-
cmd.Flags().StringP(flagFrom, "f", "", "the address from which the transaction is sent")
97+
cmd.Flags().StringP(flagFrom, "f", "", "the address from which the transaction is sent, support 0x or bech32")
9298
cmd.Flags().StringP(flags.FlagGasLimit, "g", "", "gas provided for the transaction execution, support short int and hex")
9399
cmd.Flags().StringP(flags.FlagGasPrices, "p", "", "gas prices used for each paid gas, support short int and hex")
94100
cmd.Flags().StringP(flagValue, "v", "", "value sent with this transaction, support short int and hex")

0 commit comments

Comments
 (0)