Skip to content

Commit 5b1b179

Browse files
authored
Refactor build address cmd (#2101)
1 parent c5cec22 commit 5b1b179

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

scripts/contrib/local/02-contracts.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ RESP=$(wasmd tx wasm instantiate2 "$CODE_ID" "$INIT" $(echo -n "testing" | xxd -
4343
sleep 6
4444
wasmd q tx $(echo "$RESP"| jq -r '.txhash') -o json | jq
4545

46-
47-
predictedAddress=$(wasmd q wasm build-address "$CODE_HASH" $(wasmd keys show validator -a --keyring-backend=test) $(echo -n "testing" | xxd -ps) "$INIT" | awk '{print $2}')
46+
predictedAddress=$(wasmd q wasm build-address "$CODE_HASH" $(wasmd keys show validator -a --keyring-backend=test) $(echo -n "testing" | xxd -ps) "$INIT")
4847
wasmd q wasm contract "$predictedAddress" -o json | jq
4948

5049
echo "### Query all"

x/wasm/client/cli/query.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/cosmos/cosmos-sdk/client/flags"
1919
sdk "github.com/cosmos/cosmos-sdk/types"
2020

21+
"github.com/CosmWasm/wasmd/x/wasm/keeper"
2122
"github.com/CosmWasm/wasmd/x/wasm/types"
2223
)
2324

@@ -77,19 +78,12 @@ func GetCmdBuildAddress() *cobra.Command {
7778
Aliases: []string{"address"},
7879
Args: cobra.RangeArgs(3, 4),
7980
RunE: func(cmd *cobra.Command, args []string) error {
80-
clientCtx, err := client.GetClientQueryContext(cmd)
81-
if err != nil {
82-
return err
83-
}
84-
8581
var initArgs []byte
8682
if len(args) == 4 {
8783
initArgs = types.RawContractMessage(args[3])
8884
}
8985

90-
queryClient := types.NewQueryClient(clientCtx)
91-
res, err := queryClient.BuildAddress(
92-
context.Background(),
86+
res, err := keeper.BuildAddressPredictable(
9387
&types.QueryBuildAddressRequest{
9488
CodeHash: args[0],
9589
CreatorAddress: args[1],
@@ -100,7 +94,8 @@ func GetCmdBuildAddress() *cobra.Command {
10094
if err != nil {
10195
return err
10296
}
103-
return clientCtx.PrintProto(res)
97+
fmt.Println(res.Address)
98+
return nil
10499
},
105100
SilenceUsage: true,
106101
}

x/wasm/keeper/querier.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ func (q GrpcQuerier) WasmLimitsConfig(c context.Context, req *types.QueryWasmLim
452452
}
453453

454454
func (q GrpcQuerier) BuildAddress(c context.Context, req *types.QueryBuildAddressRequest) (*types.QueryBuildAddressResponse, error) {
455+
ctx := sdk.UnwrapSDKContext(c)
456+
defer ctx.GasMeter().ConsumeGas(DefaultGasCostBuildAddress, "build address")
457+
return BuildAddressPredictable(req)
458+
}
459+
460+
func BuildAddressPredictable(req *types.QueryBuildAddressRequest) (*types.QueryBuildAddressResponse, error) {
455461
if req == nil {
456462
return nil, status.Error(codes.InvalidArgument, "empty request")
457463
}
@@ -471,9 +477,6 @@ func (q GrpcQuerier) BuildAddress(c context.Context, req *types.QueryBuildAddres
471477
return nil, status.Error(codes.InvalidArgument, "empty salt")
472478
}
473479

474-
ctx := sdk.UnwrapSDKContext(c)
475-
defer ctx.GasMeter().ConsumeGas(DefaultGasCostBuildAddress, "build address")
476-
477480
if req.InitArgs == nil {
478481
return &types.QueryBuildAddressResponse{
479482
Address: BuildContractAddressPredictable(codeHash, creator, salt, []byte{}).String(),

0 commit comments

Comments
 (0)