From 5fc67d62d08bb88a3570bf8e6101b25ac047254f Mon Sep 17 00:00:00 2001 From: Lior Bondarevski Date: Sun, 21 Aug 2022 17:41:35 +0300 Subject: [PATCH] Fix contract-hash command in cli --- x/compute/client/cli/query.go | 8 ++++++-- x/compute/client/cli/tx.go | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/x/compute/client/cli/query.go b/x/compute/client/cli/query.go index bc26f67ad..21674aa15 100644 --- a/x/compute/client/cli/query.go +++ b/x/compute/client/cli/query.go @@ -139,8 +139,12 @@ func GetCmdCodeHashByContract() *cobra.Command { return fmt.Errorf("error querying contract hash: %s", err) } - addr := hex.EncodeToString(res) - fmt.Printf("0x%s", addr) + if len(res) == 0 { + return fmt.Errorf("contract with address %s not found", args[0]) + } + + codeHash := hex.EncodeToString(res) + fmt.Printf("0x%s\n", codeHash) return nil }, } diff --git a/x/compute/client/cli/tx.go b/x/compute/client/cli/tx.go index 96238e342..0bb29a745 100644 --- a/x/compute/client/cli/tx.go +++ b/x/compute/client/cli/tx.go @@ -406,5 +406,9 @@ func GetCodeHashByContractAddr(cliCtx client.Context, contractAddr sdk.AccAddres return nil, err } + if len(res) == 0 { + return nil, fmt.Errorf("contract with address %s not found", contractAddr.String()) + } + return []byte(hex.EncodeToString(res)), nil }