Skip to content

Commit

Permalink
migrate pallet-bounties to use umbrella crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathy-bajo committed Jan 16, 2025
1 parent be2404c commit f356733
Show file tree
Hide file tree
Showing 9 changed files with 3,482 additions and 82 deletions.
7 changes: 1 addition & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 3 additions & 19 deletions substrate/frame/bounties/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { features = [
"derive",
], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame = { workspace = true, features = [ "experimental", "runtime"]}
log = { workspace = true }
pallet-treasury = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }

[dev-dependencies]
pallet-balances = { workspace = true, default-features = true }
Expand All @@ -36,29 +31,18 @@ pallet-balances = { workspace = true, default-features = true }
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"pallet-balances/std",
"pallet-treasury/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"frame/try-runtime",
"pallet-balances/try-runtime",
"pallet-treasury/try-runtime",
"sp-runtime/try-runtime",
]
6 changes: 1 addition & 5 deletions substrate/frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
use super::*;

use alloc::{vec, vec::Vec};
use frame_benchmarking::v1::{
account, benchmarks_instance_pallet, whitelisted_caller, BenchmarkError,
};
use frame_system::{pallet_prelude::BlockNumberFor as SystemBlockNumberFor, RawOrigin};
use sp_runtime::traits::{BlockNumberProvider, Bounded};
use frame::benchmarking::prelude::*;

use crate::Pallet as Bounties;
use pallet_treasury::Pallet as Treasury;
Expand Down
18 changes: 2 additions & 16 deletions substrate/frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,7 @@ extern crate alloc;

use alloc::vec::Vec;

use frame_support::traits::{
Currency, ExistenceRequirement::AllowDeath, Get, Imbalance, OnUnbalanced, ReservableCurrency,
};

use sp_runtime::{
traits::{AccountIdConversion, BadOrigin, BlockNumberProvider, Saturating, StaticLookup, Zero},
DispatchResult, Permill, RuntimeDebug,
};

use frame_support::{dispatch::DispatchResultWithPostInfo, traits::EnsureOrigin};

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

Expand Down Expand Up @@ -201,7 +187,7 @@ pub trait ChildBountyManager<Balance> {
fn bounty_removed(bounty_id: BountyIndex);
}

#[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;

Expand Down
23 changes: 10 additions & 13 deletions substrate/frame/bounties/src/migrations/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
// limitations under the License.

