Skip to content

Commit

Permalink
allow multi account conversion (polkadot-evm#1295)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moliholy committed Feb 7, 2024
1 parent 272fe88 commit 7c7cfce
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions primitives/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
use scale_codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
// Substrate
use sp_core::{ecdsa, RuntimeDebug, H160, H256};
use sp_core::{crypto::AccountId32, ecdsa, RuntimeDebug, H160, H256};
use sp_io::hashing::keccak_256;
use sp_runtime::MultiSignature;
use sp_runtime_interface::pass_by::PassByInner;

/// A fully Ethereum-compatible `AccountId`.
Expand Down Expand Up @@ -159,6 +160,13 @@ impl From<[u8; 32]> for AccountId20 {
}
}

impl From<AccountId32> for AccountId20 {
fn from(account: AccountId32) -> Self {
let bytes: &[u8; 32] = account.as_ref();
Self::from(*bytes)
}
}

#[derive(Eq, PartialEq, Clone, RuntimeDebug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EthereumSignature(ecdsa::Signature);
Expand All @@ -185,9 +193,23 @@ impl sp_runtime::traits::Verify for EthereumSignature {
}
}

impl From<MultiSignature> for EthereumSignature {
fn from(signature: MultiSignature) -> Self {
match signature {
MultiSignature::Ed25519(_) => {
panic!("Ed25519 not supported for EthereumSignature")
}
MultiSignature::Sr25519(_) => {
panic!("Sr25519 not supported for EthereumSignature")
}
MultiSignature::Ecdsa(sig) => Self(sig),
}
}
}

impl EthereumSignature {
pub fn new(s: ecdsa::Signature) -> Self {
EthereumSignature(s)
Self(s)
}
}

Expand Down

0 comments on commit 7c7cfce

Please sign in to comment.