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: replace proto build #NTRN-326 #156

Merged
merged 16 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.73.0
toolchain: 1.78.0
components: clippy
profile: minimal
override: true
Expand All @@ -31,7 +31,7 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.73.0
toolchain: 1.78.0
components: rustfmt
profile: minimal
override: true
Expand All @@ -49,7 +49,7 @@ jobs:
fetch-depth: 1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.73.0
toolchain: 1.78.0
profile: minimal
- run: cargo fetch --verbose
- run: cargo build
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ incremental = false
overflow-checks = true

[workspace.dependencies]
cosmwasm-std = "2.0.4"
cosmwasm-std = "2.1.0"
cosmwasm-schema = { version = "2.1.0", default-features = false }
cw2 = "2.0.0"
cw-storage-plus = "2.0.0"
schemars = "0.8.15"
serde = { version = "1.0.188", default-features = false }
serde-json-wasm = "1.0.0"
cw-storage-plus = "2.0.0"
cosmwasm-schema = { version = "2.0.4", default-features = false }
base64 = "0.21.7"
prost = "0.12.3"
prost-types = "0.12.1"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ check_contracts:
build: schema clippy test fmt doc compile check_contracts

build-proto:
@cargo run --bin proto-build $(revision)
@cargo run --bin proto-build
pr0n00gler marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ The Neutron SDK is contained inside `packages` folder and consists of the follow

| Package | Reference | Description |
|---------------------------------|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
| Neutron Interchain Queries | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/interchain_queries | Queries, messages and helper methods for interacting with Neutron Interchain Queries Module |
| Neutron Interchain Transactions | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/interchain_txs | Queries, messages and helper methods for interacting with Neutron Interchain Transactions Module |
| Neutron Bindings | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/bindings | Structures and helper methods for interacting with Neutron blockchain |
| Neutron Sudo | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/sudo | Structures for Sudo Contract callbacks from Neutron blockchain |
| Neutron Errors | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/errors | Structures and helpers for Neutron specific error and result types |
| Neutron Stargate | https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/stargate | Structures and helpers for interacting with Neutron via Stargate |
| Neutron Interchain Queries | <https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/interchain_queries> | Queries, messages and helper methods for interacting with Neutron Interchain Queries Module |
| Neutron Interchain Transactions | <https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/interchain_txs> | Queries, messages and helper methods for interacting with Neutron Interchain Transactions Module |
| Neutron Bindings | <https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/bindings> | Structures and helper methods for interacting with Neutron blockchain |
| Neutron Sudo | <https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/sudo> | Structures for Sudo Contract callbacks from Neutron blockchain |
| Neutron Errors | <https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/errors> | Structures and helpers for Neutron specific error and result types |
| Neutron Stargate | <https://github.com/neutron-org/neutron-sdk/tree/main/packages/neutron-sdk/src/stargate> | Structures and helpers for interacting with Neutron via Stargate |

### Example Contracts

We provide sample contracts that either implement or consume these specifications to both provide examples, and provide a basis for code you can extend for more custom contacts, without worrying about reinventing the wheel each time:

| Contract | Reference | Description |
|--------------------------------------------------|-------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Neutron Interchain Queries Example Contract | https://github.com/neutron-org/neutron-sdk/tree/main/contracts/neutron_interchain_queries | The contract shows how to properly work with [Interchain Queries Module](https://github.com/neutron-org/neutron/tree/master/x/interchainqueries) using [Interchain Queries SDK package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron-sdk/src/interchain_queries) via CosmWasm smart-contract. |
| Neutron Interchain Transactions Example Contract | https://github.com/neutron-org/neutron-sdk/tree/main/contracts/neutron_interchain_txs | The contract shows how to properly work with [Neutron Interchain Transactions Module](https://github.com/neutron-org/neutron/tree/master/x/interchaintxs) using [Interchain Transactions SDK package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron-sdk/src/interchain_txs) via CosmWasm smart-contract. |
| Neutron IBC Transfer Example Contract | https://github.com/neutron-org/neutron-sdk/tree/main/contracts/ibc_transfer | The contract shows how to properly work with [Neutron Sudo Package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron_sudo) to handle a callback from IBC transfer. |
| Neutron Interchain Queries Example Contract | <https://github.com/neutron-org/neutron-sdk/tree/main/contracts/neutron_interchain_queries> | The contract shows how to properly work with [Interchain Queries Module](https://github.com/neutron-org/neutron/tree/master/x/interchainqueries) using [Interchain Queries SDK package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron-sdk/src/interchain_queries) via CosmWasm smart-contract. |
| Neutron Interchain Transactions Example Contract | <https://github.com/neutron-org/neutron-sdk/tree/main/contracts/neutron_interchain_txs> | The contract shows how to properly work with [Neutron Interchain Transactions Module](https://github.com/neutron-org/neutron/tree/master/x/interchaintxs) using [Interchain Transactions SDK package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron-sdk/src/interchain_txs) via CosmWasm smart-contract. |
| Neutron IBC Transfer Example Contract | <https://github.com/neutron-org/neutron-sdk/tree/main/contracts/ibc_transfer> | The contract shows how to properly work with [Neutron Sudo Package](https://github.com/neutron-org/neutron-contracts/tree/main/packages/neutron_sudo) to handle a callback from IBC transfer. |

