diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index 2e81bc7d9..99a357a44 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -35,26 +35,22 @@ use crate::utils::{ }; use frame_support::{ ensure, - traits::{Currency, Defensive, Get, IsSubType, VestingSchedule}, + traits::{Currency, Get, VestingSchedule}, weights::Weight, }; pub use pallet::*; use pallet_evm::AddressMapping; use parity_scale_codec::{Decode, Encode}; -use scale_info::{ - TypeInfo, -}; -use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; +use scale_info::TypeInfo; +use serde::{self, Deserialize, Serialize}; use sp_core::H160; use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256}; use sp_runtime::{ traits::{CheckedSub, SignedExtension, Zero}, - transaction_validity::{ - InvalidTransaction, TransactionValidity, ValidTransaction, - }, + transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction}, AccountId32, RuntimeDebug, }; -use sp_std::{convert::TryInto, fmt::Debug, prelude::*, vec}; +use sp_std::{convert::TryInto, prelude::*, vec}; use utils::Sr25519Signature; /// Custom validity errors used in Polkadot while validating transactions. #[repr(u8)] @@ -313,12 +309,13 @@ pub mod pallet { pub fn claim( origin: OriginFor, dest: Option, + signer: Option, signature: MultiAddressSignature, ) -> DispatchResult { ensure_none(origin)?; let data = dest.using_encoded(to_ascii_hex); - let signer = Self::get_signer_multi_address(dest.clone(), signature, data, vec![])?; + let signer = Self::get_signer_multi_address(signer.clone(), signature, data, vec![])?; ensure!(Signing::::get(&signer).is_none(), Error::::InvalidStatement); Self::process_claim(signer, dest)?; Ok(()) @@ -351,7 +348,6 @@ pub mod pallet { ensure_root(origin)?; >::mutate(|t| *t += value); - println!("mint_claim: who: {:?}, value: {:?}", who, value); >::insert(who.clone(), value); if let Some(vs) = vesting_schedule { >::insert(who.clone(), vs); @@ -394,15 +390,15 @@ pub mod pallet { pub fn claim_attest( origin: OriginFor, dest: Option, + signer: Option, signature: MultiAddressSignature, statement: Vec, ) -> DispatchResult { ensure_none(origin)?; let data = dest.using_encoded(to_ascii_hex); - println!("claim_attest: data: {:?}", data); - let signer = Self::get_signer_multi_address(dest.clone(), signature, data, statement.clone())?; - println!("claim_attest: signer: {:?}", signer); + let signer = + Self::get_signer_multi_address(signer.clone(), signature, data, statement.clone())?; if let Some(s) = Signing::::get(signer.clone()) { ensure!(s.to_text() == &statement[..], Error::::InvalidStatement); } @@ -451,29 +447,31 @@ pub mod pallet { // // The weight of this logic is included in the `claim` dispatchable. // - Call::claim { dest: account, signature } => { + Call::claim { dest: account, signer, signature } => { let data = account.using_encoded(to_ascii_hex); - match signature { - MultiAddressSignature::EVM(ethereum_signature) => - (Self::eth_recover(ðereum_signature, &data, &[][..]), None), - MultiAddressSignature::Native(sr25519_signature) => - (Self::sr25519_recover(&sr25519_signature, &data, &[][..]), None), + match Self::get_signer_multi_address( + signer.clone(), + signature.clone(), + data, + vec![], + ) { + Ok(signer) => (Some(signer), None), + Err(_) => (None, None), } }, // // The weight of this logic is included in the `claim_attest` dispatchable. // - Call::claim_attest { dest: account, signature, statement } => { + Call::claim_attest { dest: account, signer, signature, statement } => { let data = account.using_encoded(to_ascii_hex); - match signature { - MultiAddressSignature::EVM(ethereum_signature) => ( - Self::eth_recover(ðereum_signature, &data, &statement[..]), - Some(statement.as_slice()), - ), - MultiAddressSignature::Native(sr25519_signature) => ( - Self::sr25519_recover(&sr25519_signature, &data, &statement[..]), - Some(statement.as_slice()), - ), + match Self::get_signer_multi_address( + signer.clone(), + signature.clone(), + data, + statement.clone(), + ) { + Ok(signer) => (Some(signer), Some(statement.as_slice())), + Err(_) => (None, None), } }, _ => return Err(InvalidTransaction::Call.into()), @@ -542,10 +540,24 @@ impl Pallet { Some(MultiAddress::EVM(res)) } + // Constructs the message that PolkadotJS would sign. + fn polkadotjs_signable_message(what: &[u8], extra: &[u8]) -> Vec { + let prefix = T::Prefix::get(); + let mut v = prefix.to_vec(); + v.extend_from_slice(what); + v.extend_from_slice(extra); + v + } + // Attempts to recover the Substrate address from a message signature signed by using // the Substrate RPC's `sign`. - fn sr25519_recover(_s: &Sr25519Signature, what: &[u8], extra: &[u8]) -> Option { - let _msg = keccak_256(&Self::ethereum_signable_message(what, extra)); + fn sr25519_recover( + addr: MultiAddress, + s: &Sr25519Signature, + what: &[u8], + extra: &[u8], + ) -> Option { + let msg = keccak_256(&Self::polkadotjs_signable_message(what, extra)); let res = AccountId32::new([0; 32]); Some(MultiAddress::Native(res)) } @@ -558,12 +570,12 @@ impl Pallet { let balance_due = >::get(&signer).ok_or(Error::::SignerHasNoClaim)?; let new_total = Self::total().checked_sub(&balance_due).ok_or(Error::::PotUnderflow)?; - + // If there is a destination, then we need to transfer the balance to it. let recipient = match dest { Some(d) => d, None => signer.clone(), }; - + // Convert the destination recipient to an account ID. let recipient = Self::convert_multi_address_to_account_id(recipient)?; let vesting = Vesting::::get(&signer); @@ -594,7 +606,7 @@ impl Pallet { } fn get_signer_multi_address( - _dest: Option, + signer: Option, signature: MultiAddressSignature, data: Vec, statement: Vec, @@ -603,14 +615,17 @@ impl Pallet { MultiAddressSignature::EVM(ethereum_signature) => Self::eth_recover(ðereum_signature, &data, &statement[..]) .ok_or(Error::::InvalidEthereumSignature)?, - MultiAddressSignature::Native(sr25519_signature) => - Self::sr25519_recover(&sr25519_signature, &data, &statement[..]) - .ok_or(Error::::InvalidNativeSignature)?, + MultiAddressSignature::Native(sr25519_signature) => { + ensure!(signer.is_none(), Error::::InvalidNativeAccount); + Self::sr25519_recover(signer.unwrap(), &sr25519_signature, &data, &statement[..]) + .ok_or(Error::::InvalidNativeSignature)? + }, }; Ok(signer) } + /// Convert a MultiAddress to an AccountId fn convert_multi_address_to_account_id(dest: MultiAddress) -> Result> { let account = match dest { MultiAddress::EVM(a) => T::AddressMapping::into_account_id(H160::from(a)), @@ -652,3 +667,27 @@ mod secp_utils { MultiAddressSignature::EVM(EcdsaSignature(r)) } } + +#[cfg(any(test, feature = "runtime-benchmarks"))] +mod sr25519_utils { + use super::*; + use sp_core::{sr25519, Pair}; + + pub fn public(pair: &sr25519::Pair) -> sr25519::Public { + pair.public() + } + + pub fn sub(pair: &sr25519::Pair) -> MultiAddress { + MultiAddress::Native(pair.public().into()) + } + + pub fn sig( + pair: &sr25519::Pair, + what: &[u8], + extra: &[u8], + ) -> MultiAddressSignature { + let sig = pair + .sign(&>::polkadotjs_signable_message(&to_ascii_hex(what)[..], extra)); + MultiAddressSignature::Native(Sr25519Signature(sig)) + } +} diff --git a/pallets/claims/src/mock.rs b/pallets/claims/src/mock.rs index 27c25816d..faec7962e 100644 --- a/pallets/claims/src/mock.rs +++ b/pallets/claims/src/mock.rs @@ -1,11 +1,11 @@ use super::*; use pallet_evm::HashedAddressMapping; use secp_utils::*; -use sp_core::H256; +use sp_core::{sr25519, Pair, H256}; use sp_std::convert::TryFrom; // The testing primitives are very useful for avoiding having to work with signatures // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. -use crate::pallet as pallet_airdrop_claims; +use crate::{pallet as pallet_airdrop_claims, sr25519_utils::sub}; use frame_support::{ ord_parameter_types, parameter_types, traits::{OnFinalize, OnInitialize, WithdrawReasons}, @@ -140,6 +140,14 @@ pub fn get_multi_address_account_id(id: u8) -> MultiAddress { MultiAddress::Native(AccountId32::new([id; 32])) } +pub fn alice_sr25519() -> sr25519::Pair { + sr25519::Pair::from_string(&format!("//Alice"), None).expect("static values are valid; qed") +} + +pub fn bob_sr25519() -> sr25519::Pair { + sr25519::Pair::from_string(&format!("//Bob"), None).expect("static values are valid; qed") +} + // This function basically just builds a genesis storage key/value store according to // our desired mockup. pub fn new_test_ext() -> sp_io::TestExternalities { @@ -154,6 +162,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (eth(&dave()), 200, Some(StatementKind::Regular)), (eth(&eve()), 300, Some(StatementKind::Safe)), (eth(&frank()), 400, None), + (sub(&alice_sr25519()), 500, None), + (sub(&bob_sr25519()), 600, None), ], vesting: vec![(eth(&alice()), (50, 10, 1))], expiry: None, diff --git a/pallets/claims/src/tests.rs b/pallets/claims/src/tests.rs index f4410068b..7440bda3c 100644 --- a/pallets/claims/src/tests.rs +++ b/pallets/claims/src/tests.rs @@ -1,5 +1,5 @@ use super::*; -use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::DispatchError}; +use frame_support::pallet_prelude::DispatchError; use hex_literal::hex; use parity_scale_codec::Encode; use secp_utils::*; @@ -9,8 +9,7 @@ use sp_runtime::TokenError::Frozen; // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. use crate::{mock::new_test_ext, pallet::Call as ClaimsCall}; use frame_support::{ - assert_err, assert_noop, assert_ok, - dispatch::{DispatchError::BadOrigin, Pays}, + assert_err, assert_noop, assert_ok, dispatch::DispatchError::BadOrigin, traits::ExistenceRequirement, }; use sp_runtime::transaction_validity::TransactionLongevity; @@ -18,7 +17,7 @@ use sp_runtime::transaction_validity::TransactionLongevity; use crate::mock::*; fn total_claims() -> u64 { - 100 + 200 + 300 + 400 + 100 + 200 + 300 + 400 + 500 + 600 } #[test] @@ -44,8 +43,17 @@ fn eth_signature_works() { _ => panic!("should be evm signature"), }; - assert_eq!(ClaimsPallet::eth_recover(&sig, &to_ascii_hex(&data), &[][..]), Some(eth(&alice()))); - assert!(ClaimsPallet::eth_recover(&sig, &Some(get_multi_address_account_id(43)).encode(), &[][..]) != Some(eth(&alice()))); + assert_eq!( + ClaimsPallet::eth_recover(&sig, &to_ascii_hex(&data), &[][..]), + Some(eth(&alice())) + ); + assert!( + ClaimsPallet::eth_recover( + &sig, + &Some(get_multi_address_account_id(43)).encode(), + &[][..] + ) != Some(eth(&alice())) + ); }); } @@ -65,10 +73,17 @@ fn claiming_works() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 100); - assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), Some(50)); + assert_eq!( + Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), + 100 + ); + assert_eq!( + VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), + Some(50) + ); assert_eq!(ClaimsPallet::total(), total_claims() - 100); }); } @@ -94,6 +109,7 @@ fn basic_claim_moving_works() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::SignerHasNoClaim @@ -101,10 +117,17 @@ fn basic_claim_moving_works() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&bob(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 100); - assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), Some(50)); + assert_eq!( + Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), + 100 + ); + assert_eq!( + VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), + Some(50) + ); assert_eq!(ClaimsPallet::total(), total_claims() - 100); }); } @@ -125,10 +148,14 @@ fn claim_attest_moving_works() { assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s, StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 200); + assert_eq!( + Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), + 200 + ); }); } @@ -138,12 +165,14 @@ fn claiming_does_not_bypass_signing() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&dave(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::InvalidStatement, @@ -152,6 +181,7 @@ fn claiming_does_not_bypass_signing() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&eve(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::InvalidStatement, @@ -159,6 +189,7 @@ fn claiming_does_not_bypass_signing() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&frank(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); }); @@ -169,14 +200,11 @@ fn attest_claiming_works() { new_test_ext().execute_with(|| { assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); let data = Some(get_multi_address_account_id(42)).encode(); - let s = sig::( - &dave(), - &data, - StatementKind::Safe.to_text(), - ); + let s = sig::(&dave(), &data, StatementKind::Safe.to_text()); let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s.clone(), StatementKind::Safe.to_text().to_vec(), ); @@ -185,6 +213,7 @@ fn attest_claiming_works() { let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s, StatementKind::Regular.to_text().to_vec(), ); @@ -200,10 +229,14 @@ fn attest_claiming_works() { assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s, StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 200); + assert_eq!( + Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), + 200 + ); assert_eq!(ClaimsPallet::total(), total_claims() - 200); let s = sig::( @@ -214,6 +247,7 @@ fn attest_claiming_works() { let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s, StatementKind::Regular.to_text().to_vec(), ); @@ -229,6 +263,7 @@ fn cannot_bypass_attest_claiming() { let r = ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s.clone(), ); assert_noop!(r, Error::::InvalidStatement); @@ -253,6 +288,7 @@ fn add_claim_works() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim, @@ -262,10 +298,17 @@ fn add_claim_works() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); - assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), None); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), + 200 + ); + assert_eq!( + VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), + None + ); assert_eq!(ClaimsPallet::total(), total_claims()); }); } @@ -288,6 +331,7 @@ fn add_claim_with_vesting_works() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim, @@ -302,10 +346,17 @@ fn add_claim_with_vesting_works() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); - assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), Some(50)); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), + 200 + ); + assert_eq!( + VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), + Some(50) + ); // Make sure we can not transfer the vested balance. assert_err!( @@ -344,6 +395,7 @@ fn add_claim_with_statement_works() { ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, signature.clone(), StatementKind::Regular.to_text().to_vec() ), @@ -360,6 +412,7 @@ fn add_claim_with_statement_works() { ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, signature.clone(), vec![], ), @@ -368,10 +421,14 @@ fn add_claim_with_statement_works() { assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, signature.clone(), StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), + 200 + ); }); } @@ -383,6 +440,7 @@ fn origin_signed_claiming_fail() { ClaimsPallet::claim( RuntimeOrigin::signed(get_multi_address_account_id(42).to_account_id_32()), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), sp_runtime::traits::BadOrigin, @@ -397,12 +455,14 @@ fn double_claiming_doesnt_work() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::SignerHasNoClaim @@ -413,8 +473,14 @@ fn double_claiming_doesnt_work() { #[test] fn claiming_while_vested_doesnt_work() { new_test_ext().execute_with(|| { - CurrencyOf::::make_free_balance_be(&get_multi_address_account_id(69).to_account_id_32(), total_claims()); - assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), total_claims()); + CurrencyOf::::make_free_balance_be( + &get_multi_address_account_id(69).to_account_id_32(), + total_claims(), + ); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), + total_claims() + ); // A user is already vested assert_ok!(::VestingSchedule::add_vesting_schedule( &get_multi_address_account_id(69).to_account_id_32(), @@ -437,6 +503,7 @@ fn claiming_while_vested_doesnt_work() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::VestedBalanceExists, @@ -452,6 +519,7 @@ fn non_sender_sig_doesnt_work() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim @@ -467,6 +535,7 @@ fn non_claimant_doesnt_work() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim @@ -497,6 +566,7 @@ fn validate_unsigned_works() { source, &ClaimsCall::claim { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: sig::( &alice(), &Some(get_multi_address_account_id(1)).encode(), @@ -517,6 +587,7 @@ fn validate_unsigned_works() { source, &ClaimsCall::claim { dest: Some(get_multi_address_account_id(0)), + signer: None, signature: MultiAddressSignature::EVM(EcdsaSignature([0; 65])) } ), @@ -527,6 +598,7 @@ fn validate_unsigned_works() { source, &ClaimsCall::claim { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: sig::( &bob(), &Some(get_multi_address_account_id(1)).encode(), @@ -543,6 +615,7 @@ fn validate_unsigned_works() { ); let call = ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; @@ -561,6 +634,7 @@ fn validate_unsigned_works() { source, &ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: MultiAddressSignature::EVM(EcdsaSignature([0; 65])), statement: StatementKind::Regular.to_text().to_vec() } @@ -575,6 +649,7 @@ fn validate_unsigned_works() { ); let call = ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; @@ -590,6 +665,7 @@ fn validate_unsigned_works() { ); let call = ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; @@ -605,6 +681,7 @@ fn validate_unsigned_works() { ); let call = ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: s, statement: StatementKind::Safe.to_text().to_vec(), }; @@ -623,6 +700,7 @@ fn test_unclaimed_returned_to_destination() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_eq!(Total::::get(), original_total_claims - claim_of_alice); @@ -649,6 +727,7 @@ fn test_unclaimed_returned_to_destination() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&frank(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::PotUnderflow diff --git a/pallets/claims/src/utils/mod.rs b/pallets/claims/src/utils/mod.rs index 637db603e..b781302a9 100644 --- a/pallets/claims/src/utils/mod.rs +++ b/pallets/claims/src/utils/mod.rs @@ -6,7 +6,7 @@ use scale_info::{ }; #[cfg(feature = "std")] use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; -use sp_core::{H160}; +use sp_core::{sr25519::Signature, H160}; use sp_runtime::{traits::BlakeTwo256, AccountId32, RuntimeDebug}; use sp_std::prelude::*; @@ -39,23 +39,11 @@ impl MultiAddress { } } -#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub enum MultiAddressSignature { EVM(EcdsaSignature), Native(Sr25519Signature), } -#[derive(Clone, Copy, Eq, Encode, Decode, TypeInfo)] -pub struct Sr25519Signature(pub [u8; 65]); - -impl PartialEq for Sr25519Signature { - fn eq(&self, other: &Self) -> bool { - &self.0[..] == &other.0[..] - } -} - -impl sp_std::fmt::Debug for Sr25519Signature { - fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { - write!(f, "Sr25519Signature({:?})", &self.0[..]) - } -} +#[derive(Clone, Eq, Encode, PartialEq, Decode, TypeInfo, RuntimeDebug)] +pub struct Sr25519Signature(pub Signature);