mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Associated type Hasher for QueryPreimage, StorePreimage and Bounded (#1720)
I hope it's enough to fix #1701 the only solution I found to make it happen is to put an associated type to the `Bounded` enum as well. @liamaharon @kianenigma @bkchr Polkadot address: 12poSUQPtcF1HUPQGY3zZu2P8emuW9YnsPduA4XG3oCEfJVp --------- Signed-off-by: muraca <mmuraca247@gmail.com> Co-authored-by: Liam Aharon <liam.aharon@hotmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -25,7 +25,7 @@ use frame_benchmarking::v1::{
|
||||
};
|
||||
use frame_support::{
|
||||
assert_ok,
|
||||
traits::{Bounded, Currency, EnsureOrigin, EnsureOriginWithArg, UnfilteredDispatchable},
|
||||
traits::{Currency, EnsureOrigin, EnsureOriginWithArg, UnfilteredDispatchable},
|
||||
};
|
||||
use frame_system::RawOrigin;
|
||||
use sp_runtime::traits::Bounded as ArithBounded;
|
||||
@@ -42,7 +42,7 @@ fn funded_account<T: Config<I>, I: 'static>(name: &'static str, index: u32) -> T
|
||||
caller
|
||||
}
|
||||
|
||||
fn dummy_call<T: Config<I>, I: 'static>() -> Bounded<<T as Config<I>>::RuntimeCall> {
|
||||
fn dummy_call<T: Config<I>, I: 'static>() -> BoundedCallOf<T, I> {
|
||||
let inner = frame_system::Call::remark { remark: vec![] };
|
||||
let call = <T as Config<I>>::RuntimeCall::from(inner);
|
||||
T::Preimages::bound(call).unwrap()
|
||||
|
||||
@@ -73,8 +73,8 @@ use frame_support::{
|
||||
v3::{Anon as ScheduleAnon, Named as ScheduleNamed},
|
||||
DispatchTime,
|
||||
},
|
||||
Currency, Hash as PreimageHash, LockIdentifier, OnUnbalanced, OriginTrait, PollStatus,
|
||||
Polling, QueryPreimage, ReservableCurrency, StorePreimage, VoteTally,
|
||||
Currency, LockIdentifier, OnUnbalanced, OriginTrait, PollStatus, Polling, QueryPreimage,
|
||||
ReservableCurrency, StorePreimage, VoteTally,
|
||||
},
|
||||
BoundedVec,
|
||||
};
|
||||
@@ -163,8 +163,17 @@ pub mod pallet {
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
/// The Scheduler.
|
||||
type Scheduler: ScheduleAnon<BlockNumberFor<Self>, CallOf<Self, I>, PalletsOriginOf<Self>>
|
||||
+ ScheduleNamed<BlockNumberFor<Self>, CallOf<Self, I>, PalletsOriginOf<Self>>;
|
||||
type Scheduler: ScheduleAnon<
|
||||
BlockNumberFor<Self>,
|
||||
CallOf<Self, I>,
|
||||
PalletsOriginOf<Self>,
|
||||
Hasher = Self::Hashing,
|
||||
> + ScheduleNamed<
|
||||
BlockNumberFor<Self>,
|
||||
CallOf<Self, I>,
|
||||
PalletsOriginOf<Self>,
|
||||
Hasher = Self::Hashing,
|
||||
>;
|
||||
/// Currency type for this pallet.
|
||||
type Currency: ReservableCurrency<Self::AccountId>;
|
||||
// Origins and unbalances.
|
||||
@@ -226,7 +235,7 @@ pub mod pallet {
|
||||
>;
|
||||
|
||||
/// The preimage provider.
|
||||
type Preimages: QueryPreimage + StorePreimage;
|
||||
type Preimages: QueryPreimage<H = Self::Hashing> + StorePreimage;
|
||||
}
|
||||
|
||||
/// The next free referendum index, aka the number of referenda started so far.
|
||||
@@ -257,14 +266,14 @@ pub mod pallet {
|
||||
StorageMap<_, Twox64Concat, TrackIdOf<T, I>, u32, ValueQuery>;
|
||||
|
||||
/// The metadata is a general information concerning the referendum.
|
||||
/// The `PreimageHash` refers to the preimage of the `Preimages` provider which can be a JSON
|
||||
/// The `Hash` refers to the preimage of the `Preimages` provider which can be a JSON
|
||||
/// dump or IPFS hash of a JSON file.
|
||||
///
|
||||
/// Consider a garbage collection for a metadata of finished referendums to `unrequest` (remove)
|
||||
/// large preimages.
|
||||
#[pallet::storage]
|
||||
pub type MetadataOf<T: Config<I>, I: 'static = ()> =
|
||||
StorageMap<_, Blake2_128Concat, ReferendumIndex, PreimageHash>;
|
||||
StorageMap<_, Blake2_128Concat, ReferendumIndex, T::Hash>;
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub(super) fn deposit_event)]
|
||||
@@ -376,14 +385,14 @@ pub mod pallet {
|
||||
/// Index of the referendum.
|
||||
index: ReferendumIndex,
|
||||
/// Preimage hash.
|
||||
hash: PreimageHash,
|
||||
hash: T::Hash,
|
||||
},
|
||||
/// Metadata for a referendum has been cleared.
|
||||
MetadataCleared {
|
||||
/// Index of the referendum.
|
||||
index: ReferendumIndex,
|
||||
/// Preimage hash.
|
||||
hash: PreimageHash,
|
||||
hash: T::Hash,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -691,7 +700,7 @@ pub mod pallet {
|
||||
pub fn set_metadata(
|
||||
origin: OriginFor<T>,
|
||||
index: ReferendumIndex,
|
||||
maybe_hash: Option<PreimageHash>,
|
||||
maybe_hash: Option<T::Hash>,
|
||||
) -> DispatchResult {
|
||||
let who = ensure_signed(origin)?;
|
||||
if let Some(hash) = maybe_hash {
|
||||
|
||||
@@ -473,7 +473,7 @@ impl RefState {
|
||||
}
|
||||
|
||||
/// note a new preimage without registering.
|
||||
pub fn note_preimage(who: u64) -> PreimageHash {
|
||||
pub fn note_preimage(who: u64) -> <Test as frame_system::Config>::Hash {
|
||||
use std::sync::atomic::{AtomicU8, Ordering};
|
||||
// note a new preimage on every function invoke.
|
||||
static COUNTER: AtomicU8 = AtomicU8::new(0);
|
||||
|
||||
@@ -599,9 +599,8 @@ fn curve_handles_all_inputs() {
|
||||
#[test]
|
||||
fn set_metadata_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
use frame_support::traits::Hash as PreimageHash;
|
||||
// invalid preimage hash.
|
||||
let invalid_hash: PreimageHash = [1u8; 32].into();
|
||||
let invalid_hash: <Test as frame_system::Config>::Hash = [1u8; 32].into();
|
||||
// fails to set metadata for a finished referendum.
|
||||
assert_ok!(Referenda::submit(
|
||||
RuntimeOrigin::signed(1),
|
||||
|
||||
@@ -34,7 +34,8 @@ pub type NegativeImbalanceOf<T, I> = <<T as Config<I>>::Currency as Currency<
|
||||
<T as frame_system::Config>::AccountId,
|
||||
>>::NegativeImbalance;
|
||||
pub type CallOf<T, I> = <T as Config<I>>::RuntimeCall;
|
||||
pub type BoundedCallOf<T, I> = Bounded<<T as Config<I>>::RuntimeCall>;
|
||||
pub type BoundedCallOf<T, I> =
|
||||
Bounded<<T as Config<I>>::RuntimeCall, <T as frame_system::Config>::Hashing>;
|
||||
pub type VotesOf<T, I> = <T as Config<I>>::Votes;
|
||||
pub type TallyOf<T, I> = <T as Config<I>>::Tally;
|
||||
pub type PalletsOriginOf<T> =
|
||||
|
||||
Reference in New Issue
Block a user