Skip to content

Commit 24d9eaf

Browse files
authored
Merge pull request #314 from CosmWasm/proto_account_strings_306
Replace sdk.AccAddress with bech32 string
2 parents 06cd063 + 0589dfa commit 24d9eaf

Some content is hidden

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

46 files changed

+1160
-1112
lines changed

contrib/local/02-contracts.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RESP=$(wasmd tx wasm store "$DIR/../../x/wasm/internal/keeper/testdata/hackatom.
1111
CODE_ID=$(echo "$RESP" | jq -r '.logs[0].events[0].attributes[-1].value')
1212
echo "* Code id: $CODE_ID"
1313
echo "* Download code"
14-
TMPDIR=$(mktemp -t wasmdXXXX)
14+
TMPDIR=$(mktemp -t wasmdXXXXXX)
1515
wasmd q wasm code "$CODE_ID" "$TMPDIR"
1616
rm -f "$TMPDIR"
1717
echo "-----------------------"

contrib/local/03-grpc-queries.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
set -o errexit -o nounset -o pipefail
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
5+
6+
echo "-----------------------"
7+
COSMOS_SDK_DIR=${COSMOS_SDK_DIR:-$(go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk)}
8+
9+
echo "### List all codes"
10+
grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/internal/types/query.proto \
11+
localhost:9090 wasmd.x.wasmd.v1beta1.Query/Codes | jq
12+
13+
echo "### List contract by code"
14+
RESP=$(grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/internal/types/query.proto \
15+
-d '{"codeId":2}' localhost:9090 wasmd.x.wasmd.v1beta1.Query/ContractsByCode )
16+
echo $RESP | jq
17+
18+
echo "### Show history for contract"
19+
CONTRACT=$(echo $RESP | jq -r ".contractInfos[-1].address")
20+
grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/internal/types/query.proto \
21+
-d "{\"address\": \"$CONTRACT\"}" localhost:9090 wasmd.x.wasmd.v1beta1.Query/ContractHistory | jq
22+
23+
echo "### Show contract state"
24+
CONTRACT=$(echo $RESP | jq -r ".contractInfos[-1].address")
25+
grpcurl -plaintext -import-path $COSMOS_SDK_DIR/third_party/proto -import-path $COSMOS_SDK_DIR/proto -import-path . -proto ./x/wasm/internal/types/query.proto \
26+
-d "{\"address\": \"$CONTRACT\"}" localhost:9090 wasmd.x.wasmd.v1beta1.Query/AllContractState | jq
27+
28+
echo "Empty state due to 'burner' contract cleanup"

doc/proto.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Contract struct encompasses ContractAddress, ContractInfo, and ContractState
9595

9696
| Field | Type | Label | Description |
9797
| ----- | ---- | ----- | ----------- |
98-
| contract_address | [bytes](#bytes) | | |
98+
| contract_address | [string](#string) | | |
9999
| contract_info | [ContractInfo](#wasmd.x.wasmd.v1beta1.ContractInfo) | | |
100100
| contract_state | [Model](#wasmd.x.wasmd.v1beta1.Model) | repeated | |
101101

@@ -162,8 +162,8 @@ MsgClearAdmin removes any admin stored for a smart contract
162162

163163
| Field | Type | Label | Description |
164164
| ----- | ---- | ----- | ----------- |
165-
| sender | [bytes](#bytes) | | Sender is the that actor that signed the messages |
166-
| contract | [bytes](#bytes) | | Contract is the address of the smart contract |
165+
| sender | [string](#string) | | Sender is the that actor that signed the messages |
166+
| contract | [string](#string) | | Contract is the address of the smart contract |
167167

168168

169169

@@ -178,8 +178,8 @@ MsgExecuteContract submits the given message data to a smart contract
178178

179179
| Field | Type | Label | Description |
180180
| ----- | ---- | ----- | ----------- |
181-
| sender | [bytes](#bytes) | | Sender is the that actor that signed the messages |
182-
| contract | [bytes](#bytes) | | Contract is the address of the smart contract |
181+
| sender | [string](#string) | | Sender is the that actor that signed the messages |
182+
| contract | [string](#string) | | Contract is the address of the smart contract |
183183
| msg | [bytes](#bytes) | | Msg json encoded message to be passed to the contract |
184184
| sent_funds | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | SentFunds coins that are transferred to the contract on execution |
185185

@@ -196,8 +196,8 @@ MsgInstantiateContract create a new smart contract instance for the given code i
196196

197197
| Field | Type | Label | Description |
198198
| ----- | ---- | ----- | ----------- |
199-
| sender | [bytes](#bytes) | | Sender is the that actor that signed the messages |
200-
| admin | [bytes](#bytes) | | Admin is an optional address that can execute migrations |
199+
| sender | [string](#string) | | Sender is the that actor that signed the messages |
200+
| admin | [string](#string) | | Admin is an optional address that can execute migrations |
201201
| code_id | [uint64](#uint64) | | CodeID is the reference to the stored WASM code |
202202
| label | [string](#string) | | Label is optional metadata to be stored with a contract instance. |
203203
| init_msg | [bytes](#bytes) | | InitMsg json encoded message to be passed to the contract on instantiation |
@@ -216,8 +216,8 @@ MsgMigrateContract runs a code upgrade/ downgrade for a smart contract
216216

217217
| Field | Type | Label | Description |
218218
| ----- | ---- | ----- | ----------- |
219-
| sender | [bytes](#bytes) | | Sender is the that actor that signed the messages |
220-
| contract | [bytes](#bytes) | | Contract is the address of the smart contract |
219+
| sender | [string](#string) | | Sender is the that actor that signed the messages |
220+
| contract | [string](#string) | | Contract is the address of the smart contract |
221221
| code_id | [uint64](#uint64) | | CodeID references the new WASM code |
222222
| migrate_msg | [bytes](#bytes) | | MigrateMsg json encoded message to be passed to the contract on migration |
223223

@@ -229,12 +229,12 @@ MsgMigrateContract runs a code upgrade/ downgrade for a smart contract
229229
<a name="wasmd.x.wasmd.v1beta1.MsgStoreCode"></a>
230230

231231
### MsgStoreCode
232-
MsgStoreCode submit WASM code to the system
232+
MsgStoreCode submit Wasm code to the system
233233

234234

235235
| Field | Type | Label | Description |
236236
| ----- | ---- | ----- | ----------- |
237-
| sender | [bytes](#bytes) | | Sender is the that actor that signed the messages |
237+
| sender | [string](#string) | | Sender is the that actor that signed the messages |
238238
| wasm_byte_code | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed |
239239
| source | [string](#string) | | Source is a valid absolute HTTPS URI to the contract&#39;s source code, optional |
240240
| builder | [string](#string) | | Builder is a valid docker image name with tag, optional |
@@ -253,9 +253,9 @@ MsgUpdateAdmin sets a new admin for a smart contract
253253

254254
| Field | Type | Label | Description |
255255
| ----- | ---- | ----- | ----------- |
256-
| sender | [bytes](#bytes) | | Sender is the that actor that signed the messages |
257-
| new_admin | [bytes](#bytes) | | NewAdmin address to be set |
258-
| contract | [bytes](#bytes) | | Contract is the address of the smart contract |
256+
| sender | [string](#string) | | Sender is the that actor that signed the messages |
257+
| new_admin | [string](#string) | | NewAdmin address to be set |
258+
| contract | [string](#string) | | Contract is the address of the smart contract |
259259

260260

261261

@@ -288,7 +288,7 @@ ClearAdminProposal gov proposal content type to clear the admin of a contract.
288288
| ----- | ---- | ----- | ----------- |
289289
| title | [string](#string) | | Title is a short summary |
290290
| description | [string](#string) | | Description is a human readable text |
291-
| contract | [bytes](#bytes) | | Contract is the address of the smart contract |
291+
| contract | [string](#string) | | Contract is the address of the smart contract |
292292

293293

294294

@@ -305,8 +305,8 @@ InstantiateContractProposal gov proposal content type to instantiate a contract.
305305
| ----- | ---- | ----- | ----------- |
306306
| title | [string](#string) | | Title is a short summary |
307307
| description | [string](#string) | | Description is a human readable text |
308-
| run_as | [bytes](#bytes) | | RunAs is the address that is passed to the contract&#39;s environment as sender |
309-
| admin | [bytes](#bytes) | | Admin is an optional address that can execute migrations |
308+
| run_as | [string](#string) | | RunAs is the address that is passed to the contract&#39;s environment as sender |
309+
| admin | [string](#string) | | Admin is an optional address that can execute migrations |
310310
| code_id | [uint64](#uint64) | | CodeID is the reference to the stored WASM code |
311311
| label | [string](#string) | | Label is optional metadata to be stored with a constract instance. |
312312
| init_msg | [bytes](#bytes) | | InitMsg json encoded message to be passed to the contract on instantiation |
@@ -327,8 +327,8 @@ MigrateContractProposal gov proposal content type to migrate a contract.
327327
| ----- | ---- | ----- | ----------- |
328328
| title | [string](#string) | | Title is a short summary |
329329
| description | [string](#string) | | Description is a human readable text |
330-
| run_as | [bytes](#bytes) | | RunAs is the address that is passed to the contract&#39;s environment as sender |
331-
| contract | [bytes](#bytes) | | Contract is the address of the smart contract |
330+
| run_as | [string](#string) | | RunAs is the address that is passed to the contract&#39;s environment as sender |
331+
| contract | [string](#string) | | Contract is the address of the smart contract |
332332
| code_id | [uint64](#uint64) | | CodeID references the new WASM code |
333333
| migrate_msg | [bytes](#bytes) | | MigrateMsg json encoded message to be passed to the contract on migration |
334334

@@ -347,7 +347,7 @@ StoreCodeProposal gov proposal content type to submit WASM code to the system
347347
| ----- | ---- | ----- | ----------- |
348348
| title | [string](#string) | | Title is a short summary |
349349
| description | [string](#string) | | Description is a human readable text |
350-
| run_as | [bytes](#bytes) | | RunAs is the address that is passed to the contract&#39;s environment as sender |
350+
| run_as | [string](#string) | | RunAs is the address that is passed to the contract&#39;s environment as sender |
351351
| wasm_byte_code | [bytes](#bytes) | | WASMByteCode can be raw or gzip compressed |
352352
| source | [string](#string) | | Source is a valid absolute HTTPS URI to the contract&#39;s source code, optional |
353353
| builder | [string](#string) | | Builder is a valid docker image name with tag, optional |
@@ -368,8 +368,8 @@ UpdateAdminProposal gov proposal content type to set an admin for a contract.
368368
| ----- | ---- | ----- | ----------- |
369369
| title | [string](#string) | | Title is a short summary |
370370
| description | [string](#string) | | Description is a human readable text |
371-
| new_admin | [bytes](#bytes) | | NewAdmin address to be set |
372-
| contract | [bytes](#bytes) | | Contract is the address of the smart contract |
371+
| new_admin | [string](#string) | | NewAdmin address to be set |
372+
| contract | [string](#string) | | Contract is the address of the smart contract |
373373

374374

375375

@@ -401,7 +401,7 @@ CodeInfoResponse contains code meta data from CodeInfo
401401
| Field | Type | Label | Description |
402402
| ----- | ---- | ----- | ----------- |
403403
| code_id | [uint64](#uint64) | | id for legacy support |
404-
| creator | [bytes](#bytes) | | |
404+
| creator | [string](#string) | | |
405405
| data_hash | [bytes](#bytes) | | |
406406
| source | [string](#string) | | |
407407
| builder | [string](#string) | | |
@@ -419,7 +419,7 @@ ContractInfoWithAddress adds the address (key) to the ContractInfo representatio
419419

420420
| Field | Type | Label | Description |
421421
| ----- | ---- | ----- | ----------- |
422-
| address | [bytes](#bytes) | | |
422+
| address | [string](#string) | | |
423423
| contract_info | [ContractInfo](#wasmd.x.wasmd.v1beta1.ContractInfo) | | |
424424

425425

@@ -435,7 +435,7 @@ QueryAllContractStateRequest is the request type for the Query/AllContractState
435435

436436
| Field | Type | Label | Description |
437437
| ----- | ---- | ----- | ----------- |
438-
| address | [bytes](#bytes) | | address is the address of the contract |
438+
| address | [string](#string) | | address is the address of the contract |
439439

440440

441441

@@ -511,7 +511,7 @@ QueryContractHistoryRequest is the request type for the Query/ContractHistory RP
511511

512512
| Field | Type | Label | Description |
513513
| ----- | ---- | ----- | ----------- |
514-
| address | [bytes](#bytes) | | address is the address of the contract to query |
514+
| address | [string](#string) | | address is the address of the contract to query |
515515

516516

517517

@@ -541,7 +541,7 @@ QueryContractInfoRequest is the request type for the Query/ContractInfo RPC meth
541541

542542
| Field | Type | Label | Description |
543543
| ----- | ---- | ----- | ----------- |
544-
| address | [bytes](#bytes) | | address is the address of the contract to query |
544+
| address | [string](#string) | | address is the address of the contract to query |
545545

546546

547547

@@ -556,7 +556,7 @@ QueryContractInfoResponse is the response type for the Query/ContractInfo RPC me
556556

557557
| Field | Type | Label | Description |
558558
| ----- | ---- | ----- | ----------- |
559-
| address | [bytes](#bytes) | | address is the address of the contract |
559+
| address | [string](#string) | | address is the address of the contract |
560560
| contract_info | [ContractInfo](#wasmd.x.wasmd.v1beta1.ContractInfo) | | |
561561

562562

@@ -602,7 +602,7 @@ QueryRawContractStateRequest is the request type for the Query/RawContractState
602602

603603
| Field | Type | Label | Description |
604604
| ----- | ---- | ----- | ----------- |
605-
| address | [bytes](#bytes) | | address is the address of the contract |
605+
| address | [string](#string) | | address is the address of the contract |
606606
| query_data | [bytes](#bytes) | | |
607607

608608

@@ -633,7 +633,7 @@ QuerySmartContractStateRequest is the request type for the Query/SmartContractSt
633633

634634
| Field | Type | Label | Description |
635635
| ----- | ---- | ----- | ----------- |
636-
| address | [bytes](#bytes) | | address is the address of the contract |
636+
| address | [string](#string) | | address is the address of the contract |
637637
| query_data | [bytes](#bytes) | | QueryData contains the query data passed to the contract |
638638

639639

@@ -714,7 +714,7 @@ AccessConfig access control type.
714714
| Field | Type | Label | Description |
715715
| ----- | ---- | ----- | ----------- |
716716
| permission | [AccessType](#wasmd.x.wasmd.v1beta1.AccessType) | | |
717-
| address | [bytes](#bytes) | | |
717+
| address | [string](#string) | | |
718718

719719

720720

@@ -745,7 +745,7 @@ CodeInfo is data for the uploaded contract WASM code
745745
| Field | Type | Label | Description |
746746
| ----- | ---- | ----- | ----------- |
747747
| code_hash | [bytes](#bytes) | | CodeHash is the unique CodeID |
748-
| creator | [bytes](#bytes) | | Creator address who initially stored the code |
748+
| creator | [string](#string) | | Creator address who initially stored the code |
749749
| source | [string](#string) | | Source is a valid absolute HTTPS URI to the contract&#39;s source code, optional |
750750
| builder | [string](#string) | | Builder is a valid docker image name with tag, optional |
751751
| instantiate_config | [AccessConfig](#wasmd.x.wasmd.v1beta1.AccessConfig) | | InstantiateConfig access control to apply on contract creation, optional |
@@ -796,9 +796,9 @@ ContractInfo stores a WASM contract instance
796796

797797
| Field | Type | Label | Description |
798798
| ----- | ---- | ----- | ----------- |
799-
| code_id | [uint64](#uint64) | | CodeID is the reference to the stored WASM code |
800-
| creator | [bytes](#bytes) | | Creator address who initially instantiated the contract |
801-
| admin | [bytes](#bytes) | | Admin is an optional address that can execute migrations |
799+
| code_id | [uint64](#uint64) | | CodeID is the reference to the stored Wasm code |
800+
| creator | [string](#string) | | Creator address who initially instantiated the contract |
801+
| admin | [string](#string) | | Admin is an optional address that can execute migrations |
802802
| label | [string](#string) | | Label is optional metadata to be stored with a contract instance. |
803803
| created | [AbsoluteTxPosition](#wasmd.x.wasmd.v1beta1.AbsoluteTxPosition) | | Created Tx position when the contract was instantiated. This data should kept internal and not be exposed via query results. Just use for sorting |
804804

x/wasm/client/cli/gov_tx.go

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/cosmos/cosmos-sdk/client"
66
"github.com/cosmos/cosmos-sdk/client/tx"
77
sdk "github.com/cosmos/cosmos-sdk/types"
8-
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
98
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
109
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
1110
"github.com/pkg/errors"
@@ -32,14 +31,10 @@ func ProposalStoreCodeCmd() *cobra.Command {
3231
if len(viper.GetString(flagRunAs)) == 0 {
3332
return errors.New("run-as address is required")
3433
}
35-
runAsAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagRunAs))
36-
if err != nil {
37-
return errors.Wrap(err, "run-as")
38-
}
3934
content := types.StoreCodeProposal{
4035
Title: viper.GetString(cli.FlagTitle),
4136
Description: viper.GetString(cli.FlagDescription),
42-
RunAs: runAsAddr,
37+
RunAs: viper.GetString(flagRunAs),
4338
WASMByteCode: src.WASMByteCode,
4439
Source: src.Source,
4540
Builder: src.Builder,
@@ -97,14 +92,10 @@ func ProposalInstantiateContractCmd() *cobra.Command {
9792
if len(viper.GetString(flagRunAs)) == 0 {
9893
return errors.New("creator address is required")
9994
}
100-
creator, err := sdk.AccAddressFromBech32(viper.GetString(flagRunAs))
101-
if err != nil {
102-
return errors.Wrap(err, "creator")
103-
}
10495
content := types.InstantiateContractProposal{
10596
Title: viper.GetString(cli.FlagTitle),
10697
Description: viper.GetString(cli.FlagDescription),
107-
RunAs: creator,
98+
RunAs: viper.GetString(flagRunAs),
10899
Admin: src.Admin,
109100
CodeID: src.CodeID,
110101
Label: src.Label,
@@ -163,18 +154,14 @@ func ProposalMigrateContractCmd() *cobra.Command {
163154
if len(viper.GetString(flagRunAs)) == 0 {
164155
return errors.New("run-as address is required")
165156
}
166-
runAs, err := sdk.AccAddressFromBech32(viper.GetString(flagRunAs))
167-
if err != nil {
168-
return errors.Wrap(err, "run-as")
169-
}
170157

171158
content := types.MigrateContractProposal{
172159
Title: viper.GetString(cli.FlagTitle),
173160
Description: viper.GetString(cli.FlagDescription),
174161
Contract: src.Contract,
175162
CodeID: src.CodeID,
176163
MigrateMsg: src.MigrateMsg,
177-
RunAs: runAs,
164+
RunAs: viper.GetString(flagRunAs),
178165
}
179166

180167
deposit, err := sdk.ParseCoins(viper.GetString(cli.FlagDeposit))
@@ -267,15 +254,10 @@ func ProposalClearContractAdminCmd() *cobra.Command {
267254
return err
268255
}
269256

270-
contractAddr, err := sdk.AccAddressFromBech32(args[0])
271-
if err != nil {
272-
return sdkerrors.Wrap(err, "contract")
273-
}
274-
275257
content := types.ClearAdminProposal{
276258
Title: viper.GetString(cli.FlagTitle),
277259
Description: viper.GetString(cli.FlagDescription),
278-
Contract: contractAddr,
260+
Contract: args[0],
279261
}
280262

281263
deposit, err := sdk.ParseCoins(viper.GetString(cli.FlagDeposit))

0 commit comments

Comments
 (0)