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

Add From implementation to ExtrinsicSigner #459

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pallet-staking = { optional = true, git = "https://github.com/paritytech/substra

[dev-dependencies]
node-template-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
kitchensink-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
masapr marked this conversation as resolved.
Show resolved Hide resolved

[features]
default = ["std"]
Expand Down
34 changes: 34 additions & 0 deletions primitives/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,37 @@ where
self.extrinsic_address.clone()
}
}

impl<Signer, Runtime> From<Signer> for ExtrinsicSigner<Signer, Signer::Signature, Runtime>
where
Signer: Pair,
Runtime: FrameSystemConfig,
Runtime::AccountId: From<Signer::Public>,
{
fn from(value: Signer) -> Self {
ExtrinsicSigner::<Signer, Signer::Signature, Runtime>::new(value)
}
}

#[cfg(test)]
mod tests {
use crate::ExtrinsicSigner;
use kitchensink_runtime::Runtime;
use sp_core::{sr25519, Pair};

#[test]
fn test_extrinsic_signer_from_sr25519_pair() {
let alice: sr25519::Pair = Pair::from_string(
"0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a",
None,
)
.unwrap();

let es_converted: ExtrinsicSigner<sr25519::Pair, sr25519::Signature, Runtime> =
masapr marked this conversation as resolved.
Show resolved Hide resolved
alice.clone().into();
let es_new =
ExtrinsicSigner::<sr25519::Pair, sr25519::Signature, Runtime>::new(alice.clone());

assert_eq!(es_converted.signer.public(), es_new.signer.public());
}
}