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

remove substrate compat #1850

Merged
merged 20 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
63 changes: 25 additions & 38 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ std = [
"impl-serde/std",
"primitive-types/std",
]
substrate-compat = ["polkadot-sdk/sp-core", "polkadot-sdk/sp-runtime", "polkadot-sdk/std"]

[dependencies]
codec = { package = "parity-scale-codec", workspace = true, default-features = false, features = ["derive"] }
Expand All @@ -48,6 +47,7 @@ derive-where = { workspace = true }
hex = { workspace = true, default-features = false, features = ["alloc"] }
serde = { workspace = true, default-features = false, features = ["derive"] }
serde_json = { workspace = true, default-features = false, features = ["raw_value", "alloc"] }
polkadot-sdk = { workspace = true, features = ["sp-crypto-hashing"] }
hashbrown = { workspace = true }

# For ss58 encoding AccountId32 to serialize them properly:
Expand All @@ -57,7 +57,6 @@ blake2 = { workspace = true }
# Provides some deserialization, types like U256/H256 and hashing impls like twox/blake256:
impl-serde = { workspace = true, default-features = false }
primitive-types = { workspace = true, default-features = false, features = ["codec", "serde_no_std", "scale-info"] }
polkadot-sdk = { workspace = true, features = ["sp-crypto-hashing"] }

# Included if the "substrate-compat" feature is enabled.
tracing = { workspace = true, default-features = false }
Expand Down
29 changes: 0 additions & 29 deletions core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod polkadot;
pub mod signed_extensions;
pub mod substrate;

use crate::macros::cfg_substrate_compat;
use codec::{Decode, Encode};
use core::fmt::Debug;
use scale_decode::DecodeAsType;
Expand Down Expand Up @@ -127,31 +126,3 @@ pub trait Header: Sized + Encode + Decode {
Self::Hasher::hash_of(self)
}
}

cfg_substrate_compat! {
/// implement subxt's Hasher and Header traits for some substrate structs
mod substrate_impls {
use super::*;
use polkadot_sdk::sp_runtime;

impl<T: sp_runtime::traits::Header> Header for T
where
<T as sp_runtime::traits::Header>::Number: Into<u64>,
{
type Number = T::Number;
type Hasher = T::Hashing;

fn number(&self) -> Self::Number {
*self.number()
}
}

impl<T: sp_runtime::traits::Hash> Hasher for T {
type Output = T::Output;

fn hash(s: &[u8]) -> Self::Output {
<T as sp_runtime::traits::Hash>::hash(s)
}
}
}
}
5 changes: 0 additions & 5 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,4 @@ pub mod ext {
pub use scale_decode;
pub use scale_encode;
pub use scale_value;

cfg_substrate_compat! {
pub use polkadot_sdk::sp_runtime;
pub use polkadot_sdk::sp_core;
}
}
18 changes: 0 additions & 18 deletions core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,6 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.

macro_rules! cfg_feature {
($feature:literal, $($item:item)*) => {
$(
#[cfg(feature = $feature)]
#[cfg_attr(docsrs, doc(cfg(feature = $feature)))]
$item
)*
}
}

macro_rules! cfg_substrate_compat {
($($item:item)*) => {
crate::macros::cfg_feature!("substrate-compat", $($item)*);
};
}

macro_rules! impl_from {
($module_path:path => $delegate_ty:ident :: $variant:ident) => {
impl From<$module_path> for $delegate_ty {
Expand All @@ -27,5 +11,3 @@ macro_rules! impl_from {
}
};
}

pub(crate) use {cfg_feature, cfg_substrate_compat};
75 changes: 0 additions & 75 deletions core/src/tx/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! A library to **sub**mit e**xt**rinsics to a
//! [substrate](https://github.com/paritytech/substrate) node via RPC.

use crate::macros::cfg_substrate_compat;
use crate::Config;

/// Signing transactions requires a [`Signer`]. This is responsible for
Expand All @@ -24,77 +23,3 @@ pub trait Signer<T: Config> {
/// refused the operation.
fn sign(&self, signer_payload: &[u8]) -> T::Signature;
}

cfg_substrate_compat! {
pub use pair_signer::PairSigner;
}

// A signer suitable for substrate based chains. This provides compatibility with Substrate
// packages like sp_keyring and such, and so relies on sp_core and sp_runtime to be included.
#[cfg(feature = "substrate-compat")]
mod pair_signer {
use super::Signer;
use crate::Config;
use polkadot_sdk::sp_core::Pair as PairT;
use polkadot_sdk::sp_runtime::{
traits::{IdentifyAccount, Verify},
AccountId32 as SpAccountId32, MultiSignature as SpMultiSignature,
};

/// A [`Signer`] implementation that can be constructed from an [`sp_core::Pair`].
#[derive(Clone, Debug)]
pub struct PairSigner<T: Config, Pair> {
account_id: T::AccountId,
signer: Pair,
}

impl<T, Pair> PairSigner<T, Pair>
where
T: Config,
Pair: PairT,
// We go via an `sp_runtime::MultiSignature`. We can probably generalise this
// by implementing some of these traits on our built-in MultiSignature and then
// requiring them on all T::Signatures, to avoid any go-between.
<SpMultiSignature as Verify>::Signer: From<Pair::Public>,
T::AccountId: From<SpAccountId32>,
{
/// Creates a new [`Signer`] from an [`sp_core::Pair`].
pub fn new(signer: Pair) -> Self {
let account_id =
<SpMultiSignature as Verify>::Signer::from(signer.public()).into_account();
Self {
account_id: account_id.into(),
signer,
}
}

/// Returns the [`sp_core::Pair`] implementation used to construct this.
pub fn signer(&self) -> &Pair {
&self.signer
}

/// Return the account ID.
pub fn account_id(&self) -> &T::AccountId {
&self.account_id
}
}

impl<T, Pair> Signer<T> for PairSigner<T, Pair>
where
T: Config,
Pair: PairT,
Pair::Signature: Into<T::Signature>,
{
fn account_id(&self) -> T::AccountId {
self.account_id.clone()
}

fn address(&self) -> T::Address {
self.account_id.clone().into()
}

fn sign(&self, signer_payload: &[u8]) -> T::Signature {
self.signer.sign(signer_payload).into()
}
}
}
Loading
Loading