mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Substrate.from() (#426)
* Substrate.from() * Fix some transaction validation code * must be more specific for matching now. * Update `wasm-builder` and add `build-only-wasm` script * Update to latest service builder interfaces * ANother substrate update * Another update
This commit is contained in:
@@ -29,8 +29,11 @@ use sr_primitives::traits::Zero;
|
||||
use sr_primitives::{
|
||||
weights::SimpleDispatchInfo,
|
||||
traits::ValidateUnsigned,
|
||||
transaction_validity::{TransactionLongevity, TransactionValidity, ValidTransaction},
|
||||
transaction_validity::{
|
||||
TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction
|
||||
},
|
||||
};
|
||||
use primitives::ValidityError;
|
||||
use system;
|
||||
|
||||
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
|
||||
@@ -194,11 +197,6 @@ impl<T: Trait> ValidateUnsigned for Module<T> {
|
||||
type Call = Call<T>;
|
||||
|
||||
fn validate_unsigned(call: &Self::Call) -> TransactionValidity {
|
||||
// Note errors > 0 are from ApplyError
|
||||
const INVALID_ETHEREUM_SIGNATURE: i8 = -10;
|
||||
const SIGNER_HAS_NO_CLAIM: i8 = -20;
|
||||
const INVALID_CALL: i8 = -30;
|
||||
|
||||
const PRIORITY: u64 = 100;
|
||||
|
||||
match call {
|
||||
@@ -208,14 +206,18 @@ impl<T: Trait> ValidateUnsigned for Module<T> {
|
||||
let signer = if let Some(s) = maybe_signer {
|
||||
s
|
||||
} else {
|
||||
return TransactionValidity::Invalid(INVALID_ETHEREUM_SIGNATURE);
|
||||
return InvalidTransaction::Custom(
|
||||
ValidityError::InvalidEthereumSignature.into(),
|
||||
).into();
|
||||
};
|
||||
|
||||
if !<Claims<T>>::exists(&signer) {
|
||||
return TransactionValidity::Invalid(SIGNER_HAS_NO_CLAIM);
|
||||
return Err(InvalidTransaction::Custom(
|
||||
ValidityError::SignerHasNoClaim.into(),
|
||||
).into());
|
||||
}
|
||||
|
||||
TransactionValidity::Valid(ValidTransaction {
|
||||
Ok(ValidTransaction {
|
||||
priority: PRIORITY,
|
||||
requires: vec![],
|
||||
provides: vec![("claims", signer).encode()],
|
||||
@@ -223,7 +225,7 @@ impl<T: Trait> ValidateUnsigned for Module<T> {
|
||||
propagate: true,
|
||||
})
|
||||
}
|
||||
_ => TransactionValidity::Invalid(INVALID_CALL)
|
||||
_ => Err(InvalidTransaction::Call.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -387,8 +389,10 @@ mod tests {
|
||||
fn origin_signed_claiming_fail() {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
assert_eq!(Balances::free_balance(&42), 0);
|
||||
assert_err!(Claims::claim(Origin::signed(42), 42, alice_sig(&42u64.encode())),
|
||||
"bad origin: expected to be no origin");
|
||||
assert_err!(
|
||||
Claims::claim(Origin::signed(42), 42, alice_sig(&42u64.encode())),
|
||||
"RequireNoOrigin",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -434,7 +438,7 @@ mod tests {
|
||||
with_externalities(&mut new_test_ext(), || {
|
||||
assert_eq!(
|
||||
<Module<Test>>::validate_unsigned(&Call::claim(1, alice_sig(&1u64.encode()))),
|
||||
TransactionValidity::Valid(ValidTransaction {
|
||||
Ok(ValidTransaction {
|
||||
priority: 100,
|
||||
requires: vec![],
|
||||
provides: vec![("claims", alice_eth()).encode()],
|
||||
@@ -444,15 +448,15 @@ mod tests {
|
||||
);
|
||||
assert_eq!(
|
||||
<Module<Test>>::validate_unsigned(&Call::claim(0, EcdsaSignature([0; 65]))),
|
||||
TransactionValidity::Invalid(-10)
|
||||
InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(),
|
||||
);
|
||||
assert_eq!(
|
||||
<Module<Test>>::validate_unsigned(&Call::claim(1, bob_sig(&1u64.encode()))),
|
||||
TransactionValidity::Invalid(-20)
|
||||
InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(),
|
||||
);
|
||||
assert_eq!(
|
||||
<Module<Test>>::validate_unsigned(&Call::claim(0, bob_sig(&1u64.encode()))),
|
||||
TransactionValidity::Invalid(-20)
|
||||
InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user