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

chore(proto): Add a buf.gen.rs.yaml and corresponding script to create Rust types for Wasm Stargate messages #1579

Merged
merged 15 commits into from
Sep 27, 2023

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Sep 14, 2023

Context

This implements:

  1. A buf.gen.*.yaml for Rust code generation
  2. A corresponding script that programatically reads the go.mod for versions and performs the
    code generation with buf. Generated types end up in the git ignored dist folder.

For Reviewer

Try running bash proto/buf.gen.rs.sh from the root of the repo.
You should get the following output:

NIBIRU_REPO_PATH: /home/realu/warpath/NibiruChain/nibiru
OUT_PATH: /home/realu/warpath/NibiruChain/nibiru/dist
Grabbing cosmos-sdk proto file locations from disk
NIBIRU_REPO_PATH: /home/realu/warpath/NibiruChain/nibiru

Proto Directories: 
/home/realu/warpath/NibiruChain/cosmos-sdk/proto
Generating protobuf types for each proto_dir
------------ generating cosmos-sdk/proto ------------
------------ generating nibiru/proto ------------
Completed - proto_gen() to path: /home/realu/warpath/NibiruChain/nibiru/dist
🔥 Generated Rust proto types successfully. 

This should put a bunch of Rust code in your dist directory (it's gitignored).

Purpose

This is useful for implementing raw smart contract execute calls via
CosmosMsg::StargateMsg (rather than CosmosMsg::Custom). This functionality's needed to develop a Rust package that
has functions for calling TxMsgs from custom modules on Nibiru.


↑ For reference: the messages that can be sent from a contract are as follows:

#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
// See https://github.com/serde-rs/serde/issues/1296 why we cannot add De-Serialize trait bounds to T
pub enum CosmosMsg<T = Empty> {
    Bank(BankMsg),
    // by default we use RawMsg, but a contract can override that
    // to call into more app-specific code (whatever they define)
    Custom(T),
    #[cfg(feature = "staking")]
    Staking(StakingMsg),
    #[cfg(feature = "staking")]
    Distribution(DistributionMsg),
    /// A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto).
    /// This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)
    #[cfg(feature = "stargate")]
    Stargate {
        type_url: String,
        value: Binary,
    },
    #[cfg(feature = "stargate")]
    Ibc(IbcMsg),
    Wasm(WasmMsg),
    #[cfg(feature = "stargate")]
    Gov(GovMsg),
}

@Unique-Divine Unique-Divine requested a review from a team as a code owner September 14, 2023 01:11
@@ -0,0 +1,173 @@
#!/usr/bin/env bash
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd recommend reading main() and working backwards since bash is a bit hard to follow

@NibiruChain NibiruChain deleted a comment from codecov bot Sep 14, 2023
@NibiruChain NibiruChain deleted a comment from codecov bot Sep 14, 2023
@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Merging #1579 (fdde88f) into master (a039623) will decrease coverage by 0.02%.
Report is 1 commits behind head on master.
The diff coverage is n/a.

❗ Current head fdde88f differs from pull request most recent head e906ca7. Consider uploading reports for the commit e906ca7 to get more accurate results

@@            Coverage Diff             @@
##           master    #1579      +/-   ##
==========================================
- Coverage   70.73%   70.71%   -0.02%     
==========================================
  Files         181      180       -1     
  Lines       14917    14786     -131     
==========================================
- Hits        10551    10456      -95     
+ Misses       3677     3651      -26     
+ Partials      689      679      -10     

@sonarcloud
Copy link

sonarcloud bot commented Sep 25, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@k-yang k-yang enabled auto-merge (squash) September 27, 2023 19:47
@k-yang k-yang merged commit 0c31eaf into master Sep 27, 2023
9 checks passed
@k-yang k-yang deleted the realu/bash-for-rs branch September 27, 2023 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants