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

Test substrate serde branch #407

Closed
wants to merge 16 commits into from
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ jobs:
# Compile async example separately to enable async-mode
cargo build --release -p ac-examples --example get_blocks_async --no-default-features,

# Test for no-std serde feature.
cargo build --release -p test-no-std --features application-crypto,
cargo build --release -p test-no-std --features arithmetic,
cargo build --release -p test-no-std --features beefy,
cargo build --release -p test-no-std --features babe,
cargo build --release -p test-no-std --features slots,
cargo build --release -p test-no-std --features core,
cargo build --release -p test-no-std --features finality-grandpa,
cargo build --release -p test-no-std --features mmr,
cargo build --release -p test-no-std --features npos-elections,
cargo build --release -p test-no-std --features runtime,
cargo build --release -p test-no-std --features storage,
cargo build --release -p test-no-std --features test-primitives,
cargo build --release -p test-no-std --features version,
cargo build --release -p test-no-std --features weights,


# Clippy
cargo clippy --workspace --exclude test-no-std -- -D warnings,
cargo clippy --all-features --examples -- -D warnings,
Expand Down
358 changes: 210 additions & 148 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ tungstenite = { version = "0.18.0", optional = true, features = ["native-tls"] }
ws = { version = "0.9.2", optional = true, features = ["ssl"] }

