From 3b871456f7a23b17fc01b2d17d895a0bdf60b725 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 27 Jun 2023 00:56:39 +0800 Subject: [PATCH] Improve `EthereumSigner` (#1057) * Improve `EthereumSigner` * Add `RuntimeDebug` * Typo * Update primitives/account/src/lib.rs --------- Co-authored-by: Wei Tang --- Cargo.lock | 1 + Cargo.toml | 1 + primitives/account/Cargo.toml | 2 ++ primitives/account/src/lib.rs | 19 +++++++++++++++++-- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb893341fd..c204965bef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2428,6 +2428,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", + "sp-runtime-interface", "sp-std", ] diff --git a/Cargo.toml b/Cargo.toml index db5a09fd8c..b534664352 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,6 +94,7 @@ sp-io = { version = "7.0.0", git = "https://github.com/paritytech/substrate", br sp-keyring = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master" } sp-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-runtime-interface = { version = "7.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-session = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-state-machine = { version = "0.13.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { version = "5.0.0", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/primitives/account/Cargo.toml b/primitives/account/Cargo.toml index a56506cca1..0a6f7a0f9c 100644 --- a/primitives/account/Cargo.toml +++ b/primitives/account/Cargo.toml @@ -20,6 +20,7 @@ serde = { workspace = true, optional = true } sp-core = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } +sp-runtime-interface = { workspace = true } sp-std = { workspace = true } [dev-dependencies] @@ -38,5 +39,6 @@ std = [ "sp-core/std", "sp-io/std", "sp-runtime/std", + "sp-runtime-interface/std", "sp-std/std", ] diff --git a/primitives/account/src/lib.rs b/primitives/account/src/lib.rs index acbf9a6b82..088951a699 100644 --- a/primitives/account/src/lib.rs +++ b/primitives/account/src/lib.rs @@ -20,8 +20,9 @@ use scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; // Substrate -use sp_core::{ecdsa, H160, H256}; +use sp_core::{ecdsa, RuntimeDebug, H160, H256}; use sp_io::hashing::keccak_256; +use sp_runtime_interface::pass_by::PassByInner; /// A fully Ethereum-compatible `AccountId`. /// Conforms to H160 address and ECDSA key standards. @@ -114,7 +115,7 @@ impl From for AccountId20 { } #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -#[derive(Eq, PartialEq, Clone, Encode, Decode, sp_core::RuntimeDebug, TypeInfo)] +#[derive(Eq, PartialEq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct EthereumSignature(ecdsa::Signature); impl sp_runtime::traits::Verify for EthereumSignature { @@ -145,6 +146,20 @@ impl EthereumSignature { } } +#[derive( + PartialEq, + Eq, + PartialOrd, + Ord, + Clone, + Copy, + Encode, + Decode, + PassByInner, + MaxEncodedLen, + RuntimeDebug, + TypeInfo +)] pub struct EthereumSigner([u8; 20]); impl From<[u8; 20]> for EthereumSigner {