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 serde feature for non-native serialization #1141

Merged
merged 1 commit into from
Nov 8, 2023
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
10 changes: 10 additions & 0 deletions examples/demo-rollup/stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,18 @@ native = [
"sov-mock-da/native",
"sov-modules-stf-template/native",
"clap",
"serde",
"serde_json",
"jsonrpsee",
"tokio",
"toml",
]
serde = [
"sov-bank/serde",
"sov-sequencer-registry/serde",
"sov-blob-storage/serde",
"sov-value-setter/serde",
"sov-accounts/serde",
"sov-nft-module/serde",
"sov-evm?/serde",
]
5 changes: 1 addition & 4 deletions examples/demo-rollup/stf/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ use crate::genesis_config::GenesisPaths;
#[cfg_attr(feature = "native", derive(CliWallet), expose_rpc)]
#[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)]
#[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)]
#[cfg_attr(
feature = "native",
serialization(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(feature = "serde", serialization(serde::Serialize, serde::Deserialize))]
pub struct Runtime<C: Context, Da: DaSpec> {
/// The Bank module.
pub bank: sov_bank::Bank<C>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ clap = { workspace = true, optional = true }

[features]
default = []
native = ["serde_json", "jsonrpsee", "schemars", "clap", "sov-modules-api/native", "sov-state/native"]
native = ["serde", "serde_json", "jsonrpsee", "schemars", "clap", "sov-modules-api/native", "sov-state/native"]
serde = []
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use thiserror::Error;
use super::ValueSetter;

/// This enumeration represents the available call messages for interacting with the `sov-value-setter` module.
#[cfg_attr(feature = "native", derive(CliWalletArg), derive(schemars::JsonSchema))]
#[cfg_attr(
feature = "native",
feature = "serde",
derive(serde::Serialize),
derive(serde::Deserialize),
derive(CliWalletArg),
derive(schemars::JsonSchema)
derive(serde::Deserialize)
)]
#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)]
pub enum CallMessage {
Expand Down
3 changes: 2 additions & 1 deletion module-system/module-implementations/sov-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ arbitrary = [
"sov-modules-api/arbitrary",
"sov-state/arbitrary"
]
native = ["serde_json", "jsonrpsee", "schemars", "clap", "sov-state/native", "sov-modules-api/native"]
native = ["serde", "serde_json", "jsonrpsee", "schemars", "clap", "sov-state/native", "sov-modules-api/native"]
serde = []
7 changes: 5 additions & 2 deletions module-system/module-implementations/sov-accounts/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ pub const UPDATE_ACCOUNT_MSG: [u8; 32] = [1; 32];
/// Represents the available call messages for interacting with the sov-accounts module.
#[cfg_attr(
feature = "native",
derive(serde::Serialize),
derive(serde::Deserialize),
derive(schemars::JsonSchema),
derive(sov_modules_api::macros::CliWalletArg),
schemars(
bound = "C::PublicKey: ::schemars::JsonSchema, C::Signature: ::schemars::JsonSchema",
rename = "CallMessage"
)
)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize),
derive(serde::Deserialize)
)]
#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)]
pub enum CallMessage<C: Context> {
/// Updates a public key for the corresponding Account.
Expand Down
3 changes: 2 additions & 1 deletion module-system/module-implementations/sov-bank/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ tempfile = { workspace = true }

[features]
default = []
native = ["serde_json", "jsonrpsee", "clap", "schemars", "sov-state/native", "sov-modules-api/native", ]
native = ["serde", "serde_json", "jsonrpsee", "clap", "schemars", "sov-state/native", "sov-modules-api/native", ]
cli = ["native"]
serde = []
7 changes: 5 additions & 2 deletions module-system/module-implementations/sov-bank/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ use crate::{Amount, Bank, Coins, Token};
/// This enumeration represents the available call messages for interacting with the sov-bank module.
#[cfg_attr(
feature = "native",
derive(serde::Serialize),
derive(serde::Deserialize),
derive(CliWalletArg),
derive(schemars::JsonSchema),
schemars(bound = "C::Address: ::schemars::JsonSchema", rename = "CallMessage")
)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize),
derive(serde::Deserialize)
)]
#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)]
pub enum CallMessage<C: sov_modules_api::Context> {
/// Creates a new token with the specified name and initial balance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ jmt = { workspace = true }
[features]
default = []
native = ["jsonrpsee", "schemars", "serde", "serde_json", "sov-modules-api/native", "sov-state/native", "sov-sequencer-registry/native", "clap"]
serde = ["dep:serde"]
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ use crate::BlobStorage;
/// A call message for the blob storage module
#[cfg_attr(
feature = "native",
derive(serde::Serialize),
derive(serde::Deserialize),
derive(sov_modules_api::macros::CliWalletArg),
derive(schemars::JsonSchema)
)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize),
derive(serde::Deserialize)
)]
#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)]
pub enum CallMessage {
/// Asks the blob selector to process up to the given number of deferred blobs early.
Expand Down
1 change: 1 addition & 0 deletions module-system/module-implementations/sov-evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ native = [
"sov-modules-api/native",
]
experimental = ["native"]
serde = ["dep:serde"]
smart_contracts = ["experimental"]
2 changes: 1 addition & 1 deletion module-system/module-implementations/sov-evm/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::experimental::PendingTransaction;
use crate::Evm;

#[cfg_attr(
feature = "native",
feature = "serde",
derive(serde::Serialize),
derive(serde::Deserialize)
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ sov-nft-module = { version = "*", features = ["native"], path = "." }
[features]
default = []
offchain = ["postgres","tokio","tracing"]
native = ["serde_json", "jsonrpsee", "schemars", "sov-state/native", "sov-modules-api/native", ]
native = ["serde", "serde_json", "jsonrpsee", "schemars", "sov-state/native", "sov-modules-api/native", ]
serde = []
test = ["native"]
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ use crate::{Collection, CollectionAddress, Nft, NftIdentifier, NonFungibleToken,

#[cfg_attr(
feature = "native",
derive(serde::Serialize),
derive(serde::Deserialize),
derive(schemars::JsonSchema),
schemars(bound = "C::Address: ::schemars::JsonSchema", rename = "CallMessage")
)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize),
derive(serde::Deserialize)
)]
#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)]
/// A transaction handled by the NFT module. Mints, Transfers, or Burns an NFT by id
pub enum CallMessage<C: Context> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bench = ["sov-zk-cycle-macros/bench", "risc0-zkvm", "risc0-zkvm-platform", "sov-
default = []
arbitrary = ["dep:arbitrary", "dep:proptest", "dep:proptest-derive"]
native = [
"serde",
"serde_json",
"jsonrpsee",
"schemars",
Expand All @@ -50,3 +51,4 @@ native = [
# This:
"sov-bank/native",
]
serde = []
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ use crate::SequencerRegistry;

/// This enumeration represents the available call messages for interacting with
/// the `sov-sequencer-registry` module.
#[cfg_attr(feature = "native", derive(schemars::JsonSchema), derive(CliWalletArg))]
#[cfg_attr(
feature = "native",
feature = "serde",
derive(serde::Serialize),
derive(serde::Deserialize),
derive(schemars::JsonSchema),
derive(CliWalletArg)
derive(serde::Deserialize)
)]
#[cfg_attr(
feature = "arbitrary",
Expand Down
2 changes: 2 additions & 0 deletions module-system/sov-modules-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ native = [
"serde_json",
"rand",
"schemars",
"serde",
"ed25519-dalek/default",
"ed25519-dalek/rand_core",
"clap",
Expand All @@ -71,3 +72,4 @@ native = [
"sov-state/native",
]
macros = ["sov-modules-macros"]
serde = ["sov-modules-core/serde"]
4 changes: 2 additions & 2 deletions module-system/sov-modules-api/src/default_context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "native")]
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use sha2::Digest;
use sov_modules_core::{Address, Context, PublicKey, Spec, TupleGasUnit};
Expand Down Expand Up @@ -43,7 +43,7 @@ impl Context for DefaultContext {
}

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "native", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ZkDefaultContext {
pub sender: Address,
}
Expand Down
6 changes: 2 additions & 4 deletions module-system/sov-modules-api/src/default_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ impl BorshSerialize for DefaultPublicKey {
}
}

