remove substrate compat (#1850)

* remove substrate compat

* add hacky example

* simplify substrate-compat example

* simplify substrate-compat example

* cargo fmt

* fix build

* add more examples

* fix nit

* fix test build

* Update subxt/examples/substrate_compat_signer.rs

Co-authored-by: James Wilson <james@jsdw.me>

* keep only polkadot signer example

* remove more substrate compat related stuff

* fix example

* link to substrate signer example in book

* Update subxt/src/book/usage/transactions.rs

* Update subxt/src/book/usage/transactions.rs

* address grumbles

* fix nits

---------

Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
Niklas Adolfsson
2024-11-27 16:46:38 +01:00
committed by GitHub
parent 09ab839ff2
commit f5e9ce0d2c
18 changed files with 143 additions and 305 deletions
-28
View File
@@ -160,35 +160,9 @@ impl core::str::FromStr for AccountId32 {
}
}
// Improve compat with the substrate version if we're using those crates:
#[cfg(feature = "substrate-compat")]
mod substrate_impls {
use super::*;
use polkadot_sdk::{sp_core, sp_runtime};
impl From<sp_runtime::AccountId32> for AccountId32 {
fn from(value: sp_runtime::AccountId32) -> Self {
Self(value.into())
}
}
impl From<sp_core::sr25519::Public> for AccountId32 {
fn from(value: sp_core::sr25519::Public) -> Self {
let acc: sp_runtime::AccountId32 = value.into();
acc.into()
}
}
impl From<sp_core::ed25519::Public> for AccountId32 {
fn from(value: sp_core::ed25519::Public) -> Self {
let acc: sp_runtime::AccountId32 = value.into();
acc.into()
}
}
}
#[cfg(test)]
mod test {
use super::*;
use polkadot_sdk::sp_core::{self, crypto::Ss58Codec};
use polkadot_sdk::sp_keyring::AccountKeyring;
@@ -202,8 +176,6 @@ mod test {
for keyring in keyrings {
let substrate_account = keyring.to_account_id();
// Avoid "From" impl hidden behind "substrate-compat" feature so that this test
// can work either way:
let local_account = AccountId32(substrate_account.clone().into());
// Both should encode to ss58 the same way:
+1 -31
View File
@@ -10,8 +10,7 @@ use alloc::vec::Vec;
use codec::{Decode, Encode};
/// A multi-format address wrapper for on-chain accounts. This is a simplified version of Substrate's
/// `sp_runtime::MultiAddress`. To obtain more functionality, convert this into that type (this conversion
/// functionality is provided via `From` impls if the `substrate-compat` feature is enabled).
/// `sp_runtime::MultiAddress`.
#[derive(
Clone,
Eq,
@@ -43,32 +42,3 @@ impl<AccountId, AccountIndex> From<AccountId> for MultiAddress<AccountId, Accoun
Self::Id(a)
}
}
// Improve compat with the substrate version if we're using those crates:
#[cfg(feature = "substrate-compat")]
mod substrate_impls {
use super::{super::AccountId32, *};
use polkadot_sdk::sp_runtime;
impl<N> From<sp_runtime::AccountId32> for MultiAddress<AccountId32, N> {
fn from(value: sp_runtime::AccountId32) -> Self {
let val: AccountId32 = value.into();
val.into()
}
}
impl<Id, N> From<sp_runtime::MultiAddress<Id, N>> for MultiAddress<AccountId32, N>
where
Id: Into<AccountId32>,
{
fn from(value: sp_runtime::MultiAddress<Id, N>) -> Self {
match value {
sp_runtime::MultiAddress::Id(v) => Self::Id(v.into()),
sp_runtime::MultiAddress::Index(v) => Self::Index(v),
sp_runtime::MultiAddress::Raw(v) => Self::Raw(v),
sp_runtime::MultiAddress::Address32(v) => Self::Address32(v),
sp_runtime::MultiAddress::Address20(v) => Self::Address20(v),
}
}
}
}
-38
View File
@@ -19,41 +19,3 @@ pub enum MultiSignature {
/// An ECDSA/SECP256k1 signature (a 512-bit value, plus 8 bits for recovery ID).
Ecdsa([u8; 65]),
}
// Improve compat with the substrate version if we're using those crates:
#[cfg(feature = "substrate-compat")]
mod substrate_impls {
use super::*;
use polkadot_sdk::{sp_core, sp_runtime};
impl From<sp_runtime::MultiSignature> for MultiSignature {
fn from(value: sp_runtime::MultiSignature) -> Self {
match value {
sp_runtime::MultiSignature::Ed25519(s) => Self::Ed25519(s.0),
sp_runtime::MultiSignature::Sr25519(s) => Self::Sr25519(s.0),
sp_runtime::MultiSignature::Ecdsa(s) => Self::Ecdsa(s.0),
}
}
}
impl From<sp_core::ed25519::Signature> for MultiSignature {
fn from(value: sp_core::ed25519::Signature) -> Self {
let sig: sp_runtime::MultiSignature = value.into();
sig.into()
}
}
impl From<sp_core::sr25519::Signature> for MultiSignature {
fn from(value: sp_core::sr25519::Signature) -> Self {
let sig: sp_runtime::MultiSignature = value.into();
sig.into()
}
}
impl From<sp_core::ecdsa::Signature> for MultiSignature {
fn from(value: sp_core::ecdsa::Signature) -> Self {
let sig: sp_runtime::MultiSignature = value.into();
sig.into()
}
}
}