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

allow multi account conversion #1295

Merged
Merged
Changes from all 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
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
Loading