# Substrate no_std dependencies
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime-interface = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { default-features = false, features = ["full_crypto", "serde"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-rpc = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-runtime = { default-features = false, features = ["serde"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-runtime-interface = { default-features = false, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-storage = { default-features = false, features = ["serde"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-version = { default-features = false, features = ["serde"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

# substrate std / wasm only
frame-support = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-support = { optional = true, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

# local deps
ac-compose-macros = { path = "compose-macros", default-features = false }
Expand All @@ -59,7 +62,7 @@ ac-primitives = { path = "primitives", default-features = false }

[dev-dependencies]
ac-node-api = { path = "node-api", features = ["mocks"] }
kitchensink-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
kitchensink-runtime = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
scale-info = { version = "2.1.1", features = ["derive"] }

[features]
Expand Down Expand Up @@ -103,6 +106,8 @@ std = [
"sp-core/std",
"sp-runtime/std",
"sp-runtime-interface/std",
"sp-storage/std",
"sp-version/std",
# substrate std
"frame-support",
# local deps
Expand Down
10 changes: 5 additions & 5 deletions client-keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ parking_lot = "0.12.0"
serde_json = "1.0.79"

# Substrate dependencies
sc-keystore = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keystore = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sc-keystore = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-application-crypto = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-core = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-keyring = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-keystore = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

[dev-dependencies]
tempfile = "3.3.0"
32 changes: 19 additions & 13 deletions client-keystore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
use parking_lot::RwLock;
use sp_application_crypto::{AppCrypto, AppPair, IsWrappedBy};
use sp_core::{
crypto::{ByteArray, ExposeSecret, KeyTypeId, Pair as CorePair, SecretString},
crypto::{ByteArray, ExposeSecret, KeyTypeId, Pair as CorePair, SecretString, VrfSigner},
ecdsa, ed25519, sr25519,
};
use sp_keystore::{
vrf::{make_transcript, VRFSignature, VRFTranscriptData},
Error as TraitError, Keystore, KeystorePtr,
};
use sp_keystore::{Error as TraitError, Keystore, KeystorePtr};
use std::{
collections::HashMap,
fs::{self, File},
Expand Down Expand Up @@ -102,6 +99,20 @@ impl LocalKeystore {
.map(|pair| pair.sign(msg));
Ok(signature)
}

fn vrf_sign<T: CorePair + VrfSigner>(
&self,
key_type: KeyTypeId,
public: &T::Public,
transcript: &T::VrfInput,
) -> std::result::Result<Option<T::VrfSignature>, TraitError> {
let sig = self
.0
.read()
.key_pair_by_type::<T>(public, key_type)?
.map(|pair| pair.vrf_sign(transcript));
Ok(sig)
}
}

impl Keystore for LocalKeystore {
Expand Down Expand Up @@ -133,14 +144,9 @@ impl Keystore for LocalKeystore {
&self,
key_type: KeyTypeId,
public: &sr25519::Public,
transcript_data: VRFTranscriptData,
) -> std::result::Result<Option<VRFSignature>, TraitError> {
let sig = self.0.read().key_pair_by_type::<sr25519::Pair>(public, key_type)?.map(|pair| {
let transcript = make_transcript(transcript_data);
let (inout, proof, _) = pair.as_ref().vrf_sign(transcript);
VRFSignature { output: inout.to_output(), proof }
});
Ok(sig)
transcript: &sr25519::vrf::VrfTranscript,
) -> std::result::Result<Option<sr25519::vrf::VrfSignature>, TraitError> {
self.vrf_sign::<sr25519::Pair>(key_type, public, transcript)
}

fn ed25519_public_keys(&self, key_type: KeyTypeId) -> Vec<ed25519::Public> {
Expand Down
20 changes: 10 additions & 10 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ tokio = { version = "1.24", features = ["rt-multi-thread", "macros", "time"] }
wabt = "0.10.0"

# Substrate dependencies
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
kitchensink-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-balances = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-identity = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-staking = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-support = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
frame-system = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
kitchensink-runtime = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
pallet-balances = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
pallet-identity = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
pallet-staking = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-core = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-keyring = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-runtime = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-version = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

# local deps
substrate-api-client = { path = "..", default-features = false, features = ["jsonrpsee-client", "tungstenite-client", "ws-client", "staking-xt", "contracts-xt"] }
Expand Down
10 changes: 6 additions & 4 deletions node-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ serde = { version = "1.0.136", features = ["derive"], default-features = false }
serde_json = { version = "1.0.79", default-features = false, features = ["alloc"] }

# substrate
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-runtime = { default-features = false, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-storage = { default-features = false, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

# need to add this for `no_std`
sp-application-crypto = { default-features = false, git = "https://github.com/paritytech/substrate.git", features = ["full_crypto"], branch = "master" }
sp-runtime-interface = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-application-crypto = { default-features = false, git = "https://github.com/haerdib/substrate.git", features = ["full_crypto"], branch = "add-serde-feature-to-primitives" }
sp-runtime-interface = { default-features = false, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

# local
ac-primitives = { path = "../primitives", default-features = false }
Expand All @@ -51,6 +52,7 @@ std = [
# substrate
"sp-core/std",
"sp-runtime/std",
"sp-storage/std",
# no_std support
"sp-application-crypto/std",
"sp-runtime-interface/std",
Expand Down
2 changes: 1 addition & 1 deletion node-api/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
//! This file is mostly subxt.

use crate::{alloc::borrow::ToOwned, storage::GetStorageTypes, Encoded};
use ac_primitives::StorageKey;
use codec::{Decode, Encode, Error as CodecError};
use frame_metadata::{
PalletConstantMetadata, RuntimeMetadata, RuntimeMetadataLastVersion, RuntimeMetadataPrefixed,
StorageEntryMetadata, META_RESERVED,
};
use scale_info::{form::PortableForm, PortableRegistry, Type};
use sp_storage::StorageKey;

#[cfg(feature = "std")]
use serde::Serialize;
Expand Down
2 changes: 1 addition & 1 deletion node-api/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
//! For querying runtime storage.

use crate::metadata::MetadataError;
use ac_primitives::StorageKey;
use alloc::{borrow::ToOwned, vec::Vec};
use codec::Encode;
use core::marker::PhantomData;
use frame_metadata::{StorageEntryMetadata, StorageEntryType, StorageHasher};
use scale_info::form::PortableForm;
use sp_storage::StorageKey;

#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd)]
pub struct StorageValue {
Expand Down
32 changes: 16 additions & 16 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ serde = { version = "1.0", default-features = false, features = ["derive", "allo
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }

# substrate no_std
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core-hashing = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime-interface = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-staking = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-version = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-weights = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-core = { default-features = false, features = ["full_crypto", "serde"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-core-hashing = { default-features = false, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-runtime = { default-features = false, features = ["serde"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-runtime-interface = { default-features = false, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-staking = { default-features = false, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-version = { default-features = false, features = ["serde"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-weights = { default-features = false, features = ["serde"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
# need to add this for the app_crypto macro
sp-application-crypto = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-application-crypto = { default-features = false, features = ["full_crypto"], git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

# substrate std / wasm only
frame-system = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-assets = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-balances = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-contracts = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
pallet-staking = { optional = true, git = "https://github.com/paritytech/substrate.git", branch = "master" }
frame-system = { optional = true, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
pallet-assets = { optional = true, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
pallet-balances = { optional = true, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
pallet-contracts = { optional = true, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
pallet-staking = { optional = true, git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

[dev-dependencies]
node-template-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-keyring = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
node-template-runtime = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }
sp-keyring = { git = "https://github.com/haerdib/substrate.git", branch = "add-serde-feature-to-primitives" }

[features]
default = ["std"]
Expand All @@ -58,8 +58,8 @@ std = [
"sp-runtime/std",
"sp-staking/std",
"sp-version/std",
# app_crypto macro
"sp-application-crypto/std",
"sp-weights/std",
# substrate std
"frame-system",
"pallet-assets",
Expand Down
10 changes: 6 additions & 4 deletions primitives/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use core::{fmt::Debug, marker::PhantomData};
use codec::{Decode, Encode, FullCodec};
use serde::{de::DeserializeOwned, Serialize};
use sp_core::Pair;
use sp_runtime::traits::{AtLeast32Bit, AtLeast32BitUnsigned, MaybeSerializeDeserialize};
use sp_runtime::traits::{
AtLeast32Bit, AtLeast32BitUnsigned, Block, Hash as HashTrait, Header, MaybeSerializeDeserialize,
};

use crate::{extrinsic_params, Block, Hasher, Header, SignExtrinsic};
use crate::{extrinsic_params, SignExtrinsic};

pub use polkadot::*;
pub use substrate_kitchensink::*;
Expand Down Expand Up @@ -72,11 +74,11 @@ pub trait Config {
type Signature: Debug + Encode + From<<Self::CryptoKey as Pair>::Signature>;

/// The hashing system (algorithm) being used in the runtime (e.g. Blake2).
type Hasher: Debug + Hasher<Output = Self::Hash>;
type Hasher: Debug + HashTrait<Output = Self::Hash>;

/// The block header.
type Header: Debug
+ Header<Number = Self::BlockNumber, Hasher = Self::Hasher>
+ Header<Number = Self::BlockNumber, Hashing = Self::Hasher>
+ Send
+ DeserializeOwned;

Expand Down
9 changes: 6 additions & 3 deletions primitives/src/config/substrate_kitchensink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
//! https://github.com/paritytech/subxt/blob/ce0a82e3227efb0eae131f025da5f839d9623e15/subxt/src/config/substrate.rs

use crate::{
config::Config, types::AccountData, AssetTip, BlakeTwo256, ExtrinsicSigner,
GenericExtrinsicParams, SubstrateBlock, SubstrateHeader, SubstrateOpaqueExtrinsic,
config::Config, types::AccountData, AssetTip, ExtrinsicSigner, GenericExtrinsicParams,
};
use codec::{Decode, Encode};
use core::fmt::Debug;
pub use primitive_types::{H256, U256};
use sp_core::sr25519;
use sp_runtime::{AccountId32, MultiAddress, MultiSignature};
use sp_runtime::{
generic::{Block as SubstrateBlock, Header as SubstrateHeader},
traits::BlakeTwo256,
AccountId32, MultiAddress, MultiSignature, OpaqueExtrinsic as SubstrateOpaqueExtrinsic,
};

/// Default set of commonly used types by Substrate kitchensink runtime.
#[derive(Decode, Encode, Clone, Eq, PartialEq, Debug)]
Expand Down
4 changes: 0 additions & 4 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ extern crate alloc;
// Re-export everything.
pub use config::*;
pub use extrinsics::*;
pub use rpc_numbers::*;
pub use rpc_params::*;
pub use serde_impls::*;
pub use traits::*;
pub use types::*;

pub mod config;
pub mod extrinsics;
pub mod rpc_numbers;
pub mod rpc_params;
pub mod serde_impls;
pub mod traits;
pub mod types;
Loading