Skip to content

Commit

Permalink
Updates bounties and child bounties as well
Browse files Browse the repository at this point in the history
  • Loading branch information
gupnik committed Nov 20, 2024
1 parent 99e87cc commit bd05ace
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions substrate/frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use alloc::{vec, vec::Vec};
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError,
};
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use frame_system::{pallet_prelude::BlockNumberFor as SystemBlockNumberFor, RawOrigin};
use sp_runtime::traits::{BlockNumberProvider, Bounded};

use crate::Pallet as Bounties;
use pallet_treasury::Pallet as Treasury;

const SEED: u32 = 0;

fn set_block_number<T: Config<I>, I: 'static>(n: BlockNumberFor<T>) {
fn set_block_number<T: Config<I>, I: 'static>(n: BlockNumberFor<T, I>) {
<T as pallet_treasury::Config<I>>::BlockNumberProvider::set_block_number(n);
}

Expand Down Expand Up @@ -132,7 +132,7 @@ benchmarks_instance_pallet! {
Bounties::<T, I>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::<T, I>::get() - 1;
let approve_origin = T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
Treasury::<T, I>::on_initialize(SystemBlockNumberFor::<T>::zero());
}: _<T::RuntimeOrigin>(approve_origin, bounty_id, curator_lookup, fee)
verify {
assert_last_event::<T, I>(
Expand Down
19 changes: 12 additions & 7 deletions substrate/frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ use sp_runtime::{
use frame_support::{dispatch::DispatchResultWithPostInfo, traits::EnsureOrigin};

use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use frame_system::pallet_prelude::{
ensure_signed, BlockNumberFor as SystemBlockNumberFor, OriginFor,
};
use scale_info::TypeInfo;
pub use weights::WeightInfo;

Expand All @@ -120,6 +122,9 @@ pub type BountyIndex = u32;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

type BlockNumberFor<T, I = ()> =
<<T as pallet_treasury::Config<I>>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;

/// A bounty proposal.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct Bounty<AccountId, Balance, BlockNumber> {
Expand Down Expand Up @@ -213,11 +218,11 @@ pub mod pallet {

/// The delay period for which a bounty beneficiary need to wait before claim the payout.
#[pallet::constant]
type BountyDepositPayoutDelay: Get<BlockNumberFor<Self>>;
type BountyDepositPayoutDelay: Get<BlockNumberFor<Self, I>>;

/// Bounty duration in blocks.
#[pallet::constant]
type BountyUpdatePeriod: Get<BlockNumberFor<Self>>;
type BountyUpdatePeriod: Get<BlockNumberFor<Self, I>>;

/// The curator deposit is calculated as a percentage of the curator fee.
///
Expand Down Expand Up @@ -326,7 +331,7 @@ pub mod pallet {
_,
Twox64Concat,
BountyIndex,
Bounty<T::AccountId, BalanceOf<T, I>, BlockNumberFor<T>>,
Bounty<T::AccountId, BalanceOf<T, I>, BlockNumberFor<T, I>>,
>;

/// The description of each bounty.
Expand Down Expand Up @@ -876,9 +881,9 @@ pub mod pallet {
}

#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
impl<T: Config<I>, I: 'static> Hooks<SystemBlockNumberFor<T>> for Pallet<T, I> {
#[cfg(feature = "try-runtime")]
fn try_state(_n: BlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
fn try_state(_n: SystemBlockNumberFor<T>) -> Result<(), sp_runtime::TryRuntimeError> {
Self::do_try_state()
}
}
Expand Down Expand Up @@ -928,7 +933,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Get the block number used in the treasury pallet.
///
/// It may be configured to use the relay chain block number on a parachain.
pub fn treasury_block_number() -> BlockNumberFor<T> {
pub fn treasury_block_number() -> BlockNumberFor<T, I> {
<T as pallet_treasury::Config<I>>::BlockNumberProvider::current_block_number()
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/child-bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use alloc::vec;
use frame_benchmarking::{v2::*, BenchmarkError};
use frame_support::ensure;
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
use frame_system::RawOrigin;
use pallet_bounties::Pallet as Bounties;
use pallet_treasury::Pallet as Treasury;
use sp_runtime::traits::BlockNumberProvider;
Expand Down
8 changes: 6 additions & 2 deletions substrate/frame/child-bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ use sp_runtime::{
};

use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use frame_system::pallet_prelude::{
ensure_signed, BlockNumberFor as SystemBlockNumberFor, OriginFor,
};
use pallet_bounties::BountyStatus;
use scale_info::TypeInfo;
pub use weights::WeightInfo;
Expand All @@ -90,6 +92,8 @@ type BalanceOf<T> = pallet_treasury::BalanceOf<T>;
type BountiesError<T> = pallet_bounties::Error<T>;
type BountyIndex = pallet_bounties::BountyIndex;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
type BlockNumberFor<T> =
<<T as pallet_treasury::Config>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;

/// A child bounty proposal.
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
Expand Down Expand Up @@ -810,7 +814,7 @@ pub mod pallet {
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
impl<T: Config> Hooks<SystemBlockNumberFor<T>> for Pallet<T> {
fn integrity_test() {
let parent_bounty_id: BountyIndex = 1;
let child_bounty_id: BountyIndex = 2;
Expand Down

0 comments on commit bd05ace

Please sign in to comment.