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

Migrate pallet-timestamp to umbrella crate #6523

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
9 changes: 1 addition & 8 deletions Cargo.lock

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

33 changes: 7 additions & 26 deletions substrate/frame/timestamp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,27 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { features = ["derive", "max-encoded-len"], workspace = true }
log = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
frame-benchmarking = { optional = true, workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-inherents = { workspace = true }
sp-io = { optional = true, workspace = true }
sp-runtime = { workspace = true }
sp-storage = { workspace = true }
frame = { workspace = true, features = ["experimental", "runtime"] }
sp-timestamp = { workspace = true }

docify = { workspace = true }

[dev-dependencies]
sp-core = { workspace = true, default-features = true }
sp-io = { workspace = true, default-features = true }
# [dev-dependencies]
# sp-core = { workspace = true, default-features = true }
# sp-io = { workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"frame/std",
"log/std",
"scale-info/std",
"sp-core/std",
"sp-inherents/std",
"sp-io?/std",
"sp-runtime/std",
"sp-storage/std",
"sp-timestamp/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-io",
"sp-runtime/runtime-benchmarks",
"frame/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"frame/try-runtime",
]
5 changes: 3 additions & 2 deletions substrate/frame/timestamp/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
//! Timestamp pallet benchmarking.

#![cfg(feature = "runtime-benchmarks")]

/*
use frame_benchmarking::{benchmarking::add_to_whitelist, v2::*};
use frame_support::traits::OnFinalize;
use frame_system::RawOrigin;
use sp_storage::TrackedStorageKey;

*/
use frame::{benchmarking::prelude::*, traits::TrackedStorageKey};
use crate::*;

const MAX_TIME: u32 = 100;
Expand Down
18 changes: 12 additions & 6 deletions substrate/frame/timestamp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@
//!
//! ```
//! use pallet_timestamp::{self as timestamp};
//! use frame::prelude::*;
//!
//! #[frame_support::pallet]
//! #[frame::pallet]
//! pub mod pallet {
//! use super::*;
//! use frame_support::pallet_prelude::*;
//! use frame_system::pallet_prelude::*;
//!
//! #[pallet::pallet]
//! pub struct Pallet<T>(_);
Expand Down Expand Up @@ -134,18 +133,24 @@ mod tests;
pub mod weights;

use core::{cmp, result};
/*
use frame_support::traits::{OnTimestampSet, Time, UnixTime};
use sp_runtime::traits::{AtLeast32Bit, SaturatedConversion, Scale, Zero};
*/
use frame::{prelude::*, runtime::prelude::derive_impl, arithmetic::AtLeast32Bit, traits::{Scale, OnTimestampSet, Time, UnixTime}};
use sp_timestamp::{InherentError, InherentType, INHERENT_IDENTIFIER};
pub use weights::WeightInfo;

pub use pallet::*;

#[frame_support::pallet]
// #[frame_support::pallet]
#[frame::pallet]
pub mod pallet {
use super::*;
/*
use frame_support::{derive_impl, pallet_prelude::*};
use frame_system::pallet_prelude::*;
*/

/// Default preludes for [`Config`].
pub mod config_preludes {
Expand All @@ -157,7 +162,8 @@ pub mod pallet {
#[derive_impl(frame_system::config_preludes::TestDefaultConfig, no_aggregated_types)]
impl frame_system::DefaultConfig for TestDefaultConfig {}

#[frame_support::register_default_impl(TestDefaultConfig)]
// #[frame_support::register_default_impl(TestDefaultConfig)]
#[frame::prelude::register_default_impl(TestDefaultConfig)]
impl DefaultConfig for TestDefaultConfig {
type Moment = u64;
type OnTimestampSet = ();
Expand Down Expand Up @@ -354,7 +360,7 @@ impl<T: Config> Time for Pallet<T> {
/// A type that represents a unit of time.
type Moment = T::Moment;

fn now() -> Self::Moment {
fn now() -> <pallet::Pallet<T> as Time>::Moment {
Now::<T>::get()
}
}
Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/timestamp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

use super::*;
use crate as pallet_timestamp;

/*
use frame_support::{derive_impl, parameter_types, traits::ConstU64};
use sp_io::TestExternalities;
use sp_runtime::BuildStorage;

*/
use frame::{prelude::*, runtime::{testing_prelude::BuildStorage, prelude::*}, testing_prelude::TestExternalities};
type Block = frame_system::mocking::MockBlock<Test>;
type Moment = u64;

frame_support::construct_runtime!(
construct_runtime!(
pub enum Test
{
System: frame_system,
Expand Down
4 changes: 3 additions & 1 deletion substrate/frame/timestamp/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
//! Tests for the Timestamp module.

use crate::mock::*;
use frame_support::assert_ok;
//use frame_support::assert_ok;

use frame::testing_prelude::*;

#[test]
fn timestamp_works() {
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/timestamp/src/weights.rs

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