mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
Remove Default bound for AccountId (#10403)
* Remove Default for AccountId * More removals of default * Update frame/authorship/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/authorship/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/authorship/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/authorship/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * More work * More work * Remove old code * More work * pallet-asset-tx-payment * tips * sc-consensus-babe * sc-finality-grandpa * sc-consensus-babe-rpc * sc-cli * make npos crates accept non-default account (#10420) * minimal changes to make npos pallets all work * make this pesky reduce.rs a bit cleaner * more work * more work * Tests build * Fix imonline tests * Formatting * Fixes * Fixes * Fix bench * Fixes * Fixes * Fixes * Fixes * Fixes * Formatting * Fixes * Formatting * Fixes * Formatting * Fixes * Formatting * Fixes * Formatting * Update client/keystore/src/local.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/finality-grandpa/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/keystore/src/local.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/keystore/src/local.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/staking/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update frame/staking/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Formatting Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: kianenigma <kian@parity.io>
This commit is contained in:
@@ -70,20 +70,26 @@ where
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> crate::ApplyExtrinsicResultWithInfo<PostDispatchInfoOf<Self::Call>> {
|
||||
let (maybe_who, pre) = if let Some((id, extra)) = self.signed {
|
||||
let (maybe_who, maybe_pre) = if let Some((id, extra)) = self.signed {
|
||||
let pre = Extra::pre_dispatch(extra, &id, &self.function, info, len)?;
|
||||
(Some(id), pre)
|
||||
(Some(id), Some(pre))
|
||||
} else {
|
||||
let pre = Extra::pre_dispatch_unsigned(&self.function, info, len)?;
|
||||
Extra::pre_dispatch_unsigned(&self.function, info, len)?;
|
||||
U::pre_dispatch(&self.function)?;
|
||||
(None, pre)
|
||||
(None, None)
|
||||
};
|
||||
let res = self.function.dispatch(Origin::from(maybe_who));
|
||||
let post_info = match res {
|
||||
Ok(info) => info,
|
||||
Err(err) => err.post_info,
|
||||
};
|
||||
Extra::post_dispatch(pre, info, &post_info, len, &res.map(|_| ()).map_err(|e| e.error))?;
|
||||
Extra::post_dispatch(
|
||||
maybe_pre,
|
||||
info,
|
||||
&post_info,
|
||||
len,
|
||||
&res.map(|_| ()).map_err(|e| e.error),
|
||||
)?;
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,7 +364,7 @@ mod tests {
|
||||
use crate::{
|
||||
codec::{Decode, Encode},
|
||||
testing::TestSignature as TestSig,
|
||||
traits::{IdentityLookup, SignedExtension},
|
||||
traits::{DispatchInfoOf, IdentityLookup, SignedExtension},
|
||||
};
|
||||
use sp_io::hashing::blake2_256;
|
||||
|
||||
@@ -387,6 +387,16 @@ mod tests {
|
||||
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(self.validate(who, call, info, len).map(|_| ())?)
|
||||
}
|
||||
}
|
||||
|
||||
type Ex = UncheckedExtrinsic<TestAccountId, TestCall, TestSig, TestExtra>;
|
||||
|
||||
@@ -44,7 +44,7 @@ pub use sp_application_crypto as app_crypto;
|
||||
pub use sp_core::storage::{Storage, StorageChild};
|
||||
|
||||
use sp_core::{
|
||||
crypto::{self, Public},
|
||||
crypto::{self, ByteArray},
|
||||
ecdsa, ed25519,
|
||||
hash::{H256, H512},
|
||||
sr25519,
|
||||
@@ -284,12 +284,6 @@ impl TryFrom<MultiSignature> for ecdsa::Signature {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for MultiSignature {
|
||||
fn default() -> Self {
|
||||
Self::Ed25519(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
/// Public key for any known crypto algorithm.
|
||||
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
@@ -302,12 +296,6 @@ pub enum MultiSigner {
|
||||
Ecdsa(ecdsa::Public),
|
||||
}
|
||||
|
||||
impl Default for MultiSigner {
|
||||
fn default() -> Self {
|
||||
Self::Ed25519(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
/// NOTE: This implementations is required by `SimpleAddressDeterminer`,
|
||||
/// we convert the hash into some AccountId, it's fine to use any scheme.
|
||||
impl<T: Into<H256>> crypto::UncheckedFrom<T> for MultiSigner {
|
||||
@@ -403,10 +391,14 @@ impl Verify for MultiSignature {
|
||||
type Signer = MultiSigner;
|
||||
fn verify<L: Lazy<[u8]>>(&self, mut msg: L, signer: &AccountId32) -> bool {
|
||||
match (self, signer) {
|
||||
(Self::Ed25519(ref sig), who) =>
|
||||
sig.verify(msg, &ed25519::Public::from_slice(who.as_ref())),
|
||||
(Self::Sr25519(ref sig), who) =>
|
||||
sig.verify(msg, &sr25519::Public::from_slice(who.as_ref())),
|
||||
(Self::Ed25519(ref sig), who) => match ed25519::Public::from_slice(who.as_ref()) {
|
||||
Ok(signer) => sig.verify(msg, &signer),
|
||||
Err(()) => false,
|
||||
},
|
||||
(Self::Sr25519(ref sig), who) => match sr25519::Public::from_slice(who.as_ref()) {
|
||||
Ok(signer) => sig.verify(msg, &signer),
|
||||
Err(()) => false,
|
||||
},
|
||||
(Self::Ecdsa(ref sig), who) => {
|
||||
let m = sp_io::hashing::blake2_256(msg.get());
|
||||
match sp_io::crypto::secp256k1_ecdsa_recover_compressed(sig.as_ref(), &m) {
|
||||
@@ -433,7 +425,10 @@ impl Verify for AnySignature {
|
||||
.map(|s| s.verify(msg, signer))
|
||||
.unwrap_or(false) ||
|
||||
ed25519::Signature::try_from(self.0.as_fixed_bytes().as_ref())
|
||||
.map(|s| s.verify(msg, &ed25519::Public::from_slice(signer.as_ref())))
|
||||
.map(|s| match ed25519::Public::from_slice(signer.as_ref()) {
|
||||
Err(()) => false,
|
||||
Ok(signer) => s.verify(msg, &signer),
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
@@ -924,7 +919,7 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
use codec::{Decode, Encode};
|
||||
use sp_core::crypto::Pair;
|
||||
use sp_core::crypto::{Pair, UncheckedFrom};
|
||||
use sp_io::TestExternalities;
|
||||
use sp_state_machine::create_proof_check_backend;
|
||||
|
||||
@@ -1010,7 +1005,9 @@ mod tests {
|
||||
|
||||
ext.execute_with(|| {
|
||||
let _batching = SignatureBatching::start();
|
||||
sp_io::crypto::sr25519_verify(&Default::default(), &Vec::new(), &Default::default());
|
||||
let dummy = UncheckedFrom::unchecked_from([1; 32]);
|
||||
let dummy_sig = UncheckedFrom::unchecked_from([1; 64]);
|
||||
sp_io::crypto::sr25519_verify(&dummy_sig, &Vec::new(), &dummy);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,3 @@ impl<AccountId, AccountIndex> From<AccountId> for MultiAddress<AccountId, Accoun
|
||||
Self::Id(a)
|
||||
}
|
||||
}
|
||||
|
||||
impl<AccountId: Default, AccountIndex> Default for MultiAddress<AccountId, AccountIndex> {
|
||||
fn default() -> Self {
|
||||
Self::Id(Default::default())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ use crate::{
|
||||
};
|
||||
use serde::{de::Error as DeError, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use sp_core::{
|
||||
crypto::{key_types, CryptoType, Dummy, Public},
|
||||
crypto::{key_types, ByteArray, CryptoType, Dummy},
|
||||
U256,
|
||||
};
|
||||
pub use sp_core::{sr25519, H256};
|
||||
@@ -77,10 +77,10 @@ impl From<UintAuthorityId> for u64 {
|
||||
}
|
||||
|
||||
impl UintAuthorityId {
|
||||
/// Convert this authority id into a public key.
|
||||
pub fn to_public_key<T: Public>(&self) -> T {
|
||||
/// Convert this authority ID into a public key.
|
||||
pub fn to_public_key<T: ByteArray>(&self) -> T {
|
||||
let bytes: [u8; 32] = U256::from(self.0).into();
|
||||
T::from_slice(&bytes)
|
||||
T::from_slice(&bytes).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -851,7 +851,7 @@ pub trait SignedExtension:
|
||||
type AdditionalSigned: Encode + TypeInfo;
|
||||
|
||||
/// The type that encodes information that can be passed from pre_dispatch to post-dispatch.
|
||||
type Pre: Default;
|
||||
type Pre;
|
||||
|
||||
/// Construct any additional data that should be in the signed payload of the transaction. Can
|
||||
/// also perform any pre-signature-verification checks and return an error if needed.
|
||||
@@ -890,11 +890,7 @@ pub trait SignedExtension:
|
||||
call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
self.validate(who, call, info, len)
|
||||
.map(|_| Self::Pre::default())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
) -> Result<Self::Pre, TransactionValidityError>;
|
||||
|
||||
/// Validate an unsigned transaction for the transaction queue.
|
||||
///
|
||||
@@ -924,14 +920,15 @@ pub trait SignedExtension:
|
||||
call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Self::validate_unsigned(call, info, len)
|
||||
.map(|_| Self::Pre::default())
|
||||
.map_err(Into::into)
|
||||
) -> Result<(), TransactionValidityError> {
|
||||
Self::validate_unsigned(call, info, len).map(|_| ()).map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Do any post-flight stuff for an extrinsic.
|
||||
///
|
||||
/// If the transaction is signed, then `_pre` will contain the output of `pre_dispatch`,
|
||||
/// and `None` otherwise.
|
||||
///
|
||||
/// This gets given the `DispatchResult` `_result` from the extrinsic and can, if desired,
|
||||
/// introduce a `TransactionValidityError`, causing the block to become invalid for including
|
||||
/// it.
|
||||
@@ -944,7 +941,7 @@ pub trait SignedExtension:
|
||||
/// introduced by the current block author; generally this implies that it is an inherent and
|
||||
/// will come from either an offchain-worker or via `InherentData`.
|
||||
fn post_dispatch(
|
||||
_pre: Self::Pre,
|
||||
_pre: Option<Self::Pre>,
|
||||
_info: &DispatchInfoOf<Self::Call>,
|
||||
_post_info: &PostDispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
@@ -1029,18 +1026,26 @@ impl<AccountId, Call: Dispatchable> SignedExtension for Tuple {
|
||||
call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(for_tuples!( ( #( Tuple::pre_dispatch_unsigned(call, info, len)? ),* ) ))
|
||||
) -> Result<(), TransactionValidityError> {
|
||||
for_tuples!( #( Tuple::pre_dispatch_unsigned(call, info, len)?; )* );
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn post_dispatch(
|
||||
pre: Self::Pre,
|
||||
pre: Option<Self::Pre>,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
post_info: &PostDispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
result: &DispatchResult,
|
||||
) -> Result<(), TransactionValidityError> {
|
||||
for_tuples!( #( Tuple::post_dispatch(pre.Tuple, info, post_info, len, result)?; )* );
|
||||
match pre {
|
||||
Some(x) => {
|
||||
for_tuples!( #( Tuple::post_dispatch(Some(x.Tuple), info, post_info, len, result)?; )* );
|
||||
},
|
||||
None => {
|
||||
for_tuples!( #( Tuple::post_dispatch(None, info, post_info, len, result)?; )* );
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1062,6 +1067,15 @@ impl SignedExtension for () {
|
||||
fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
|
||||
Ok(())
|
||||
}
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
info: &DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
Ok(self.validate(who, call, info, len).map(|_| ())?)
|
||||
}
|
||||
}
|
||||
|
||||
/// An "executable" piece of information, used by the standard Substrate Executive in order to
|
||||
@@ -1212,6 +1226,11 @@ impl<'a> TrailingZeroInput<'a> {
|
||||
pub fn new(data: &'a [u8]) -> Self {
|
||||
Self(data)
|
||||
}
|
||||
|
||||
/// Create a new instance which only contains zeroes as input.
|
||||
pub fn zeroes() -> Self {
|
||||
Self::new(&[][..])
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> codec::Input for TrailingZeroInput<'a> {
|
||||
@@ -1260,11 +1279,11 @@ pub trait AccountIdConversion<AccountId>: Sized {
|
||||
|
||||
/// Format is TYPE_ID ++ encode(parachain ID) ++ 00.... where 00... is indefinite trailing zeroes to
|
||||
/// fill AccountId.
|
||||
impl<T: Encode + Decode + Default, Id: Encode + Decode + TypeId> AccountIdConversion<T> for Id {
|
||||
impl<T: Encode + Decode, Id: Encode + Decode + TypeId> AccountIdConversion<T> for Id {
|
||||
fn into_sub_account<S: Encode>(&self, sub: S) -> T {
|
||||
(Id::TYPE_ID, self, sub)
|
||||
.using_encoded(|b| T::decode(&mut TrailingZeroInput(b)))
|
||||
.unwrap_or_default()
|
||||
.expect("`AccountId` type is never greater than 32 bytes; qed")
|
||||
}
|
||||
|
||||
fn try_from_sub_account<S: Decode>(x: &T) -> Option<(Self, S)> {
|
||||
@@ -1317,7 +1336,7 @@ macro_rules! impl_opaque_keys_inner {
|
||||
) => {
|
||||
$( #[ $attr ] )*
|
||||
#[derive(
|
||||
Default, Clone, PartialEq, Eq,
|
||||
Clone, PartialEq, Eq,
|
||||
$crate::codec::Encode,
|
||||
$crate::codec::Decode,
|
||||
$crate::scale_info::TypeInfo,
|
||||
@@ -1616,7 +1635,10 @@ pub trait BlockNumberProvider {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::codec::{Decode, Encode, Input};
|
||||
use sp_core::{crypto::Pair, ecdsa};
|
||||
use sp_core::{
|
||||
crypto::{Pair, UncheckedFrom},
|
||||
ecdsa,
|
||||
};
|
||||
|
||||
mod t {
|
||||
use sp_application_crypto::{app_crypto, sr25519};
|
||||
@@ -1629,8 +1651,8 @@ mod tests {
|
||||
use super::AppVerify;
|
||||
use t::*;
|
||||
|
||||
let s = Signature::default();
|
||||
let _ = s.verify(&[0u8; 100][..], &Public::default());
|
||||
let s = Signature::try_from(vec![0; 64]).unwrap();
|
||||
let _ = s.verify(&[0u8; 100][..], &Public::unchecked_from([0; 32]));
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Default, PartialEq, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user