Skip to content

Commit

Permalink
Merge pull request #204 from CosmWasm/code_id
Browse files Browse the repository at this point in the history
Rename ambiguous Code attribute
  • Loading branch information
alpe authored Jul 20, 2020
2 parents 81351d8 + db464d8 commit 02a54d3
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions x/wasm/client/cli/gov_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func ProposalInstantiateContractCmd(cdc *codec.Codec) *cobra.Command {
},
RunAs: creator,
Admin: src.Admin,
Code: src.Code,
CodeID: src.CodeID,
Label: src.Label,
InitMsg: src.InitMsg,
InitFunds: src.InitFunds,
Expand Down Expand Up @@ -171,7 +171,7 @@ func ProposalMigrateContractCmd(cdc *codec.Codec) *cobra.Command {
Description: viper.GetString(cli.FlagDescription),
},
Contract: src.Contract,
Code: src.Code,
CodeID: src.CodeID,
MigrateMsg: src.MigrateMsg,
RunAs: runAs,
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/client/cli/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func parseMigrateContractArgs(args []string, cliCtx context.CLIContext) (types.M
msg := types.MsgMigrateContract{
Sender: cliCtx.GetFromAddress(),
Contract: contractAddr,
Code: codeID,
CodeID: codeID,
MigrateMsg: []byte(migrateMsg),
}
return msg, nil
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func parseInstantiateArgs(args []string, cliCtx context.CLIContext) (types.MsgIn
// build and sign the transaction, then broadcast to Tendermint
msg := types.MsgInstantiateContract{
Sender: cliCtx.GetFromAddress(),
Code: codeID,
CodeID: codeID,
Label: label,
InitFunds: amount,
InitMsg: []byte(initMsg),
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/client/rest/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s InstantiateProposalJsonReq) Content() gov.Content {
WasmProposal: types.WasmProposal{Title: s.Title, Description: s.Description},
RunAs: s.RunAs,
Admin: s.Admin,
Code: s.Code,
CodeID: s.Code,
Label: s.Label,
InitMsg: s.InitMsg,
InitFunds: s.InitFunds,
Expand Down Expand Up @@ -140,7 +140,7 @@ func (s MigrateProposalJsonReq) Content() gov.Content {
return types.MigrateContractProposal{
WasmProposal: types.WasmProposal{Title: s.Title, Description: s.Description},
Contract: s.Contract,
Code: s.Code,
CodeID: s.Code,
MigrateMsg: s.MigrateMsg,
RunAs: s.RunAs,
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/client/rest/new_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func migrateContractHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
msg := types.MsgMigrateContract{
Sender: cliCtx.GetFromAddress(),
Contract: contractAddress,
Code: req.CodeID,
CodeID: req.CodeID,
MigrateMsg: req.MigrateMsg,
}
if err = msg.ValidateBasic(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func instantiateContractHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {

msg := types.MsgInstantiateContract{
Sender: cliCtx.GetFromAddress(),
Code: codeID,
CodeID: codeID,
InitFunds: req.Deposit,
InitMsg: req.InitMsg,
Admin: req.Admin,
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestInitGenesis(t *testing.T) {

initCmd := MsgInstantiateContract{
Sender: creator,
Code: 1,
CodeID: 1,
InitMsg: initMsgBz,
InitFunds: deposit,
}
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func handleStoreCode(ctx sdk.Context, k Keeper, msg *MsgStoreCode) (*sdk.Result,
}

func handleInstantiate(ctx sdk.Context, k Keeper, msg *MsgInstantiateContract) (*sdk.Result, error) {
contractAddr, err := k.Instantiate(ctx, msg.Code, msg.Sender, msg.Admin, msg.InitMsg, msg.Label, msg.InitFunds)
contractAddr, err := k.Instantiate(ctx, msg.CodeID, msg.Sender, msg.Admin, msg.InitMsg, msg.Label, msg.InitFunds)
if err != nil {
return nil, err
}
Expand All @@ -100,7 +100,7 @@ func handleInstantiate(ctx sdk.Context, k Keeper, msg *MsgInstantiateContract) (
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender.String()),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", msg.Code)),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", msg.CodeID)),
sdk.NewAttribute(types.AttributeKeyContract, contractAddr.String()),
)

Expand Down Expand Up @@ -129,7 +129,7 @@ func handleExecute(ctx sdk.Context, k Keeper, msg *MsgExecuteContract) (*sdk.Res
}

func handleMigration(ctx sdk.Context, k Keeper, msg *MsgMigrateContract) (*sdk.Result, error) {
res, err := k.Migrate(ctx, msg.Contract, msg.Sender, msg.Code, msg.MigrateMsg)
res, err := k.Migrate(ctx, msg.Contract, msg.Sender, msg.CodeID, msg.MigrateMsg)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/keeper/handler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func EncodeWasmMsg(sender sdk.AccAddress, msg *wasmTypes.WasmMsg) ([]sdk.Msg, er

sdkMsg := types.MsgInstantiateContract{
Sender: sender,
Code: msg.Instantiate.CodeID,
CodeID: msg.Instantiate.CodeID,
// TODO: add this to CosmWasm
Label: fmt.Sprintf("Auto-created by %s", sender),
InitMsg: msg.Instantiate.Msg,
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/keeper/handler_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestEncoding(t *testing.T) {
output: []sdk.Msg{
types.MsgInstantiateContract{
Sender: addr1,
Code: 7,
CodeID: 7,
// TODO: fix this
Label: fmt.Sprintf("Auto-created by %s", addr1),
InitMsg: jsonMsg,
Expand Down
6 changes: 3 additions & 3 deletions x/wasm/internal/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func handleInstantiateProposal(ctx sdk.Context, k Keeper, p types.InstantiateCon
return err
}

contractAddr, err := k.instantiate(ctx, p.Code, p.RunAs, p.Admin, p.InitMsg, p.Label, p.InitFunds, GovAuthorizationPolicy{})
contractAddr, err := k.instantiate(ctx, p.CodeID, p.RunAs, p.Admin, p.InitMsg, p.Label, p.InitFunds, GovAuthorizationPolicy{})
if err != nil {
return err
}

ourEvent := sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", p.Code)),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", p.CodeID)),
sdk.NewAttribute(types.AttributeKeyContract, contractAddr.String()),
)
ctx.EventManager().EmitEvent(ourEvent)
Expand All @@ -83,7 +83,7 @@ func handleMigrateProposal(ctx sdk.Context, k Keeper, p types.MigrateContractPro
return err
}

res, err := k.migrate(ctx, p.Contract, p.RunAs, p.Code, p.MigrateMsg, GovAuthorizationPolicy{})
res, err := k.migrate(ctx, p.Contract, p.RunAs, p.CodeID, p.MigrateMsg, GovAuthorizationPolicy{})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/internal/keeper/proposal_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestInstantiateProposal(t *testing.T) {
otherAddress sdk.AccAddress = bytes.Repeat([]byte{0x2}, sdk.AddrLen)
)
src := types.InstantiateContractProposalFixture(func(p *types.InstantiateContractProposal) {
p.Code = 1
p.CodeID = 1
p.RunAs = oneAddress
p.Admin = otherAddress
p.Label = "testing"
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestMigrateProposal(t *testing.T) {
Title: "Foo",
Description: "Bar",
},
Code: 2,
CodeID: 2,
Contract: contractAddr,
MigrateMsg: migMsgBz,
RunAs: otherAddress,
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func TestHandler(k Keeper) sdk.Handler {
}

func handleInstantiate(ctx sdk.Context, k Keeper, msg *wasmtypes.MsgInstantiateContract) (*sdk.Result, error) {
contractAddr, err := k.Instantiate(ctx, msg.Code, msg.Sender, msg.Admin, msg.InitMsg, msg.Label, msg.InitFunds)
contractAddr, err := k.Instantiate(ctx, msg.CodeID, msg.Sender, msg.Admin, msg.InitMsg, msg.Label, msg.InitFunds)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions x/wasm/internal/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type MsgInstantiateContract struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
// Admin is an optional address that can execute migrations
Admin sdk.AccAddress `json:"admin,omitempty" yaml:"admin"`
Code uint64 `json:"code_id" yaml:"code_id"`
CodeID uint64 `json:"code_id" yaml:"code_id"`
Label string `json:"label" yaml:"label"`
InitMsg json.RawMessage `json:"init_msg" yaml:"init_msg"`
InitFunds sdk.Coins `json:"init_funds" yaml:"init_funds"`
Expand All @@ -82,7 +82,7 @@ func (msg MsgInstantiateContract) ValidateBasic() error {
return err
}

if msg.Code == 0 {
if msg.CodeID == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required")
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func (msg MsgExecuteContract) GetSigners() []sdk.AccAddress {
type MsgMigrateContract struct {
Sender sdk.AccAddress `json:"sender" yaml:"sender"`
Contract sdk.AccAddress `json:"contract" yaml:"contract"`
Code uint64 `json:"code_id" yaml:"code_id"`
CodeID uint64 `json:"code_id" yaml:"code_id"`
MigrateMsg json.RawMessage `json:"msg" yaml:"msg"`
}

Expand All @@ -163,7 +163,7 @@ func (msg MsgMigrateContract) Type() string {
}

func (msg MsgMigrateContract) ValidateBasic() error {
if msg.Code == 0 {
if msg.CodeID == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required")
}
if err := sdk.VerifyAddressFormat(msg.Sender); err != nil {
Expand Down
20 changes: 10 additions & 10 deletions x/wasm/internal/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"correct minimal": {
msg: MsgInstantiateContract{
Sender: goodAddress,
Code: 1,
CodeID: 1,
Label: "foo",
InitMsg: []byte("{}"),
},
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"bad sender minimal": {
msg: MsgInstantiateContract{
Sender: badAddress,
Code: 1,
CodeID: 1,
Label: "foo",
InitMsg: []byte("{}"),
},
Expand All @@ -186,7 +186,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"correct maximal": {
msg: MsgInstantiateContract{
Sender: goodAddress,
Code: 1,
CodeID: 1,
Label: "foo",
InitMsg: []byte(`{"some": "data"}`),
InitFunds: sdk.Coins{sdk.Coin{Denom: "foobar", Amount: sdk.NewInt(200)}},
Expand All @@ -196,7 +196,7 @@ func TestInstantiateContractValidation(t *testing.T) {
"negative funds": {
msg: MsgInstantiateContract{
Sender: goodAddress,
Code: 1,
CodeID: 1,
Label: "foo",
InitMsg: []byte(`{"some": "data"}`),
// we cannot use sdk.NewCoin() constructors as they panic on creating invalid data (before we can test)
Expand Down Expand Up @@ -354,29 +354,29 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: anotherGoodAddress,
Code: 1,
CodeID: 1,
MigrateMsg: []byte{1},
},
},
"MigrateMsg optional": {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: anotherGoodAddress,
Code: 1,
CodeID: 1,
},
},
"bad sender": {
src: MsgMigrateContract{
Sender: badAddress,
Contract: anotherGoodAddress,
Code: 1,
CodeID: 1,
},
expErr: true,
},
"empty sender": {
src: MsgMigrateContract{
Contract: anotherGoodAddress,
Code: 1,
CodeID: 1,
},
expErr: true,
},
Expand All @@ -391,14 +391,14 @@ func TestMsgMigrateContract(t *testing.T) {
src: MsgMigrateContract{
Sender: goodAddress,
Contract: badAddress,
Code: 1,
CodeID: 1,
},
expErr: true,
},
"empty contract addr": {
src: MsgMigrateContract{
Sender: goodAddress,
Code: 1,
CodeID: 1,
},
expErr: true,
},
Expand Down
20 changes: 10 additions & 10 deletions x/wasm/internal/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ type InstantiateContractProposal struct {
RunAs sdk.AccAddress `json:"run_as"`
// Admin is an optional address that can execute migrations
Admin sdk.AccAddress `json:"admin,omitempty"`
Code uint64 `json:"code_id"`
CodeID uint64 `json:"code_id"`
Label string `json:"label"`
InitMsg json.RawMessage `json:"init_msg"`
InitFunds sdk.Coins `json:"init_funds"`
Expand All @@ -187,7 +187,7 @@ func (p InstantiateContractProposal) ValidateBasic() error {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "run as")
}

if p.Code == 0 {
if p.CodeID == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code id is required")
}

Expand Down Expand Up @@ -219,23 +219,23 @@ func (p InstantiateContractProposal) String() string {
Label: %s
InitMsg: %q
InitFunds: %s
`, p.Title, p.Description, p.RunAs, p.Admin, p.Code, p.Label, p.InitMsg, p.InitFunds)
`, p.Title, p.Description, p.RunAs, p.Admin, p.CodeID, p.Label, p.InitMsg, p.InitFunds)
}

func (p InstantiateContractProposal) MarshalYAML() (interface{}, error) {
return struct {
WasmProposal `yaml:",inline"`
RunAs sdk.AccAddress `yaml:"run_as"`
Admin sdk.AccAddress `yaml:"admin"`
Code uint64 `yaml:"code_id"`
CodeID uint64 `yaml:"code_id"`
Label string `yaml:"label"`
InitMsg string `yaml:"init_msg"`
InitFunds sdk.Coins `yaml:"init_funds"`
}{
WasmProposal: p.WasmProposal,
RunAs: p.RunAs,
Admin: p.Admin,
Code: p.Code,
CodeID: p.CodeID,
Label: p.Label,
InitMsg: string(p.InitMsg),
InitFunds: p.InitFunds,
Expand All @@ -246,7 +246,7 @@ func (p InstantiateContractProposal) MarshalYAML() (interface{}, error) {
type MigrateContractProposal struct {
WasmProposal `yaml:",inline"`
Contract sdk.AccAddress `json:"contract"`
Code uint64 `json:"code_id"`
CodeID uint64 `json:"code_id"`
MigrateMsg json.RawMessage `json:"msg"`
// RunAs is the address that is passed to the contract's environment as sender
RunAs sdk.AccAddress `json:"run_as"`
Expand All @@ -260,7 +260,7 @@ func (p MigrateContractProposal) ValidateBasic() error {
if err := p.WasmProposal.ValidateBasic(); err != nil {
return err
}
if p.Code == 0 {
if p.CodeID == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "code_id is required")
}
if err := sdk.VerifyAddressFormat(p.Contract); err != nil {
Expand All @@ -281,20 +281,20 @@ func (p MigrateContractProposal) String() string {
Code id: %d
Run as: %s
MigrateMsg %q
`, p.Title, p.Description, p.Contract, p.Code, p.RunAs, p.MigrateMsg)
`, p.Title, p.Description, p.Contract, p.CodeID, p.RunAs, p.MigrateMsg)
}

func (p MigrateContractProposal) MarshalYAML() (interface{}, error) {
return struct {
WasmProposal `yaml:",inline"`
Contract sdk.AccAddress `yaml:"contract"`
Code uint64 `yaml:"code_id"`
CodeID uint64 `yaml:"code_id"`
MigrateMsg string `yaml:"msg"`
RunAs sdk.AccAddress `yaml:"run_as"`
}{
WasmProposal: p.WasmProposal,
Contract: p.Contract,
Code: p.Code,
CodeID: p.CodeID,
MigrateMsg: string(p.MigrateMsg),
RunAs: p.RunAs,
}, nil
Expand Down
Loading

0 comments on commit 02a54d3

Please sign in to comment.