mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +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:
@@ -731,6 +731,16 @@ where
|
||||
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(|_| ())?)
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
_who: &Self::AccountId,
|
||||
|
||||
@@ -233,7 +233,7 @@ pub mod pallet {
|
||||
// Retrieve sender of the transaction.
|
||||
let who = ensure_signed(origin)?;
|
||||
// Add the price to the on-chain list.
|
||||
Self::add_price(who, price);
|
||||
Self::add_price(Some(who), price);
|
||||
Ok(().into())
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ pub mod pallet {
|
||||
// This ensures that the function can only be called via unsigned transaction.
|
||||
ensure_none(origin)?;
|
||||
// Add the price to the on-chain list, but mark it as coming from an empty address.
|
||||
Self::add_price(Default::default(), price);
|
||||
Self::add_price(None, price);
|
||||
// now increment the block number at which we expect next unsigned transaction.
|
||||
let current_block = <system::Pallet<T>>::block_number();
|
||||
<NextUnsignedAt<T>>::put(current_block + T::UnsignedInterval::get());
|
||||
@@ -278,7 +278,7 @@ pub mod pallet {
|
||||
// This ensures that the function can only be called via unsigned transaction.
|
||||
ensure_none(origin)?;
|
||||
// Add the price to the on-chain list, but mark it as coming from an empty address.
|
||||
Self::add_price(Default::default(), price_payload.price);
|
||||
Self::add_price(None, price_payload.price);
|
||||
// now increment the block number at which we expect next unsigned transaction.
|
||||
let current_block = <system::Pallet<T>>::block_number();
|
||||
<NextUnsignedAt<T>>::put(current_block + T::UnsignedInterval::get());
|
||||
@@ -291,7 +291,7 @@ pub mod pallet {
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
pub enum Event<T: Config> {
|
||||
/// Event generated when new price is accepted to contribute to the average.
|
||||
NewPrice { price: u32, who: T::AccountId },
|
||||
NewPrice { price: u32, maybe_who: Option<T::AccountId> },
|
||||
}
|
||||
|
||||
#[pallet::validate_unsigned]
|
||||
@@ -641,7 +641,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// Add new price to the list.
|
||||
fn add_price(who: T::AccountId, price: u32) {
|
||||
fn add_price(maybe_who: Option<T::AccountId>, price: u32) {
|
||||
log::info!("Adding to the average: {}", price);
|
||||
<Prices<T>>::mutate(|prices| {
|
||||
const MAX_LEN: usize = 64;
|
||||
@@ -657,7 +657,7 @@ impl<T: Config> Pallet<T> {
|
||||
.expect("The average is not empty, because it was just mutated; qed");
|
||||
log::info!("Current average price is: {}", average);
|
||||
// here we are raising the NewPrice event
|
||||
Self::deposit_event(Event::NewPrice { price, who });
|
||||
Self::deposit_event(Event::NewPrice { price, maybe_who });
|
||||
}
|
||||
|
||||
/// Calculate current average price.
|
||||
|
||||
@@ -125,15 +125,19 @@ impl Config for Test {
|
||||
type UnsignedPriority = UnsignedPriority;
|
||||
}
|
||||
|
||||
fn test_pub() -> sp_core::sr25519::Public {
|
||||
sp_core::sr25519::Public::from_raw([1u8; 32])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_aggregates_the_price() {
|
||||
sp_io::TestExternalities::default().execute_with(|| {
|
||||
assert_eq!(Example::average_price(), None);
|
||||
|
||||
assert_ok!(Example::submit_price(Origin::signed(Default::default()), 27));
|
||||
assert_ok!(Example::submit_price(Origin::signed(test_pub()), 27));
|
||||
assert_eq!(Example::average_price(), Some(27));
|
||||
|
||||
assert_ok!(Example::submit_price(Origin::signed(Default::default()), 43));
|
||||
assert_ok!(Example::submit_price(Origin::signed(test_pub()), 43));
|
||||
assert_eq!(Example::average_price(), Some(35));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -105,13 +105,13 @@ pub struct EnlistedParticipant {
|
||||
|
||||
impl EnlistedParticipant {
|
||||
fn verify(&self, event_id: &[u8]) -> bool {
|
||||
use sp_core::Public;
|
||||
use sp_core::ByteArray;
|
||||
use sp_runtime::traits::Verify;
|
||||
|
||||
match sp_core::sr25519::Signature::try_from(&self.signature[..]) {
|
||||
Ok(signature) => {
|
||||
let public = sp_core::sr25519::Public::from_slice(self.account.as_ref());
|
||||
signature.verify(event_id, &public)
|
||||
Ok(signature) => match sp_core::sr25519::Public::from_slice(self.account.as_ref()) {
|
||||
Err(()) => false,
|
||||
Ok(signer) => signature.verify(event_id, &signer),
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
|
||||
@@ -81,6 +81,14 @@ impl Config for Test {
|
||||
type Call = Call;
|
||||
}
|
||||
|
||||
fn test_pub(n: u8) -> sp_core::sr25519::Public {
|
||||
sp_core::sr25519::Public::from_raw([n; 32])
|
||||
}
|
||||
|
||||
fn test_origin(n: u8) -> Origin {
|
||||
Origin::signed(test_pub(n))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_can_enlist() {
|
||||
use sp_core::Pair;
|
||||
@@ -91,8 +99,7 @@ fn it_can_enlist() {
|
||||
|
||||
let event_name = b"test";
|
||||
|
||||
Example::run_event(Origin::signed(Default::default()), event_name.to_vec())
|
||||
.expect("Failed to enlist");
|
||||
Example::run_event(test_origin(1), event_name.to_vec()).expect("Failed to enlist");
|
||||
|
||||
let participants = vec![
|
||||
EnlistedParticipant {
|
||||
@@ -105,7 +112,7 @@ fn it_can_enlist() {
|
||||
},
|
||||
];
|
||||
|
||||
Example::enlist_participants(Origin::signed(Default::default()), participants)
|
||||
Example::enlist_participants(Origin::signed(test_pub(1)), participants)
|
||||
.expect("Failed to enlist");
|
||||
|
||||
assert_eq!(Example::participants().len(), 2);
|
||||
@@ -123,8 +130,7 @@ fn one_wrong_will_not_enlist_anyone() {
|
||||
|
||||
let event_name = b"test";
|
||||
|
||||
Example::run_event(Origin::signed(Default::default()), event_name.to_vec())
|
||||
.expect("Failed to enlist");
|
||||
Example::run_event(test_origin(1), event_name.to_vec()).expect("Failed to enlist");
|
||||
|
||||
let participants = vec![
|
||||
EnlistedParticipant {
|
||||
@@ -142,8 +148,7 @@ fn one_wrong_will_not_enlist_anyone() {
|
||||
},
|
||||
];
|
||||
|
||||
Example::enlist_participants(Origin::signed(Default::default()), participants)
|
||||
.expect("Failed to enlist");
|
||||
Example::enlist_participants(test_origin(1), participants).expect("Failed to enlist");
|
||||
|
||||
assert_eq!(Example::participants().len(), 0);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user