## Development

Expand All @@ -35,7 +35,7 @@ We provide sample contracts that either implement or consume these specification
- `wasm32-unknown-unknown` target
- Docker

1. Install `rustup` via https://rustup.rs/
1. Install `rustup` via <https://rustup.rs/>

2. Run the following:

Expand Down Expand Up @@ -64,9 +64,10 @@ make schema

Neutron proto files represented as generated Rust code is a part of the Neutron SDK. In case Neutron
proto files have changed there's a command for Rust generated code rebuild. To rebuild the files,
run the following command using the respective Neutron revision (tag) as an argument, e.g.:
run the following command:

```sh
make build-proto revision=v3.0.3
make build-proto
```

### Production
Expand All @@ -81,7 +82,7 @@ This performs several optimizations which can significantly reduce the final siz

## Documentation

Check out our documentation at https://docs.neutron.org.
Check out our documentation at <https://docs.neutron.org>.

## License

Expand Down
7 changes: 5 additions & 2 deletions packages/neutron-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ homepage = "https://neutron.org"
readme = "README.md"

[dependencies]
cosmwasm-std = { workspace = true, features = ["stargate"] }
cosmwasm-std = { workspace = true, features = ["cosmwasm_2_0"] }
cosmos-sdk-proto = { workspace = true }
serde = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde-cw-value = "0.7.0"
schemars = { workspace = true }
serde-json-wasm = { workspace = true }
bech32 = { workspace = true }
Expand All @@ -23,6 +24,8 @@ prost = { workspace = true }
prost-types = { workspace = true }
tendermint-proto = { workspace = true }
speedate = { workspace = true }
chrono = { version = "0.4.22", default-features = false }
neutron-std-derive = { version = "0.20.1", path = "../neutron-std-derive" }

[dev-dependencies]
base64 = { workspace = true }
Expand Down
13 changes: 12 additions & 1 deletion packages/neutron-sdk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]
// #![forbid(unsafe_code)]
#![warn(trivial_casts, trivial_numeric_casts, unused_import_braces)]

/// The version (commit hash) of the Cosmos SDK used when generating this library.
pub const NEUTROND_VERSION: &str = include_str!("proto_types/NEUTRON_COMMIT");

pub mod bindings;
mod errors;
pub mod interchain_queries;
pub mod interchain_txs;
#[allow(deprecated, clippy::module_inception)]
pub mod proto_types;
pub mod query;
pub mod stargate;
mod serde;
pub mod shim;
pub mod sudo;

pub use errors::error::{NeutronError, NeutronResult};
pub use shim::{cosmwasm_to_proto_coins, try_proto_to_cosmwasm_coins};

