Skip to content

Commit

Permalink
Get the block timestamp using the Time trait
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 19, 2024
1 parent 306825e commit c74ce3a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod pallet {
use frame_support::pallet_prelude::*;
use frame_support::traits::fungible::{Inspect, InspectHold, Mutate, MutateHold};
use frame_support::traits::tokens::Preservation;
use frame_support::traits::Randomness as RandomnessT;
use frame_support::traits::{Randomness as RandomnessT, Time};
use frame_support::weights::Weight;
use frame_support::{Identity, PalletError};
use frame_system::pallet_prelude::*;
Expand Down Expand Up @@ -390,6 +390,9 @@ mod pallet {
/// Storage fee interface used to deal with bundle storage fee
type StorageFee: StorageFee<BalanceOf<Self>>;

/// The block timestamp
type BlockTimestamp: Time;

/// The block slot
type BlockSlot: BlockSlot<Self>;

Expand Down Expand Up @@ -1913,7 +1916,11 @@ mod pallet {
Into::<H256>::into(Self::extrinsics_shuffling_seed()).to_fixed_bytes(),
);

let timestamp = Moment::default();
// There is no actual conversion here, but the trait bounds required to prove that
// (and debug-print the error in expect()) are very verbose.
let timestamp = TryInto::<Moment>::try_into(T::BlockTimestamp::now())
.map_err(|_| ())
.expect("Moment is the same type in both pallets; qed");

let invalid_inherent_extrinsic_data = InvalidInherentExtrinsicData {
extrinsics_shuffling_seed,
Expand Down
1 change: 1 addition & 0 deletions crates/pallet-domains/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ impl pallet_domains::Config for Test {
type Randomness = MockRandomness;
type PalletId = DomainsPalletId;
type StorageFee = DummyStorageFee;
type BlockTimestamp = pallet_timestamp::Pallet<Test>;
type BlockSlot = DummyBlockSlot;
type DomainsTransfersTracker = MockDomainsTransfersTracker;
type MaxInitialDomainAccounts = MaxInitialDomainAccounts;
Expand Down
1 change: 1 addition & 0 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ impl pallet_domains::Config for Runtime {
type Randomness = Subspace;
type PalletId = DomainsPalletId;
type StorageFee = TransactionFees;
type BlockTimestamp = pallet_timestamp::Pallet<Runtime>;
type BlockSlot = BlockSlot;
type BundleLongevity = BundleLongevity;
type DomainsTransfersTracker = Transporter;
Expand Down
1 change: 1 addition & 0 deletions test/subspace-test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ impl pallet_domains::Config for Runtime {
type MinNominatorStake = MinNominatorStake;
type PalletId = DomainsPalletId;
type StorageFee = TransactionFees;
type BlockTimestamp = pallet_timestamp::Pallet<Runtime>;
type BlockSlot = BlockSlot;
type BundleLongevity = BundleLongevity;
type DomainsTransfersTracker = Transporter;
Expand Down

0 comments on commit c74ce3a

Please sign in to comment.