Skip to content

Commit

Permalink
Hide sov-modules-macros for all public APIs; re-export from `sov-mo…
Browse files Browse the repository at this point in the history
…dules-api` (#542)

* Re-export macros for `sov-modules-api`

* Remove direct use of `sov-modules-macros`

* Update all docs

* Fix intradoc links

* Fix macros module doc comment & import

* Fix all tests

* Fix default features

* Fix README code example
  • Loading branch information
neysofu authored and preston-evans98 committed Sep 14, 2023
1 parent d00a6b3 commit c0a3f97
Show file tree
Hide file tree
Showing 57 changed files with 126 additions and 162 deletions.
3 changes: 1 addition & 2 deletions examples/demo-nft-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ anyhow = { workspace = true }
borsh = { workspace = true, features = ["rc"] }
serde = { workspace = true, optional = true }

sov-modules-api = { path = "../../module-system/sov-modules-api", default-features = false }
sov-modules-macros = { path = "../../module-system/sov-modules-macros" }
sov-modules-api = { path = "../../module-system/sov-modules-api", default-features = false, features = ["macros"] }
sov-state = { path = "../../module-system/sov-state", default-features = false }

[dev-dependencies]
Expand Down
19 changes: 8 additions & 11 deletions examples/demo-nft-module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Here are defining basic dependencies in `Cargo.toml` that module needs to get st
```toml
[dependencies]
anyhow = { anyhow = "1.0.62" }
sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "stable", default-features = false }
sov-modules-macros = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "stable" }
sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "stable", features = ["macros"] }
```

### Establishing the Root Module Structure
Expand All @@ -55,8 +54,7 @@ has private state, which it updates in response to input messages.
NFT module is defined as the following:

```rust
use sov_modules_api::Context;
use sov_modules_macros::ModuleInfo;
use sov_modules_api::{Context, ModuleInfo};

#[derive(ModuleInfo, Clone)]
pub struct NonFungibleToken<C: Context> {
Expand Down Expand Up @@ -121,14 +119,13 @@ Before we start implementing the `Module` trait, there are several preparatory s
serde = { version = "1", features = ["derive"] }
serde_json = "1"

sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "stable", default-features = false }
sov-modules-macros = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "stable" }
sov-state = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "stable", default-features = false }
sov-modules-api = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "stable", default-features = false, features = ["macros"] }
sov-state = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "stable", default-features = false }

[features]
default = ["native"]
serde = ["dep:serde", "dep:serde_json"]
native = ["serde", "sov-state/native", "sov-modules-api/native"]
[features]
default = ["native"]
serde = ["dep:serde", "dep:serde_json"]
native = ["serde", "sov-state/native", "sov-modules-api/native"]
```

This step is necessary to optimize the module for execution in ZK mode, where none of the RPC-related logic is
Expand Down
3 changes: 1 addition & 2 deletions examples/demo-nft-module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ pub mod genesis;
#[cfg(feature = "native")]
pub mod query;

use sov_modules_api::{CallResponse, Context, Error, Module};
use sov_modules_macros::ModuleInfo;
use sov_modules_api::{CallResponse, Context, Error, Module, ModuleInfo};
use sov_state::WorkingSet;

#[derive(ModuleInfo, Clone)]
Expand Down
7 changes: 1 addition & 6 deletions examples/demo-prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions examples/demo-prover/methods/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions examples/demo-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ sov-sequencer-registry = { path = "../../module-system/module-implementations/so
sov-bank = { path = "../../module-system/module-implementations/sov-bank", default-features = false }
sov-modules-stf-template = { path = "../../module-system/sov-modules-stf-template" } # no features available
sov-value-setter = { path = "../../module-system/module-implementations/examples/sov-value-setter", default-features = false }
sov-accounts = { path = "../../module-system/module-implementations/sov-accounts", default-features = false}
sov-accounts = { path = "../../module-system/module-implementations/sov-accounts", default-features = false }
sov-state = { path = "../../module-system/sov-state", default-features = false }
sov-modules-api = { path = "../../module-system/sov-modules-api", default-features = false }
sov-modules-macros = { path = "../../module-system/sov-modules-macros" }
# Only enable the sequencer on "native" feature
sov-modules-api = { path = "../../module-system/sov-modules-api", default-features = false, features = ["macros"] }
sov-sequencer = { path = "../../full-node/sov-sequencer", optional = true }

# Only enable the evm on "experimental" feature
sov-evm = { path = "../../module-system/module-implementations/sov-evm", default-features = false, optional = true}
sov-evm = { path = "../../module-system/module-implementations/sov-evm", default-features = false, optional = true }

[dev-dependencies]
sov-rollup-interface = { path = "../../rollup-interface", features = ["mocks"] }
Expand All @@ -50,8 +48,7 @@ rand = "0.8"

[features]
default = ["native"]
experimental =["sov-evm/experimental"]

experimental = ["sov-evm/experimental"]

native = [
"sov-bank/native",
Expand All @@ -66,5 +63,6 @@ native = [
"serde_json",
"jsonrpsee",
"tokio",
"toml"]
"toml",
]
verifier = []
4 changes: 2 additions & 2 deletions examples/demo-stf/src/batch_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ mod tests {
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::default_signature::private_key::DefaultPrivateKey;
use sov_modules_api::default_signature::DefaultPublicKey;
use sov_modules_api::macros::DefaultRuntime;
use sov_modules_api::transaction::Transaction;
use sov_modules_api::{Context, Genesis};
use sov_modules_macros::{DefaultRuntime, DispatchCall, Genesis, MessageCodec};
use sov_modules_api::{Context, DispatchCall, Genesis, MessageCodec};
use sov_rollup_interface::services::batch_builder::BatchBuilder;
use sov_state::{DefaultStorageSpec, ProverStorage, Storage};
use sov_value_setter::{CallMessage, ValueSetterConfig};
Expand Down
6 changes: 3 additions & 3 deletions examples/demo-stf/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use sov_election::{ElectionRpcImpl, ElectionRpcServer};
use sov_evm::query::{EvmRpcImpl, EvmRpcServer};
#[cfg(feature = "native")]
pub use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::Context;
use sov_modules_api::macros::DefaultRuntime;
#[cfg(feature = "native")]
use sov_modules_macros::{cli_parser, expose_rpc};
use sov_modules_macros::{DefaultRuntime, DispatchCall, Genesis, MessageCodec};
use sov_modules_api::macros::{cli_parser, expose_rpc};
use sov_modules_api::{Context, DispatchCall, Genesis, MessageCodec};
#[cfg(feature = "native")]
use sov_sequencer_registry::{SequencerRegistryRpcImpl, SequencerRegistryRpcServer};
#[cfg(feature = "native")]
Expand Down
2 changes: 1 addition & 1 deletion module-system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<C: sov_modules_api::Context> sov_modules_api::Module for Bank<C> {
### The `RPC` Macro: The Node-to-User Interface

The third interface that modules expose is an rpc implementation. To generate an RPC implementation, simply annotate your `impl` block
with the `#[rpc_gen]` macro from `sov_modules_macros`.
with the `#[rpc_gen]` macro from `sov_modules_api::macros`.

```rust
#[rpc_gen(client, server, namespace = "bank")]
Expand Down
2 changes: 1 addition & 1 deletion module-system/RPC_WALKTHROUGH.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ except that the `method` annotation has been renamed to `rpc_method` to clarify

```rust
// This code goes in your module's query.rs file
use sov_modules_macros::rpc_gen;
use sov_modules_api::macros::rpc_gen;

#[rpc_gen(client, server, namespace = "bank")]
impl<C: Context> Bank<C> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }

sov-modules-api = { path = "../../../sov-modules-api", default-features = false }
sov-modules-macros = { path = "../../../sov-modules-macros" }
sov-modules-api = { path = "../../../sov-modules-api", default-features = false, features = ["macros"] }
sov-state = { path = "../../../sov-state", default-features = false }

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ mod types;
pub use call::CallMessage;
#[cfg(feature = "native")]
pub use query::{ElectionRpcImpl, ElectionRpcServer, GetNbOfVotesResponse, GetResultResponse};
use sov_modules_api::Error;
use sov_modules_macros::ModuleInfo;
use sov_modules_api::{Error, ModuleInfo};
use sov_state::WorkingSet;
pub use types::Candidate;
use types::Voter;
Expand All @@ -21,7 +20,7 @@ pub struct ElectionConfig<C: sov_modules_api::Context> {
pub admin: C::Address,
}

#[cfg_attr(feature = "native", derive(sov_modules_macros::ModuleCallJsonSchema))]
#[cfg_attr(feature = "native", derive(sov_modules_api::ModuleCallJsonSchema))]
#[derive(ModuleInfo, Clone)]
pub struct Election<C: sov_modules_api::Context> {
#[address]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sov_modules_macros::rpc_gen;
use sov_modules_api::macros::rpc_gen;
use sov_state::WorkingSet;

use super::types::Candidate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ tempfile = { workspace = true }

[dependencies]
anyhow = { workspace = true }
sov-modules-api = { path = "../../../sov-modules-api", default-features = false }
sov-modules-macros = { path = "../../../sov-modules-macros" }
sov-modules-api = { path = "../../../sov-modules-api", default-features = false, features = ["macros"] }
sov-state = { path = "../../../sov-state", default-features = false }
sov-rollup-interface = { path = "../../../../rollup-interface" }
schemars = { workspace = true, optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ mod query;
pub use call::CallMessage;
#[cfg(feature = "native")]
pub use query::{Response, ValueSetterRpcImpl, ValueSetterRpcServer};
use sov_modules_api::Error;
use sov_modules_macros::ModuleInfo;
use sov_modules_api::{Error, ModuleInfo};
use sov_state::WorkingSet;

pub struct ValueSetterConfig<C: sov_modules_api::Context> {
Expand All @@ -22,7 +21,7 @@ pub struct ValueSetterConfig<C: sov_modules_api::Context> {
/// - Must derive `ModuleInfo`
/// - Must contain `[address]` field
/// - Can contain any number of ` #[state]` or `[module]` fields
#[cfg_attr(feature = "native", derive(sov_modules_macros::ModuleCallJsonSchema))]
#[cfg_attr(feature = "native", derive(sov_modules_api::ModuleCallJsonSchema))]
#[derive(ModuleInfo)]
pub struct ValueSetter<C: sov_modules_api::Context> {
/// Address of the module.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sov_modules_macros::rpc_gen;
use sov_modules_api::macros::rpc_gen;
use sov_state::WorkingSet;

use super::ValueSetter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ borsh = { workspace = true, features = ["rc"] }
tempfile = { workspace = true }

sov-modules-api = { path = "../../sov-modules-api" }
sov-modules-macros = { path = "../../sov-modules-macros" }
sov-state = { path = "../../sov-state" }
sov-rollup-interface = { path = "../../../rollup-interface" }
sov-schema-db = { path = "../../../full-node/db/sov-schema-db" }

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext};
use sov_modules_api::{Context, Prefix};
use sov_modules_macros::ModuleInfo;
use sov_modules_api::{Context, ModuleInfo, Prefix};
use sov_rollup_interface::stf::Event;
use sov_state::{ProverStorage, StateMap, StateValue, Storage, WorkingSet, ZkStorage};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ resolver = "2"
[dependencies]
anyhow = { workspace = true }
sov-bank = { path = "../sov-bank", default-features = false }
sov-modules-api = { path = "../../sov-modules-api", default-features = false }
sov-modules-macros = { path = "../../sov-modules-macros" }
sov-modules-api = { path = "../../sov-modules-api", default-features = false, features = ["macros"] }
sov-state = { path = "../../sov-state", default-features = false }
sov-rollup-interface = { path = "../../../rollup-interface" }
schemars = { workspace = true, optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ mod query;
pub use call::CallMessage;
#[cfg(feature = "native")]
pub use query::Response;
use sov_modules_api::Error;
use sov_modules_macros::ModuleInfo;
use sov_modules_api::{Error, ModuleInfo};
use sov_state::WorkingSet;

pub struct ExampleModuleConfig {}
Expand All @@ -24,7 +23,7 @@ pub struct ExampleModuleConfig {}
/// This is optional, and is only used to generate a JSON Schema for your
/// module's call messages (which is useful to develop clients, CLI tooling
/// etc.).
#[cfg_attr(feature = "native", derive(sov_modules_macros::ModuleCallJsonSchema))]
#[cfg_attr(feature = "native", derive(sov_modules_api::ModuleCallJsonSchema))]
#[derive(ModuleInfo)]
pub struct ExampleModule<C: sov_modules_api::Context> {
/// Address of the module.
Expand Down
3 changes: 1 addition & 2 deletions module-system/module-implementations/sov-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ serde = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
jsonrpsee = { workspace = true, features = ["macros", "client-core", "server"], optional = true }

sov-modules-api = { path = "../../sov-modules-api", version = "0.1", default-features = false }
sov-modules-macros = { path = "../../sov-modules-macros", version = "0.1" }
sov-modules-api = { path = "../../sov-modules-api", version = "0.1", default-features = false, features = ["macros"] }
sov-state = { path = "../../sov-state", version = "0.1", default-features = false }


Expand Down
Loading

0 comments on commit c0a3f97

Please sign in to comment.