#[cfg_attr(
feature = "native",
derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
)]
#[cfg_attr(feature = "native", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct DefaultSignature {
#[cfg_attr(
Expand Down
1 change: 1 addition & 0 deletions module-system/sov-modules-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ std = [
"sync",
"thiserror",
]
serde = []
sync = [
"borsh/rc",
"serde/rc",
Expand Down
8 changes: 7 additions & 1 deletion module-system/sov-modules-core/src/module/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ pub trait Spec {
+ schemars::JsonSchema;

/// The digital signature scheme used by the rollup
#[cfg(not(all(feature = "native", feature = "std")))]
#[cfg(all(not(all(feature = "native", feature = "std")), not(feature = "serde")))]
type Signature: Signature<PublicKey = Self::PublicKey>;

/// The digital signature scheme used by the rollup
#[cfg(all(not(all(feature = "native", feature = "std")), feature = "serde"))]
type Signature: Signature<PublicKey = Self::PublicKey>
+ serde::Serialize
+ for<'a> serde::Deserialize<'a>;

/// A structure containing the non-deterministic inputs from the prover to the zk-circuit
type Witness: Witness;
}
Expand Down
1 change: 1 addition & 0 deletions module-system/sov-modules-macros/src/new_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn address_type_helper(input: DeriveInput) -> Result<TokenStream, syn::Error
pub struct #name<C: Context>(C::Address);

#[cfg(not(feature = "native"))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Clone, Debug, PartialEq, Eq, Hash)]
#(#attrs)*
pub struct #name<C: Context>(C::Address);
Expand Down
Loading