use core::str;
use frame_support::{
storage::{generator::StorageValue, StoragePrefixedMap},
traits::{
Get, GetStorageVersion, PalletInfoAccess, StorageVersion,
STORAGE_VERSION_STORAGE_KEY_POSTFIX,
use frame::{
deps::{
sp_core::hexdisplay::HexDisplay,
sp_io::{hashing::twox_128, storage},
},
weights::Weight,
testing_prelude::*,
};
use sp_core::hexdisplay::HexDisplay;
use sp_io::{hashing::twox_128, storage};

use crate as pallet_bounties;

Expand Down Expand Up @@ -66,31 +63,31 @@ pub fn migrate<

if on_chain_storage_version < 4 {
let storage_prefix = pallet_bounties::BountyCount::<T>::storage_prefix();
frame_support::storage::migration::move_storage_from_pallet(
migration::move_storage_from_pallet(
storage_prefix,
old_pallet_name.as_bytes(),
new_pallet_name.as_bytes(),
);
log_migration("migration", storage_prefix, old_pallet_name, new_pallet_name);

let storage_prefix = pallet_bounties::Bounties::<T>::storage_prefix();
frame_support::storage::migration::move_storage_from_pallet(
migration::move_storage_from_pallet(
storage_prefix,
old_pallet_name.as_bytes(),
new_pallet_name.as_bytes(),
);
log_migration("migration", storage_prefix, old_pallet_name, new_pallet_name);

let storage_prefix = pallet_bounties::BountyDescriptions::<T>::storage_prefix();
frame_support::storage::migration::move_storage_from_pallet(
migration::move_storage_from_pallet(
storage_prefix,
old_pallet_name.as_bytes(),
new_pallet_name.as_bytes(),
);
log_migration("migration", storage_prefix, old_pallet_name, new_pallet_name);

let storage_prefix = pallet_bounties::BountyApprovals::<T>::storage_prefix();
frame_support::storage::migration::move_storage_from_pallet(
migration::move_storage_from_pallet(
storage_prefix,
old_pallet_name.as_bytes(),
new_pallet_name.as_bytes(),
Expand Down Expand Up @@ -158,7 +155,7 @@ pub fn pre_migration<T: pallet_bounties::Config, P: GetStorageVersion + 'static,
),
"unexpected next_key({}) = {:?}",
new_pallet_name,
HexDisplay::from(&sp_io::storage::next_key(&new_pallet_prefix).unwrap()),
HexDisplay::from(&storage::next_key(&new_pallet_prefix).unwrap()),
);
assert!(<P as GetStorageVersion>::on_chain_storage_version() < 4);
}
Expand Down
20 changes: 4 additions & 16 deletions substrate/frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,19 @@
use super::*;
use crate as pallet_bounties;

use frame_support::{
assert_noop, assert_ok, derive_impl, parameter_types,
traits::{
tokens::{PayFromAccount, UnityAssetBalanceConversion},
ConstU32, ConstU64, OnInitialize,
},
PalletId,
};

use sp_runtime::{
traits::{BadOrigin, IdentityLookup},
BuildStorage, Perbill, Storage,
};
use frame::testing_prelude::*;

use super::Event as BountiesEvent;

type Block = frame_system::mocking::MockBlock<Test>;
type Block = MockBlock<Test>;

// This function directly jumps to a block number, and calls `on_initialize`.
fn go_to_block(n: u64) {
<Test as pallet_treasury::Config>::BlockNumberProvider::set_block_number(n);
<Treasury as OnInitialize<u64>>::on_initialize(n);
}

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down Expand Up @@ -955,7 +943,7 @@ fn test_migration_v4() {

s.top = data.into_iter().collect();

sp_io::TestExternalities::new(s).execute_with(|| {
TestExternalities::new(s).execute_with(|| {
use frame_support::traits::PalletInfo;
let old_pallet_name = <Test as frame_system::Config>::PalletInfo::name::<Bounties>()
.expect("Bounties is part of runtime, so it has a name; qed");
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/bounties/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions substrate/frame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,23 @@ pub mod prelude {

/// Dispatch types from `frame-support`, other fundamental traits
#[doc(no_inline)]
pub use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo};
pub use frame_support::dispatch::{
DispatchResultWithPostInfo, GetDispatchInfo, PostDispatchInfo,
};
pub use frame_support::{
defensive, defensive_assert,
storage::{generator::StorageValue, StoragePrefixedMap, migration},
traits::{
Contains, EitherOf, EstimateNextSessionRotation, IsSubType, MapSuccess, NoOpPoll,
OnRuntimeUpgrade, OneSessionHandler, RankedMembers, RankedMembersSwapHandler,
tokens::{PayFromAccount, UnityAssetBalanceConversion},
Contains, Currency, EitherOf, EnsureOrigin, EstimateNextSessionRotation,
ExistenceRequirement::AllowDeath,
Get, GetStorageVersion, Imbalance, IsSubType, MapSuccess, NoOpPoll, OnRuntimeUpgrade,
OnUnbalanced, OneSessionHandler, PalletInfoAccess, RankedMembers,
RankedMembersSwapHandler, ReservableCurrency, StorageVersion,
STORAGE_VERSION_STORAGE_KEY_POSTFIX,
},
weights::Weight,
PalletId,
};

/// Pallet prelude of `frame-system`.
Expand All @@ -231,9 +241,13 @@ pub mod prelude {

/// Runtime traits
#[doc(no_inline)]
pub use sp_runtime::traits::{
BlockNumberProvider, Bounded, Convert, DispatchInfoOf, Dispatchable, ReduceBy,
ReplaceWithDefault, SaturatedConversion, Saturating, StaticLookup, TrailingZeroInput,
pub use sp_runtime::{
traits::{
AccountIdConversion, BadOrigin, BlockNumberProvider, Bounded, Convert, DispatchInfoOf,
Dispatchable, IdentityLookup, ReduceBy, ReplaceWithDefault, SaturatedConversion,
Saturating, StaticLookup, TrailingZeroInput, Zero,
},
BuildStorage, DispatchResult, Perbill, Permill, RuntimeDebug, Storage,
};
/// Other error/result types for runtime
#[doc(no_inline)]
Expand Down
Loading

0 comments on commit f356733

Please sign in to comment.