Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace sdk.AccAddress with bech32 string #314

Merged
merged 2 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contrib/local/02-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RESP=$(wasmd tx wasm store "$DIR/../../x/wasm/internal/keeper/testdata/hackatom.
CODE_ID=$(echo "$RESP" | jq -r '.logs[0].events[0].attributes[-1].value')
echo "* Code id: $CODE_ID"
echo "* Download code"
TMPDIR=$(mktemp -t wasmdXXXX)
TMPDIR=$(mktemp -t wasmdXXXXXX)
wasmd q wasm code "$CODE_ID" "$TMPDIR"
rm -f "$TMPDIR"
echo "-----------------------"
Expand Down
28 changes: 28 additions & 0 deletions contrib/local/03-grpc-queries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

echo "-----------------------"
COSMOS_SDK_DIR=${COSMOS_SDK_DIR:-$(go list -f "{{ .Dir }}" -m github.com/cosmos/cosmos-sdk)}

echo "### List all codes"
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 \
localhost:9090 wasmd.x.wasmd.v1beta1.Query/Codes | jq

echo "### List contract by code"
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 \
-d '{"codeId":2}' localhost:9090 wasmd.x.wasmd.v1beta1.Query/ContractsByCode )
echo $RESP | jq

echo "### Show history for contract"
CONTRACT=$(echo $RESP | jq -r ".contractInfos[-1].address")
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 \
-d "{\"address\": \"$CONTRACT\"}" localhost:9090 wasmd.x.wasmd.v1beta1.Query/ContractHistory | jq

echo "### Show contract state"
CONTRACT=$(echo $RESP | jq -r ".contractInfos[-1].address")
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 \
-d "{\"address\": \"$CONTRACT\"}" localhost:9090 wasmd.x.wasmd.v1beta1.Query/AllContractState | jq

echo "Empty state due to 'burner' contract cleanup"
70 changes: 35 additions & 35 deletions doc/proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Contract struct encompasses ContractAddress, ContractInfo, and ContractState

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| contract_address | [bytes](#bytes) | | |
| contract_address | [string](#string) | | |
| contract_info | [ContractInfo](#wasmd.x.wasmd.v1beta1.ContractInfo) | | |
| contract_state | [Model](#wasmd.x.wasmd.v1beta1.Model) | repeated | |

Expand Down Expand Up @@ -162,8 +162,8 @@ MsgClearAdmin removes any admin stored for a smart contract

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



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

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

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

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

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

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

### MsgStoreCode
MsgStoreCode submit WASM code to the system
MsgStoreCode submit Wasm code to the system


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

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



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



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

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



Expand Down Expand Up @@ -401,7 +401,7 @@ CodeInfoResponse contains code meta data from CodeInfo
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| code_id | [uint64](#uint64) | | id for legacy support |
| creator | [bytes](#bytes) | | |
| creator | [string](#string) | | |
| data_hash | [bytes](#bytes) | | |
| source | [string](#string) | | |
| builder | [string](#string) | | |
Expand All @@ -419,7 +419,7 @@ ContractInfoWithAddress adds the address (key) to the ContractInfo representatio

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| address | [bytes](#bytes) | | |
| address | [string](#string) | | |
| contract_info | [ContractInfo](#wasmd.x.wasmd.v1beta1.ContractInfo) | | |


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

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| address | [bytes](#bytes) | | address is the address of the contract |
| address | [string](#string) | | address is the address of the contract |



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

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



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

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



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

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


Expand Down Expand Up @@ -602,7 +602,7 @@ QueryRawContractStateRequest is the request type for the Query/RawContractState

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| address | [bytes](#bytes) | | address is the address of the contract |
| address | [string](#string) | | address is the address of the contract |
| query_data | [bytes](#bytes) | | |


Expand Down Expand Up @@ -633,7 +633,7 @@ QuerySmartContractStateRequest is the request type for the Query/SmartContractSt

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


Expand Down Expand Up @@ -714,7 +714,7 @@ AccessConfig access control type.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| permission | [AccessType](#wasmd.x.wasmd.v1beta1.AccessType) | | |
| address | [bytes](#bytes) | | |
| address | [string](#string) | | |



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

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| code_id | [uint64](#uint64) | | CodeID is the reference to the stored WASM code |
| creator | [bytes](#bytes) | | Creator address who initially instantiated the contract |
| admin | [bytes](#bytes) | | Admin is an optional address that can execute migrations |
| code_id | [uint64](#uint64) | | CodeID is the reference to the stored Wasm code |
| creator | [string](#string) | | Creator address who initially instantiated the contract |
| admin | [string](#string) | | Admin is an optional address that can execute migrations |
| label | [string](#string) | | Label is optional metadata to be stored with a contract instance. |
| 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 |

Expand Down
26 changes: 4 additions & 22 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/gov/client/cli"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/pkg/errors"
Expand All @@ -32,14 +31,10 @@ func ProposalStoreCodeCmd() *cobra.Command {
if len(viper.GetString(flagRunAs)) == 0 {
return errors.New("run-as address is required")
}
runAsAddr, err := sdk.AccAddressFromBech32(viper.GetString(flagRunAs))
if err != nil {
return errors.Wrap(err, "run-as")
}
content := types.StoreCodeProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
RunAs: runAsAddr,
RunAs: viper.GetString(flagRunAs),
WASMByteCode: src.WASMByteCode,
Source: src.Source,
Builder: src.Builder,
Expand Down Expand Up @@ -97,14 +92,10 @@ func ProposalInstantiateContractCmd() *cobra.Command {
if len(viper.GetString(flagRunAs)) == 0 {
return errors.New("creator address is required")
}
creator, err := sdk.AccAddressFromBech32(viper.GetString(flagRunAs))
if err != nil {
return errors.Wrap(err, "creator")
}
content := types.InstantiateContractProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
RunAs: creator,
RunAs: viper.GetString(flagRunAs),
Admin: src.Admin,
CodeID: src.CodeID,
Label: src.Label,
Expand Down Expand Up @@ -163,18 +154,14 @@ func ProposalMigrateContractCmd() *cobra.Command {
if len(viper.GetString(flagRunAs)) == 0 {
return errors.New("run-as address is required")
}
runAs, err := sdk.AccAddressFromBech32(viper.GetString(flagRunAs))
if err != nil {
return errors.Wrap(err, "run-as")
}

content := types.MigrateContractProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
Contract: src.Contract,
CodeID: src.CodeID,
MigrateMsg: src.MigrateMsg,
RunAs: runAs,
RunAs: viper.GetString(flagRunAs),
}

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

contractAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return sdkerrors.Wrap(err, "contract")
}

content := types.ClearAdminProposal{
Title: viper.GetString(cli.FlagTitle),
Description: viper.GetString(cli.FlagDescription),
Contract: contractAddr,
Contract: args[0],
}

deposit, err := sdk.ParseCoins(viper.GetString(cli.FlagDeposit))
Expand Down
Loading