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

feat: Add A New Message For Storing A Code and Instantiating A Contract With It #122

Merged
merged 8 commits into from
Apr 22, 2021

Conversation

loloicci
Copy link
Contributor

@loloicci loloicci commented Apr 8, 2021

Description

This PR adds a new message for storing a wasm code and instantiating a contract with it.

This PR includes

  • adding the message (tested)
  • implementing the handler (tested)
  • implementing a new command to CLI (tested)
  • implementing a new endpoint to REST (NOT tested. because there are no tests for REST for wasm and these will be abolished or published after being tested.)

This is part of #111. After we make a stable wasm module for v2, we will make the same message for v2 and then closes it.


  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/) (There are no docs)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md (It will be generated with script, right?)
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@loloicci loloicci added the C:WASM label Apr 8, 2021
@loloicci loloicci self-assigned this Apr 8, 2021
@LINK-Network-Dev
Copy link

tps:337

@LINK-Network-Dev
Copy link

tps:331

Comment on lines 100 to 103
err := msg.ValidateBasic()
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContractAddress: contractAddr,
}

bz, err := codec.MarshalJSONIndent(types.ModuleCdc, data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data of msg should be length prefixed. (according to https://github.com/line/lbm-sdk/blob/v1/develop/baseapp/baseapp.go#L689-L690)
(FYI, https://github.com/line/lbm-sdk/blob/v1/develop/x/staking/handler.go#L220)

k.cdc.MarshalBinaryLengthPrefixed()

But this contract is not kept in many modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't k.cdc private field and hidden from handler.go?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! The staking module uses types.ModuleCdc for codec. we can use it I think.

Comment on lines 116 to 122
ourEvent := sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender.String()),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)),
sdk.NewAttribute(types.AttributeKeyContract, contractAddr.String()),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LINK-Network-Dev
Copy link

tps:317

@loloicci
Copy link
Contributor Author

7c8be83 includes removing the unneeded validating of messages. Missed writing in the commit message.

Comment on lines +110 to +122
storeEvent := sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender.String()),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)),
)
instantiateEvent := sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, ModuleName),
sdk.NewAttribute(types.AttributeKeySigner, msg.Sender.String()),
sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)),
sdk.NewAttribute(types.AttributeKeyContract, contractAddr.String()),
)
Copy link
Contributor

@whylee259 whylee259 Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem that we should define another EventType to specify msg action details.

It seems that x/wasm is using events incorrectly as a whole.

The original concept seems that EventTypeMessage specifies only module and sender and the details of action will be included in another EventType

Let's correct it another issue.

brew0722 pushed a commit that referenced this pull request Apr 19, 2021
* Start migration server side

* Return migration response and emit events

* Dispatch migrate contract messages

* Rebase to 0.9 and minor updates

* Review feedback

* Update changelog

* Add msg test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants