Skip to content

Commit a51170c

Browse files
committed
improve message content
1 parent e1bc6a9 commit a51170c

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Lazy Rest API setting
1818
```bash
1919
export DEVD_COSMOS_REST='https://cosmos.example.com:1317'
2020
```
21-
_By setting this environment variable, you don't need to pass `--rest` flag everytime for non-localhost Rest API
21+
_By setting this environment variable, you don't need to pass `--rest` flag everytime for non-localhost Rest API_
2222

2323
#### Query account balance
2424

@@ -194,7 +194,7 @@ _Assumption: no access list, not contract creation, Homestead, EIP-2028 (Istanbu
194194

195195
### Notes:
196196

197-
- Output messages are printed via stdout, while messages with prefixes `WARN:` and `ERR:` are printed via stderr. So for integration with other tools, to omit stderr, forward stdout only.
197+
- 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.
198198
> Eg: `devd c a cosmos1... 1> /tmp/output.txt`
199199
- When passing arguments into command via both argument and pipe, the argument will be used.
200200
> Eg: `echo 123 | devd c d2h 456` will convert `456` to hexadecimal, not `123`.

cmd/query/balance.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func GetQueryBalanceCommand() *cobra.Command {
4949
display, high, low, err := utils.ConvertNumberIntoDisplayWithExponent(nativeBalance, 18)
5050
utils.ExitOnErr(err, "failed to convert number into display with exponent")
5151

52-
printRow("Native", "-", "(native)", display, nativeBalance.String(), "18", high.String(), low.String(), "")
52+
printRow("native", "-", "(native)", display, nativeBalance.String(), "18", high.String(), low.String(), "")
5353

5454
for i := 1; i < len(evmAddrs); i++ {
5555
contractAddr := evmAddrs[i]
@@ -63,9 +63,13 @@ func GetQueryBalanceCommand() *cobra.Command {
6363
}
6464

6565
if fetchErc20ModuleAndVfbc && restApiEndpoint != "" {
66-
erc20TokenPairs, err := fetchErc20ModuleTokenPairsFromRest(restApiEndpoint)
66+
erc20TokenPairs, statusCode, err := fetchErc20ModuleTokenPairsFromRest(restApiEndpoint)
6767
if err != nil {
68-
utils.PrintlnStdErr("ERR:", err)
68+
if statusCode == 501 {
69+
utils.PrintlnStdErr("WARN: `x/erc20` module is not available on the chain")
70+
} else {
71+
utils.PrintlnStdErr("ERR:", err)
72+
}
6973
} else {
7074
for _, erc20TokenPair := range erc20TokenPairs {
7175
if !erc20TokenPair.Enabled {
@@ -87,9 +91,13 @@ func GetQueryBalanceCommand() *cobra.Command {
8791
}
8892
}
8993

90-
vfcbPairs, err := fetchVirtualFrontierBankContractPairsFromRest(restApiEndpoint)
94+
vfcbPairs, statusCode, err := fetchVirtualFrontierBankContractPairsFromRest(restApiEndpoint)
9195
if err != nil {
92-
utils.PrintlnStdErr("ERR:", err)
96+
if statusCode == 501 {
97+
utils.PrintlnStdErr("WARN: virtual frontier contract feature is not available on the chain")
98+
} else {
99+
utils.PrintlnStdErr("ERR:", err)
100+
}
93101
} else {
94102
for _, vfbcPair := range vfcbPairs {
95103
if !vfbcPair.Enabled {

cmd/query/cosmos.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func mustGetRest(cmd *cobra.Command) (rest string) {
2929

3030
rest = strings.TrimSuffix(rest, "/")
3131

32-
fmt.Println("Connecting to", rest, fmt.Sprintf("(from %s)", inputSource))
32+
utils.PrintlnStdErr("INF: Connecting to Cosmos Rest-API", rest, fmt.Sprintf("(from %s)", inputSource))
3333

3434
// pre-flight check to ensure the connection is working
3535
_, err := http.Get(rest)
@@ -42,16 +42,19 @@ func mustGetRest(cmd *cobra.Command) (rest string) {
4242
return
4343
}
4444

45-
func fetchErc20ModuleTokenPairsFromRest(rest string) (erc20ModuleTokenPairs []Erc20ModuleTokenPair, err error) {
45+
func fetchErc20ModuleTokenPairsFromRest(rest string) (erc20ModuleTokenPairs []Erc20ModuleTokenPair, statusCode int, err error) {
4646
var resp *http.Response
4747
resp, err = http.Get(rest + "/evmos/erc20/v1/token_pairs")
4848
if err != nil {
4949
err = errors.Wrap(err, "failed to fetch ERC-20 module token pairs")
5050
return
5151
}
5252

53+
statusCode = resp.StatusCode
54+
5355
if resp.StatusCode != http.StatusOK {
54-
return nil, fmt.Errorf("failed to fetch ERC-20 module token pairs! Status code: %d", resp.StatusCode)
56+
err = fmt.Errorf("failed to fetch ERC-20 module token pairs! Status code: %d", resp.StatusCode)
57+
return
5558
}
5659

5760
type responseStruct struct {
@@ -64,13 +67,15 @@ func fetchErc20ModuleTokenPairsFromRest(rest string) (erc20ModuleTokenPairs []Er
6467

6568
bz, err := io.ReadAll(resp.Body)
6669
if err != nil {
67-
return nil, errors.Wrap(err, "failed to read response body of ERC-20 module token pairs")
70+
err = errors.Wrap(err, "failed to read response body of ERC-20 module token pairs")
71+
return
6872
}
6973

7074
var response responseStruct
7175
err = json.Unmarshal(bz, &response)
7276
if err != nil {
73-
return nil, errors.Wrap(err, "failed to unmarshal response body of ERC-20 module token pairs")
77+
err = errors.Wrap(err, "failed to unmarshal response body of ERC-20 module token pairs")
78+
return
7479
}
7580

7681
erc20ModuleTokenPairs = response.TokenPairs
@@ -83,16 +88,19 @@ type Erc20ModuleTokenPair struct {
8388
Enabled bool `json:"enabled"`
8489
}
8590

86-
func fetchVirtualFrontierBankContractPairsFromRest(rest string) (vfbcPairs []VfbcTokenPair, err error) {
91+
func fetchVirtualFrontierBankContractPairsFromRest(rest string) (vfbcPairs []VfbcTokenPair, statusCode int, err error) {
8792
var resp *http.Response
8893
resp, err = http.Get(rest + "/ethermint/evm/v1/virtual_frontier_bank_contracts")
8994
if err != nil {
9095
err = errors.Wrap(err, "failed to fetch VFBC pairs")
9196
return
9297
}
9398

99+
statusCode = resp.StatusCode
100+
94101
if resp.StatusCode != http.StatusOK {
95-
return nil, fmt.Errorf("failed to fetch VFBC pairs! Status code: %d", resp.StatusCode)
102+
err = fmt.Errorf("failed to fetch VFBC pairs! Status code: %d", resp.StatusCode)
103+
return
96104
}
97105

98106
type responseStruct struct {
@@ -105,13 +113,15 @@ func fetchVirtualFrontierBankContractPairsFromRest(rest string) (vfbcPairs []Vfb
105113

106114
bz, err := io.ReadAll(resp.Body)
107115
if err != nil {
108-
return nil, errors.Wrap(err, "failed to read response body of VFBC pairs")
116+
err = errors.Wrap(err, "failed to read response body of VFBC pairs")
117+
return
109118
}
110119

111120
var response responseStruct
112121
err = json.Unmarshal(bz, &response)
113122
if err != nil {
114-
return nil, errors.Wrap(err, "failed to unmarshal response body of VFBC pairs")
123+
err = errors.Wrap(err, "failed to unmarshal response body of VFBC pairs")
124+
return
115125
}
116126

117127
vfbcPairs = response.Pairs

cmd/query/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func mustGetEthClient(cmd *cobra.Command, fallbackDeprecatedFlagHost bool) (ethC
114114
inputSource = "default"
115115
}
116116

117-
fmt.Println("Connecting to", rpc, fmt.Sprintf("(from %s)", inputSource))
117+
utils.PrintlnStdErr("INF: Connecting to EVM Json-RPC", rpc, fmt.Sprintf("(from %s)", inputSource))
118118

119119
ethClient8545, err = ethclient.Dial(rpc)
120120
utils.ExitOnErr(err, "failed to connect to EVM Json-RPC")

constants/varcons.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package constants
44

55
//goland:noinspection GoSnakeCaseUsage
66
var (
7-
VERSION = "2.1.1"
7+
VERSION = "2.1.2"
88
)

0 commit comments

Comments
 (0)