Skip to content

Commit e190031

Browse files
authored
Merge pull request #16 from bcdevtools/feat/v3
feat: v3
2 parents 817b6ea + 9ba1148 commit e190031

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1684
-978
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ GO_BIN := $(shell echo $(shell which go || echo "/usr/local/go/bin/go" ))
55
### Build flags ###
66
###############################################################################
77

8-
LD_FLAGS = -X github.com/bcdevtools/devd/v2/constants.VERSION=$(VERSION)
8+
LD_FLAGS = -X github.com/bcdevtools/devd/v3/constants.VERSION=$(VERSION)
99

1010
BUILD_FLAGS := -ldflags '$(LD_FLAGS)'
1111

README.md

Lines changed: 89 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
### Install
44

55
```bash
6-
go install -v github.com/bcdevtools/devd/v2/cmd/devd@latest
6+
go install -v github.com/bcdevtools/devd/v3/cmd/devd@latest
77
```
88

99
### Query tools
1010

11-
Lazy RPC setting
11+
Lazy EVM-RPC setting
1212
```bash
1313
export DEVD_EVM_RPC='https://evm.example.com:8545'
1414
```
15-
_By setting this environment variable, you don't need to pass `--rpc` flag everytime for non-localhost EVM Json-RPC_
15+
_By setting this environment variable, you don't need to pass `--evm-rpc` flag everytime for non-localhost EVM Json-RPC_
1616
___
1717
Lazy TM-RPC setting
1818
```bash
@@ -22,17 +22,15 @@ _By setting this environment variable, you don't need to pass `--tm-rpc` flag ev
2222
___
2323
Lazy Rest API setting
2424
```bash
25-
export DEVD_COSMOS_REST='https://ethermint-rest.example.com:1317'
25+
export DEVD_COSMOS_REST='https://cosmos-rest.example.com:1317'
2626
```
2727
_By setting this environment variable, you don't need to pass `--rest` flag everytime for non-localhost Rest API_
2828
___
29-
Some queries will try to decode some fields in response data into human-readable format
30-
and inject back into the response data with `_` prefix like EVM tx, receipt, block, trace.
3129

3230
#### Query account balance
3331

3432
```bash
35-
devd query balance [account addr] [optional ERC20 addr..] [--erc20] [--rpc http://localhost:8545]
33+
devd query balance [account addr] [optional ERC20 addr..] [--erc20] [--evm-rpc http://localhost:8545]
3634
# devd q b 0xAccount
3735
# devd q b ethm1account
3836
# devd q b 0xAccount 0xErc20Contract
@@ -41,6 +39,13 @@ devd query balance [account addr] [optional ERC20 addr..] [--erc20] [--rpc http:
4139
```
4240
_`--erc20` flag, if provided, will attempt to fetch user balance of contracts on `x/erc20` module and virtual frontier bank contracts. This request additional Rest-API endpoint provided, or use default 1317._
4341

42+
#### Query account info
43+
44+
```bash
45+
devd query account [0xAddress/Bech32] [--rest http://localhost:1317]
46+
# devd q acc 0xAccount
47+
```
48+
4449
#### Query block/tx events
4550

4651
```bash
@@ -54,40 +59,44 @@ _`--filter` flags, if provided, will accept events those contain at least one pr
5459
#### Query ERC20 token information
5560

5661
```bash
57-
devd query erc20 [ERC20 addr] [optional account] [--rpc http://localhost:8545]
62+
devd query erc20 [ERC20 addr] [optional account] [--evm-rpc http://localhost:8545]
5863
# devd q erc20 0xErc20Contract
5964
# devd q erc20 0xErc20Contract 0xAccount
6065
# devd q erc20 0xErc20Contract ethm1account
6166
```
6267

63-
#### Get EVM transaction information
68+
_This command will try to query `totalSupply()` if possible_
69+
70+
#### Query simple txs info in a block
6471

6572
```bash
66-
devd query eth_getTransactionByHash [0xHash] [--rpc http://localhost:8545]
67-
# devd q tx 0xHash
73+
devd query txs-in-block [block number] [--tm-rpc http://localhost:26657]
74+
# devd q txs-in-block 100000
6875
```
6976

70-
#### Get EVM transaction receipt
77+
#### Some EVM-RPC queries
7178

7279
```bash
73-
devd query eth_getTransactionReceipt [0xHash] [--rpc http://localhost:8545]
74-
# devd q receipt 0xHash
75-
```
80+
devd query eth_getTransactionByHash [0xHash] [--evm-rpc http://localhost:8545]
81+
# devd q evm-tx 0xHash
7682

77-
#### Get EVM block by number
83+
devd query eth_getTransactionReceipt [0xHash] [--evm-rpc http://localhost:8545]
84+
# devd q evm-receipt 0xHash
7885

79-
```bash
80-
devd query eth_getBlockByNumber [hex or dec block no] [--full] [--rpc http://localhost:8545]
81-
# devd q block 0xF
82-
# devd q block 16 --full
83-
```
86+
devd query eth_getBlockByNumber [hex or dec block no] [--full] [--evm-rpc http://localhost:8545]
87+
# devd q evm-block 0xF
88+
# devd q evm-block 16 --full
8489

85-
#### Trace EVM transaction
90+
devd query debug_traceTransaction [0xHash] [--tracer callTracer] [--evm-rpc http://localhost:8545]
91+
# devd q evm-trace 0xHash
92+
# devd q evm-trace 0xHash --tracer callTracer
8693

87-
```bash
88-
devd query debug_traceTransaction [0xHash] [--tracer callTracer] [--rpc http://localhost:8545]
89-
# devd q trace 0xHash
90-
# devd q trace 0xHash --tracer callTracer
94+
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]
95+
96+
devd query eth_getAccount [0xAddress/Bech32] [--evm-rpc http://localhost:8545]
97+
# devd q evm-account 0xAddress
98+
99+
devd query eth_chainId [--evm-rpc http://localhost:8545]
91100
```
92101

93102
### Tx tools
@@ -96,20 +105,22 @@ devd query debug_traceTransaction [0xHash] [--tracer callTracer] [--rpc http://l
96105

97106
```bash
98107
# Transfer native coin
99-
devd tx send [to] [amount]
108+
devd tx send [to] [amount] [--raw-tx]
100109
# Transfer ERC-20 token
101110
devd tx send [to] [amount] [--erc20 contract_address]
111+
# Use `--raw-tx` flag to see raw RLP-encoded EVM tx
102112
```
103113

104-
_Support custom integer like 1e18, 2k, 3m, 4b, 5kb,...: devd tx send [to] [1e18/1bb]_
114+
_support short int (2e18, 5bb,...): `devd tx send [to] [1e18/1bb]`_
105115

106116
#### Deploy EVM contract
107117

108118
```bash
109119
# Deploy contract with deployment bytecode
110-
devd tx deploy-contract [deployment bytecode] [--gas 4m] [--gas-prices 20b]
120+
devd tx deploy-contract [deployment bytecode] [--gas 4m] [--gas-prices 20b] [--raw-tx]
111121
# Deploy ERC-20 contract with pre-defined bytecode
112122
devd tx deploy-contract erc20
123+
# Use `--raw-tx` flag to see raw RLP-encoded EVM tx
113124
```
114125

115126
### Convert tools
@@ -128,86 +139,77 @@ devd convert address [address] [optional bech32 hrp]
128139

129140
***Support pipe***
130141
```bash
131-
devd convert abi_string [string or ABI encoded string]
132-
# devd c abi_string 000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000045553444300000000000000000000000000000000000000000000000000000000
133-
# devd c abi_string USDC Token
134-
# echo 'USDC Token' | devd c abi_string
142+
devd convert abi-string [string or ABI encoded string]
143+
# devd c abi-string 000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000045553444300000000000000000000000000000000000000000000000000000000
144+
# devd c abi-string USDC Token
145+
# echo 'USDC Token' | devd c abi-string
135146
```
136147

137148
#### Convert hexadecimal to decimal and vice versa
138149

139150
***Support pipe***
140151
```bash
141-
devd convert hex_2_dec [hexadecimal]
142-
# devd c h2d 0x16a
143-
# devd c h2d 16a
144-
# echo 16a | devd c h2d
145-
devd convert dec_2_hex [decimal]
146-
# devd c d2h 170
147-
# echo 170 | devd c d2h
148-
# Support custom integer like 1e18, 2k, 3m, 4b, 5kb,...:
149-
# devd c d2h 20bb
152+
devd convert hexadecimal [hexadecimal or decimal]
153+
# devd c hex 0x16a
154+
# echo 0x16a | devd c hex
155+
# devd c hex 362
156+
# echo 362 | devd c hex
150157
```
151158

152159
#### Convert Solidity event/method signature into hashed signature
153160

154161
```bash
155-
devd convert solc_sig [event/method signature]
156-
# devd c solc_sig 'transfer(address,uint256)'
157-
# devd c solc_sig 'function transfer(address recipient, uint256 amount) external returns (bool);'
158-
# devd c solc_sig 'event Transfer(address indexed from, address indexed to, uint256 value);'
162+
devd convert solc-sig [event/method signature]
163+
# devd c solc-sig 'transfer(address,uint256)'
164+
# devd c solc-sig 'function transfer(address recipient, uint256 amount) external returns (bool);'
165+
# devd c solc-sig 'event Transfer(address indexed from, address indexed to, uint256 value);'
159166
```
160167

161-
#### Convert input into upper/lower case
168+
#### Convert input into lower/upper case
162169

163170
***Support pipe***
164171
```bash
165-
devd convert to_lower_case [input]
166-
# devd c lowercase AA
167-
# echo AA | devd c lowercase
168-
devd convert to_upper_case [input]
169-
# devd c uppercase aa
170-
# echo aa | devd c uppercase
172+
devd convert case [input]
173+
# devd c case AA
174+
# echo AA | devd c case
175+
# > aa
176+
devd convert case [input] --upper
177+
# devd c case aa
178+
# echo aa | devd c case --upper
179+
# > AA
171180
```
172181
173182
#### Encode/Decode base64
174183
175184
***Support pipe***
176185
```bash
177-
devd convert encode_base64 [input]
186+
devd convert base64 [input]
178187
# devd c base64 123
179188
# echo 123 | devd c base64
180-
devd convert decode_base64 [base64]
181-
# devd c decode_base64 TVRJeg==
182-
# echo TVRJeg== | devd c decode_base64
189+
devd convert base64 [base64] --decode
190+
# devd c base64 TVRJeg== --decode
191+
# echo TVRJeg== | devd c base64 --decode
183192
```
184193
185194
#### Convert raw balance into display balance and vice versa
186195
187196
```bash
188-
devd convert display_balance [raw balance] [exponent]
197+
devd convert display-balance [raw balance] [exponent]
189198
# devd c dbal 10011100 6
190199
# > 10.0111
191-
# Support custom integer like 1e18, 2k, 3m, 4b, 5kb,...:
200+
# Support short int:
192201
# devd c dbal 20bb 18
193202
# > 20.0
194203
```
195204
196205
```bash
197-
devd convert raw_balance [display balance] [exponent] [--decimals-point , or .]
206+
devd convert raw-balance [display balance] [exponent] [--decimals-point , or .]
198207
# devd c rbal 10.0111 6
199208
# > 10011100
200209
# devd c rbal 10,0111 6 -d ,
201210
# > 10011100
202211
```
203212
204-
#### Convert (decode) raw RLP-encoded EVM tx into tx object
205-
206-
```bash
207-
devd convert decode_raw_tx [raw RLP-encoded EVM tx hex]
208-
# view inner tx information, including sender address
209-
```
210-
211213
### Hashing tools
212214
213215
***Support pipe***
@@ -237,11 +239,19 @@ devd check port [port]
237239
238240
### Debug tools
239241
242+
#### Decode raw RLP-encoded EVM tx into tx object
243+
244+
```bash
245+
devd debug raw-tx [raw RLP-encoded EVM tx hex]
246+
# devd debug raw-tx 0x02f8af82271c3b83112a8883aba95082be209480b5a32e4f032b2a058b4f29ec95eefeeb87adcd80b844a9059cbb000000000000000000000000bfcfe6d5ad56aa831313856949e98656d46f9248000000000000000000000000000000000000000000000000002386f26fc10000c001a088907374a796ed70a5a2bdc51b50010b68dcc4d2ed12d94abc607bb0a90271b6a0167d3e031b70ec511b67416d9ad8334caee7013d95ff8275721b23798c5c3602
247+
```
248+
_to view inner tx information, including sender address_
249+
240250
#### Compute EVM transaction intrinsic gas
241251
242252
```bash
243-
devd debug intrinsic_gas [0xCallData]
244-
# devd d intrinsic_gas 0xCallData
253+
devd debug intrinsic-gas [0xCallData]
254+
# devd d intrinsic-gas 0xCallData
245255
```
246256
_Assumption: no access list, not contract creation, Homestead, EIP-2028 (Istanbul). If contract creation, plus 32,000 into the output._
247257
@@ -250,5 +260,13 @@ _Assumption: no access list, not contract creation, Homestead, EIP-2028 (Istanbu
250260
- Output messages are printed via stdout, while messages with prefixes `INF:` `WARN:` and `ERR:` are printed via stderr. So for integration with other tools, to omit stderr, forward stdout only.
251261
> Eg: `devd c a cosmos1... 1> /tmp/output.txt`
252262
- When passing arguments into command via both argument and pipe, the argument will be used.
253-
> Eg: `echo 123 | devd c d2h 456` will convert `456` to hexadecimal, not `123`.
254-
- For commands those marked `support custom integer`, you can pass number with format like `1e18`, `1k` (thousand), `2m` (million), `3b` (billion), `4kb` (trillion), `5mb` (million billion), `6bb`,... Decimal point also supported for `k`, `m`, `b` suffixes like `1.5k`, `2.5m`, `3.5bb`,...
263+
> Eg: `echo 123 | devd c hex 456` will convert `456` to hexadecimal, not `123`.
264+
- For commands those marked `support short int`, you can pass number with format like:
265+
- `2e18` = 2 x 10^18
266+
- `2k` = 2,000
267+
- `2.7m` = 2,700,000
268+
- `3.08b` = 3,080,000,000
269+
- `4kb` = 4,000,000,000,000
270+
- `5.555mb` = 5,555,000,000,000,000
271+
- `6bb` = 6,000,000,000,000,000,000 = 6e18
272+
- Some queries will try to decode some fields in response data into human-readable format and inject back into the response data with `_` prefix like EVM tx, receipt, block, trace.

cmd/check/port.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66
"strconv"
77

8-
"github.com/bcdevtools/devd/v2/cmd/utils"
8+
"github.com/bcdevtools/devd/v3/cmd/utils"
99
psnet "github.com/shirou/gopsutil/v3/net"
1010
"github.com/shirou/gopsutil/v3/process"
1111
"github.com/spf13/cobra"

cmd/convert/abi_string.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"regexp"
77
"strings"
88

9-
"github.com/bcdevtools/devd/v2/cmd/utils"
9+
"github.com/bcdevtools/devd/v3/cmd/utils"
1010
"github.com/spf13/cobra"
1111
)
1212

1313
func GetConvertAbiStringCmd() *cobra.Command {
1414
cmd := &cobra.Command{
15-
Use: "abi_string [hex or text]",
15+
Use: "abi-string [hex or text]",
1616
Short: `Convert ABI encoded hex to string or vice versa.`,
1717
Long: `Convert ABI encoded hex to string or vice versa.
1818
Support pipe.`,

cmd/convert/address.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"regexp"
77
"strings"
88

9-
"github.com/bcdevtools/devd/v2/cmd/utils"
9+
"github.com/bcdevtools/devd/v3/cmd/utils"
1010
sdk "github.com/cosmos/cosmos-sdk/types"
1111
"github.com/cosmos/cosmos-sdk/types/bech32"
1212
"github.com/ethereum/go-ethereum/common"
@@ -16,7 +16,7 @@ import (
1616
// GetConvertAddressCmd creates a helper command that convert account bech32 address into hex address or vice versa
1717
func GetConvertAddressCmd() *cobra.Command {
1818
cmd := &cobra.Command{
19-
Use: "address [account] [bech32 hrp]",
19+
Use: "address [account] [?bech32 hrp]",
2020
Aliases: []string{"a"},
2121
Short: "Convert account bech32 address into hex address or vice versa.",
2222
Long: `Convert account bech32 address into hex address or vice versa.

cmd/convert/base64.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package convert
2+
3+
import (
4+
"encoding/base64"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/bcdevtools/devd/v3/cmd/utils"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
const (
13+
flagDecode = "decode"
14+
)
15+
16+
// GetBase64CaseCmd creates a helper command that encode/decode base64
17+
func GetBase64CaseCmd() *cobra.Command {
18+
cmd := &cobra.Command{
19+
Use: "base64 [input]",
20+
Short: fmt.Sprintf("Encode base64, use --%s to decode", flagDecode),
21+
Long: fmt.Sprintf(`Encode/decode base64, use --%s to decode.
22+
Support pipe.`, flagDecode),
23+
Run: func(cmd *cobra.Command, args []string) {
24+
args, err := utils.ProvidedArgsOrFromPipe(args)
25+
utils.ExitOnErr(err, "failed to get args from pipe")
26+
27+
if cmd.Flag(flagDecode).Changed {
28+
utils.RequireExactArgsCount(args, 1, cmd)
29+
utils.PrintlnStdErr("INF: decoding base64")
30+
data, err := base64.StdEncoding.DecodeString(args[0])
31+
utils.ExitOnErr(err, "failed to decode base64")
32+
fmt.Println(string(data))
33+
} else {
34+
utils.RequireArgs(args, cmd)
35+
utils.PrintfStdErr("INF: encoding base64 (use --%s to decode)\n", flagDecode)
36+
fmt.Println(base64.StdEncoding.EncodeToString([]byte(strings.Join(args, " "))))
37+
}
38+
},
39+
}
40+
41+
cmd.Flags().BoolP(flagDecode, "d", false, "decode base64 instead of encode")
42+
43+
return cmd
44+
}

0 commit comments

Comments
 (0)