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
Changes from 1 commit
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
74 changes: 2 additions & 72 deletions subxt/src/book/usage/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@
//! There are two main ways to create a compatible signer instance:
//! 1. The `subxt_signer` crate provides a WASM compatible implementation of [`crate::tx::Signer`]
//! for chains which require sr25519 or ecdsa signatures (requires the `subxt` feature to be enabled).
//! 2. Alternately, Subxt can use instances of Substrate's `sp_core::Pair` to sign things by wrapping
//! them in a new type pattern and implement `crate::tx::Signer`.
//! 2. Alternately, implement your own [`crate::tx::Signer`] instance using the `polkadot-sdk` signer.
//!
//! Going for 1 leads to fewer dependencies being imported and WASM compatibility out of the box via
//! the `web` feature flag. Going for 2 is useful if you're already using the Substrate dependencies or
Expand All @@ -94,76 +93,7 @@
//! let keypair = sr25519::Keypair::from_uri(&uri)
//! .expect("valid keypair");
//!
//! //// 2. Use the corresponding `sp_core::Pair` impl:
//!
//! use polkadot_sdk::sp_runtime::{
//! traits::{IdentifyAccount, Verify},
//! MultiSignature as SpMultiSignature,
//! };
//! use sp_core::Pair;
//! use subxt::config::substrate::{AccountId32, MultiSignature};
//! use subxt::Config;
//!
//! #[derive(Clone)]
//! pub struct PairSigner {
//! account_id: <PolkadotConfig as Config>::AccountId,
//! signer: sp_core::sr25519::Pair,
//! }
//!
//! impl PairSigner {
//! pub fn new(signer: sp_core::sr25519::Pair) -> Self {
//! let account_id =
//! <SpMultiSignature as Verify>::Signer::from(signer.public()).into_account();
//! Self {
//! account_id: AccountId32(account_id.into()),
//! signer,
//! }
//! }
//!
//! /// Return the account ID.
//! pub fn account_id(&self) -> &AccountId32 {
//! &self.account_id
//! }
//! }
//!
//! impl subxt::tx::Signer<PolkadotConfig> for PairSigner {
//! fn account_id(&self) -> <PolkadotConfig as Config>::AccountId {
//! self.account_id.clone()
//! }
//!
//! fn address(&self) -> <PolkadotConfig as Config>::Address {
//! self.account_id.clone().into()
//! }
//!
//! fn sign(&self, signer_payload: &[u8]) -> <PolkadotConfig as Config>::Signature {
//! let signature = self.signer.sign(signer_payload);
//! MultiSignature::Sr25519(signature.0)
//! }
//! }
//!
//! // Get hold of a `Signer` for a test account:
//! let alice = sp_keyring::AccountKeyring::Alice.pair();
//! let alice = PairSigner::new(alice);
//!
//! // Or generate a keypair, here from an SURI:
//! let keypair = sp_core::sr25519::Pair::from_string("vessel ladder alter error federal sibling chat ability sun glass valve picture/0/1///Password", None)
//! .expect("valid URI");
//! let keypair = PairSigner::new(keypair);
//! #
//! # // Test that these all impl Signer trait while we're here:
//! #
//! # fn is_subxt_signer(_signer: impl subxt::tx::Signer<PolkadotConfig>) {}
//! # is_subxt_signer(subxt_signer::sr25519::dev::alice());
//! # is_subxt_signer(subxt_signer::ecdsa::dev::alice());
//! # is_subxt_signer(PairSigner::new(sp_keyring::AccountKeyring::Alice.pair()));
//! # }
//! ```
//!
//! See the `subxt_signer` crate or the `sp_core::Pair` docs for more ways to construct
//! and work with key pairs.
//!
//! If this isn't suitable/available, you can either implement [`crate::tx::Signer`] yourself to use
//! custom signing logic, or you can use some external signing logic, like so:
//! //// 2. See `subxt/examples/substrate_compat_signer.rs` how to use the polkadot-sdk signer with Subxt.
Copy link
Collaborator

@jsdw jsdw Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe have this below the code block instead, something like:

"See <...> for an example on of intagratating polkadot-sdk's signer in to Subxt."

//!
//! ```rust,no_run
//! # #[tokio::main]
Expand Down
Loading