// This is a signal, such that any contract that imports these helpers will only run on the
// neutron blockchain
Expand Down
2 changes: 1 addition & 1 deletion packages/neutron-sdk/src/proto_types/NEUTRON_COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a6eae66545df6e128da2c7cac81ff4c1c02deb7b
v4.1.0
1 change: 1 addition & 0 deletions packages/neutron-sdk/src/proto_types/capability/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod v1;
112 changes: 112 additions & 0 deletions packages/neutron-sdk/src/proto_types/capability/v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
use neutron_std_derive::CosmwasmExt;
/// Capability defines an implementation of an object capability. The index
/// provided to a Capability must be globally unique.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/capability.v1.Capability")]
pub struct Capability {
#[prost(uint64, tag = "1")]
#[serde(
serialize_with = "crate::serde::as_str::serialize",
deserialize_with = "crate::serde::as_str::deserialize"
)]
pub index: u64,
}
/// Owner defines a single capability owner. An owner is defined by the name of
/// capability and the module name.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/capability.v1.Owner")]
pub struct Owner {
#[prost(string, tag = "1")]
pub module: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub name: ::prost::alloc::string::String,
}
/// CapabilityOwners defines a set of owners of a single Capability. The set of
/// owners must be unique.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/capability.v1.CapabilityOwners")]
pub struct CapabilityOwners {
#[prost(message, repeated, tag = "1")]
pub owners: ::prost::alloc::vec::Vec<Owner>,
}
/// GenesisOwners defines the capability owners with their corresponding index.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/capability.v1.GenesisOwners")]
pub struct GenesisOwners {
/// index is the index of the capability owner.
#[prost(uint64, tag = "1")]
#[serde(
serialize_with = "crate::serde::as_str::serialize",
deserialize_with = "crate::serde::as_str::deserialize"
)]
pub index: u64,
/// index_owners are the owners at the given index.
#[prost(message, optional, tag = "2")]
pub index_owners: ::core::option::Option<CapabilityOwners>,
}
/// GenesisState defines the capability module's genesis state.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/capability.v1.GenesisState")]
pub struct GenesisState {
/// index is the capability global index.
#[prost(uint64, tag = "1")]
#[serde(
serialize_with = "crate::serde::as_str::serialize",
deserialize_with = "crate::serde::as_str::deserialize"
)]
pub index: u64,
/// owners represents a map from index to owners of the capability index
/// index key is string to allow amino marshalling.
#[prost(message, repeated, tag = "2")]
pub owners: ::prost::alloc::vec::Vec<GenesisOwners>,
}
2 changes: 2 additions & 0 deletions packages/neutron-sdk/src/proto_types/cosmos/app/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod runtime;
pub mod v1alpha1;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod v1alpha1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use neutron_std_derive::CosmwasmExt;
/// Module is the config object for the runtime module.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/cosmos.app.runtime.v1alpha1.Module")]
pub struct Module {
/// app_name is the name of the app.
#[prost(string, tag = "1")]
pub app_name: ::prost::alloc::string::String,
/// begin_blockers specifies the module names of begin blockers
/// to call in the order in which they should be called. If this is left empty
/// no begin blocker will be registered.
#[prost(string, repeated, tag = "2")]
pub begin_blockers: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// end_blockers specifies the module names of the end blockers
/// to call in the order in which they should be called. If this is left empty
/// no end blocker will be registered.
#[prost(string, repeated, tag = "3")]
pub end_blockers: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// init_genesis specifies the module names of init genesis functions
/// to call in the order in which they should be called. If this is left empty
/// no init genesis function will be registered.
#[prost(string, repeated, tag = "4")]
pub init_genesis: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// export_genesis specifies the order in which to export module genesis data.
/// If this is left empty, the init_genesis order will be used for export genesis
/// if it is specified.
#[prost(string, repeated, tag = "5")]
pub export_genesis: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// override_store_keys is an optional list of overrides for the module store keys
/// to be used in keeper construction.
#[prost(message, repeated, tag = "6")]
pub override_store_keys: ::prost::alloc::vec::Vec<StoreKeyConfig>,
/// order_migrations defines the order in which module migrations are performed.
/// If this is left empty, it uses the default migration order.
/// <https://pkg.go.dev/github.com/cosmos/[email protected]/types/module#DefaultMigrationsOrder>
#[prost(string, repeated, tag = "7")]
pub order_migrations: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// precommiters specifies the module names of the precommiters
/// to call in the order in which they should be called. If this is left empty
/// no precommit function will be registered.
#[prost(string, repeated, tag = "8")]
pub precommiters: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// prepare_check_staters specifies the module names of the prepare_check_staters
/// to call in the order in which they should be called. If this is left empty
/// no preparecheckstate function will be registered.
#[prost(string, repeated, tag = "9")]
pub prepare_check_staters: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
/// StoreKeyConfig may be supplied to override the default module store key, which
/// is the module name.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/cosmos.app.runtime.v1alpha1.StoreKeyConfig")]
pub struct StoreKeyConfig {
/// name of the module to override the store key of
#[prost(string, tag = "1")]
pub module_name: ::prost::alloc::string::String,
/// the kv store key to use instead of the module name.
#[prost(string, tag = "2")]
pub kv_store_key: ::prost::alloc::string::String,
}
Loading
Loading