mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 18:41: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(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,16 +31,17 @@ use codec::{Encode, Decode};
|
||||
use substrate_primitives::u32_trait::{_1, _2, _3, _4};
|
||||
use primitives::{
|
||||
AccountId, AccountIndex, Balance, BlockNumber, Hash, Nonce, Signature, Moment,
|
||||
parachain,
|
||||
parachain, ValidityError,
|
||||
};
|
||||
use client::{
|
||||
block_builder::api::{self as block_builder_api, InherentData, CheckInherentsResult},
|
||||
runtime_api as client_api, impl_runtime_apis,
|
||||
};
|
||||
use sr_primitives::{
|
||||
ApplyResult, generic, transaction_validity::{ValidTransaction, TransactionValidity},
|
||||
ApplyResult, generic,
|
||||
transaction_validity::{TransactionValidity, InvalidTransaction, TransactionValidityError},
|
||||
impl_opaque_keys, weights::{Weight, DispatchInfo}, create_runtime_str, key_types, traits::{
|
||||
BlakeTwo256, Block as BlockT, DigestFor, StaticLookup, DispatchError, SignedExtension,
|
||||
BlakeTwo256, Block as BlockT, DigestFor, StaticLookup, SignedExtension,
|
||||
},
|
||||
};
|
||||
use version::RuntimeVersion;
|
||||
@@ -55,6 +56,7 @@ use srml_support::{
|
||||
parameter_types, construct_runtime, traits::{SplitTwoWays, Currency}
|
||||
};
|
||||
use im_online::sr25519::{AuthorityId as ImOnlineId};
|
||||
use system::offchain::TransactionSubmitter;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub use staking::StakerStatus;
|
||||
@@ -98,7 +100,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
spec_name: create_runtime_str!("kusama"),
|
||||
impl_name: create_runtime_str!("parity-kusama"),
|
||||
authoring_version: 1,
|
||||
spec_version: 1002,
|
||||
spec_version: 1003,
|
||||
impl_version: 0,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
@@ -124,14 +126,14 @@ impl SignedExtension for OnlyStakingAndClaims {
|
||||
type Call = Call;
|
||||
type AdditionalSigned = ();
|
||||
type Pre = ();
|
||||
fn additional_signed(&self) -> rstd::result::Result<(), &'static str> { Ok(()) }
|
||||
fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) }
|
||||
fn validate(&self, _: &Self::AccountId, call: &Self::Call, _: DispatchInfo, _: usize)
|
||||
-> Result<ValidTransaction, DispatchError>
|
||||
-> TransactionValidity
|
||||
{
|
||||
match call {
|
||||
Call::Staking(_) | Call::Claims(_) | Call::Sudo(_) | Call::Session(_) =>
|
||||
Ok(Default::default()),
|
||||
_ => Err(DispatchError::NoPermission),
|
||||
_ => Err(InvalidTransaction::Custom(ValidityError::NoPermission.into()).into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,11 +415,13 @@ impl offences::Trait for Runtime {
|
||||
type OnOffenceHandler = Staking;
|
||||
}
|
||||
|
||||
type SubmitTransaction = TransactionSubmitter<ImOnlineId, Runtime, UncheckedExtrinsic>;
|
||||
|
||||
impl im_online::Trait for Runtime {
|
||||
type AuthorityId = ImOnlineId;
|
||||
type Call = Call;
|
||||
type Event = Event;
|
||||
type UncheckedExtrinsic = UncheckedExtrinsic;
|
||||
type Call = Call;
|
||||
type SubmitTransaction = SubmitTransaction;
|
||||
type ReportUnresponsiveness = ();
|
||||
type CurrentElectedSet = staking::CurrentElectedStashAccounts<Runtime>;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use codec::{Encode, Decode, HasCompact};
|
||||
use srml_support::{decl_storage, decl_module, fail, ensure};
|
||||
|
||||
use sr_primitives::traits::{
|
||||
Hash as HashT, BlakeTwo256, Member, CheckedConversion, Saturating, One, Zero,
|
||||
Hash as HashT, BlakeTwo256, Member, CheckedConversion, Saturating, One, Zero, Dispatchable,
|
||||
};
|
||||
use sr_primitives::weights::SimpleDispatchInfo;
|
||||
use primitives::{Hash, Balance, parachain::{
|
||||
@@ -31,7 +31,7 @@ use primitives::{Hash, Balance, parachain::{
|
||||
}};
|
||||
use {system, session};
|
||||
use srml_support::{
|
||||
StorageValue, StorageMap, Parameter, Dispatchable, dispatch::Result,
|
||||
StorageValue, StorageMap, Parameter, dispatch::Result,
|
||||
traits::{Currency, Get, WithdrawReason, ExistenceRequirement}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user