diff --git a/crates/pallet-token-claims/src/signed_ext.rs b/crates/pallet-token-claims/src/signed_ext.rs index 542959068..d5151600a 100644 --- a/crates/pallet-token-claims/src/signed_ext.rs +++ b/crates/pallet-token-claims/src/signed_ext.rs @@ -7,8 +7,9 @@ use frame_support::{ pallet_prelude::*, sp_runtime, traits::IsSubType, - unsigned::{TransactionValidity, TransactionValidityError}, + unsigned::TransactionValidity, }; +use primitives_ethereum::{EcdsaSignature, EthereumAddress}; use sp_runtime::traits::{DispatchInfoOf, SignedExtension}; use super::*; @@ -18,18 +19,11 @@ impl Pallet { /// Validate that the `claim` is correct and should be allowed for inclusion. /// /// Implement the flood protection logic. - fn validate_claim_call(who: &T::AccountId, call: &Call) -> TransactionValidity { - // Check if the call matches. - let (ethereum_address, ethereum_signature) = match call { - // Allow `claim` call. - Call::claim { - ethereum_address, - ethereum_signature, - } => (ethereum_address, ethereum_signature), - // Deny all unknown calls. - _ => return Err(TransactionValidityError::Invalid(InvalidTransaction::Call)), - }; - + fn validate_claim_call( + who: &T::AccountId, + ethereum_address: &EthereumAddress, + ethereum_signature: &EcdsaSignature, + ) -> TransactionValidity { // Check the signature. let message_params = EthereumSignatureMessageParams { account_id: who.clone(), @@ -40,14 +34,12 @@ impl Pallet { &message_params, ethereum_address, ) { - return Err(TransactionValidityError::Invalid( - InvalidTransaction::BadProof, - )); + return InvalidTransaction::BadProof.into(); } // Check the presence of a claim. if !>::contains_key(ethereum_address) { - return Err(TransactionValidityError::Invalid(InvalidTransaction::Call)); + return InvalidTransaction::Call.into(); } // All good, letting through. @@ -98,7 +90,23 @@ where _len: usize, ) -> TransactionValidity { match call.is_sub_type() { - Some(call) => Pallet::::validate_claim_call(who, call), + // Allow `claim` call. + Some(Call::claim { + ethereum_address, + ethereum_signature, + }) => Pallet::::validate_claim_call(who, ethereum_address, ethereum_signature), + _ => Ok(Default::default()), + } + } + + fn validate_unsigned( + call: &Self::Call, + _info: &DispatchInfoOf, + _len: usize, + ) -> TransactionValidity { + match call.is_sub_type() { + // Disallow `claim` call - can't be used as an unsigned tx. + Some(Call::claim { .. }) => InvalidTransaction::Call.into(), _ => Ok(Default::default()), } }