Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet grants BlockNumberProvider integration #436

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

8 changes: 5 additions & 3 deletions pallets/grants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use frame_support::{
};
use parity_scale_codec::{Decode, Encode};
use sp_runtime::{
traits::{AtLeast32Bit, CheckedAdd, Saturating, StaticLookup, Zero},
traits::{AtLeast32Bit, BlockNumberProvider, CheckedAdd, Saturating, StaticLookup, Zero},
DispatchResult, RuntimeDebug,
};
use sp_std::{
Expand Down Expand Up @@ -123,6 +123,8 @@ pub mod pallet {
type ForceOrigin: EnsureOrigin<Self::Origin>;
/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
// The block number provider
type BlockNumberProvider: BlockNumberProvider<BlockNumber = Self::BlockNumber>;
}

#[pallet::pallet]
Expand Down Expand Up @@ -231,7 +233,7 @@ pub mod pallet {
let target = T::Lookup::lookup(who)?;
VestingSchedules::<T>::insert(target.clone(), new_schedules.clone());

let now = <frame_system::Pallet<T>>::block_number();
let now = T::BlockNumberProvider::current_block_number();
let new_lock: BalanceOf<T> = new_schedules
.iter()
.fold(Zero::zero(), |acc, s| {
Expand Down Expand Up @@ -374,7 +376,7 @@ impl<T: Config> Pallet<T> {

/// Returns locked balance based on current block number.
fn locked_balance(who: &T::AccountId) -> BalanceOf<T> {
let now = <frame_system::Pallet<T>>::block_number();
let now = T::BlockNumberProvider::current_block_number();
Self::vesting_schedules(who)
.iter()
.fold(Zero::zero(), |acc, s| {
Expand Down
1 change: 1 addition & 0 deletions pallets/grants/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl Config for Test {
type CancelOrigin = EnsureSignedBy<CancelOrigin, AccountId>;
type ForceOrigin = EnsureSignedBy<ForceOrigin, AccountId>;
type WeightInfo = ();
type BlockNumberProvider = frame_system::Pallet<Test>;
}

pub const ALICE: AccountId = 1;
Expand Down
2 changes: 1 addition & 1 deletion runtimes/eden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Eliott Teissonniere <[email protected]>"]
edition = "2018"
name = "runtime-eden"
version = "2.0.13"
version = "2.0.14"

[features]
default = ["std"]
Expand Down
17 changes: 16 additions & 1 deletion runtimes/eden/src/implementations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

use crate::{Authorship, Balances, CompanyReserve};
use frame_support::traits::{Currency, Imbalance, OnUnbalanced};
use primitives::AccountId;
use primitives::{AccountId, BlockNumber};
use sp_runtime::traits::BlockNumberProvider;

/// Logic for the author to get a portion of fees.
pub struct Author;
Expand Down Expand Up @@ -49,3 +50,17 @@ impl OnUnbalanced<NegativeImbalance> for DealWithFees {
}
}
}

pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);

impl<T: cumulus_pallet_parachain_system::Config> BlockNumberProvider
for RelayChainBlockNumberProvider<T>
{
type BlockNumber = BlockNumber;

fn current_block_number() -> Self::BlockNumber {
cumulus_pallet_parachain_system::Pallet::<T>::validation_data()
.map(|d| d.relay_parent_number)
.unwrap_or_default()
}
}
6 changes: 5 additions & 1 deletion runtimes/eden/src/pallets_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use crate::{constants, Balances, Call, Event, Origin, OriginCaller, Runtime};
use crate::{
constants, implementations::RelayChainBlockNumberProvider, Balances, Call, Event, Origin,
OriginCaller, Runtime,
};
use frame_support::{parameter_types, weights::Weight};
use primitives::{AccountId, Balance};
use sp_runtime::Perbill;
Expand All @@ -26,6 +29,7 @@ impl pallet_grants::Config for Runtime {
type CancelOrigin = frame_system::EnsureRoot<AccountId>;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type WeightInfo = pallet_grants::weights::SubstrateWeight<Runtime>;
type BlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions runtimes/main/src/pallets_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl pallet_grants::Config for Runtime {
type ForceOrigin =
pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, FinancialCollective>;
type WeightInfo = pallet_grants::weights::SubstrateWeight<Runtime>;
type BlockNumberProvider = frame_system::Pallet<Runtime>;
}

impl pallet_utility::Config for Runtime {
Expand Down