From 102c73673440199a14a8550d6f9a77a4ccde7aa7 Mon Sep 17 00:00:00 2001 From: bennethxyz Date: Sat, 23 Nov 2024 18:01:23 -0800 Subject: [PATCH] add frame --- Cargo.lock | 8 +----- .../frame/transaction-storage/Cargo.toml | 25 +++---------------- .../transaction-storage/src/benchmarking.rs | 3 +++ .../frame/transaction-storage/src/lib.rs | 10 ++++++-- .../frame/transaction-storage/src/mock.rs | 8 +++--- .../frame/transaction-storage/src/tests.rs | 3 +++ .../frame/transaction-storage/src/weights.rs | 3 ++- 7 files changed, 26 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 182d8f6bacad4..5062feba57c60 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15598,18 +15598,12 @@ name = "pallet-transaction-storage" version = "27.0.0" dependencies = [ "array-bytes", - "frame-benchmarking 28.0.0", - "frame-support 28.0.0", - "frame-system 28.0.0", "log", "pallet-balances 28.0.0", "parity-scale-codec", + "polkadot-sdk-frame 0.1.0", "scale-info", "serde", - "sp-core 28.0.0", - "sp-inherents 26.0.0", - "sp-io 30.0.0", - "sp-runtime 31.0.1", "sp-transaction-storage-proof 26.0.0", ] diff --git a/substrate/frame/transaction-storage/Cargo.toml b/substrate/frame/transaction-storage/Cargo.toml index f5d6bd1c364c4..e85a24af0fd3f 100644 --- a/substrate/frame/transaction-storage/Cargo.toml +++ b/substrate/frame/transaction-storage/Cargo.toml @@ -20,48 +20,31 @@ array-bytes = { optional = true, workspace = true, default-features = true } codec = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { optional = true, workspace = true, default-features = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } +frame = { workspace = true, features = ["experimental", "runtime"] } pallet-balances = { workspace = true } -sp-inherents = { workspace = true } -sp-io = { workspace = true } -sp-runtime = { workspace = true } sp-transaction-storage-proof = { workspace = true } log = { workspace = true } [dev-dependencies] -sp-core = { workspace = true } sp-transaction-storage-proof = { default-features = true, workspace = true } [features] default = ["std"] runtime-benchmarks = [ "array-bytes", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", + "frame/runtime-benchmarks", "pallet-balances/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", ] std = [ "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", + "frame/std", "log/std", "pallet-balances/std", "scale-info/std", "serde", - "sp-core/std", - "sp-inherents/std", - "sp-io/std", - "sp-runtime/std", "sp-transaction-storage-proof/std", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame/try-runtime", "pallet-balances/try-runtime", - "sp-runtime/try-runtime", ] diff --git a/substrate/frame/transaction-storage/src/benchmarking.rs b/substrate/frame/transaction-storage/src/benchmarking.rs index 0b5b0dc994054..892b546a3f606 100644 --- a/substrate/frame/transaction-storage/src/benchmarking.rs +++ b/substrate/frame/transaction-storage/src/benchmarking.rs @@ -21,10 +21,13 @@ use crate::*; use alloc::{vec, vec::Vec}; +/* use frame_benchmarking::v2::*; use frame_support::traits::{Get, OnFinalize, OnInitialize}; use frame_system::{pallet_prelude::BlockNumberFor, EventRecord, Pallet as System, RawOrigin}; use sp_runtime::traits::{Bounded, CheckedDiv, One, Zero}; +*/ +use frame::{benchmarking::prelude::*, arithmetic::{Bounded, One, Zero} , traits::{Get, CheckedDiv}, deps::{frame_system::{pallet_prelude::BlockNumberFor, EventRecord, Pallet as System}}}; use sp_transaction_storage_proof::TransactionStorageProof; // Proof generated from max size storage: diff --git a/substrate/frame/transaction-storage/src/lib.rs b/substrate/frame/transaction-storage/src/lib.rs index 68f24526300d8..2601595fbcaa6 100644 --- a/substrate/frame/transaction-storage/src/lib.rs +++ b/substrate/frame/transaction-storage/src/lib.rs @@ -33,6 +33,7 @@ extern crate alloc; use alloc::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; use core::result; +/* use frame_support::{ dispatch::GetDispatchInfo, traits::{ @@ -42,6 +43,8 @@ use frame_support::{ }, }; use sp_runtime::traits::{BlakeTwo256, Dispatchable, Hash, One, Saturating, Zero}; +*/ +use frame::{deps::{sp_io, sp_runtime}, prelude::*, traits::{Get, IsType, fungible::{hold::Balanced, Inspect, Mutate, MutateHold}, tokens::fungible::Credit, OnUnbalanced, BlakeTwo256, Dispatchable, Hash, One, Saturating, Zero}}; use sp_transaction_storage_proof::{ encode_index, random_chunk, InherentError, TransactionStorageProof, CHUNK_SIZE, INHERENT_IDENTIFIER, @@ -66,7 +69,7 @@ pub const DEFAULT_MAX_BLOCK_TRANSACTIONS: u32 = 512; Encode, Decode, Clone, - sp_runtime::RuntimeDebug, + frame::derive::RuntimeDebug, PartialEq, Eq, scale_info::TypeInfo, @@ -88,11 +91,14 @@ fn num_chunks(bytes: u32) -> u32 { ((bytes as u64 + CHUNK_SIZE as u64 - 1) / CHUNK_SIZE as u64) as u32 } -#[frame_support::pallet] +// #[frame_support::pallet] +#[frame::pallet] pub mod pallet { use super::*; + /* use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; + */ /// A reason for this pallet placing a hold on funds. #[pallet::composite_enum] diff --git a/substrate/frame/transaction-storage/src/mock.rs b/substrate/frame/transaction-storage/src/mock.rs index 73174b73dbacc..38f8a3cfebff4 100644 --- a/substrate/frame/transaction-storage/src/mock.rs +++ b/substrate/frame/transaction-storage/src/mock.rs @@ -21,16 +21,18 @@ use crate::{ self as pallet_transaction_storage, TransactionStorageProof, DEFAULT_MAX_BLOCK_TRANSACTIONS, DEFAULT_MAX_TRANSACTION_SIZE, }; +use frame::{testing_prelude::*, traits::IdentityLookup}; +/* use frame_support::{ derive_impl, traits::{ConstU32, OnFinalize, OnInitialize}, }; use sp_runtime::{traits::IdentityLookup, BuildStorage}; - +*/ pub type Block = frame_system::mocking::MockBlock; // Configure a mock runtime to test the pallet. -frame_support::construct_runtime!( +construct_runtime!( pub enum Test { System: frame_system, @@ -63,7 +65,7 @@ impl pallet_transaction_storage::Config for Test { type MaxTransactionSize = ConstU32<{ DEFAULT_MAX_TRANSACTION_SIZE }>; } -pub fn new_test_ext() -> sp_io::TestExternalities { +pub fn new_test_ext() -> frame::deps::sp_io::TestExternalities { let t = RuntimeGenesisConfig { system: Default::default(), balances: pallet_balances::GenesisConfig:: { diff --git a/substrate/frame/transaction-storage/src/tests.rs b/substrate/frame/transaction-storage/src/tests.rs index b725990e6e121..f9b1baff92489 100644 --- a/substrate/frame/transaction-storage/src/tests.rs +++ b/substrate/frame/transaction-storage/src/tests.rs @@ -19,9 +19,12 @@ use super::{Pallet as TransactionStorage, *}; use crate::mock::*; +use frame::{testing_prelude::*, deps::{frame_system::RawOrigin, sp_runtime::{DispatchError, TokenError::FundsUnavailable}}}; +/* use frame_support::{assert_noop, assert_ok}; use frame_system::RawOrigin; use sp_runtime::{DispatchError, TokenError::FundsUnavailable}; +*/ use sp_transaction_storage_proof::registration::build_proof; const MAX_DATA_SIZE: u32 = DEFAULT_MAX_TRANSACTION_SIZE; diff --git a/substrate/frame/transaction-storage/src/weights.rs b/substrate/frame/transaction-storage/src/weights.rs index 36681f0abd8bd..5d0c578c1bc3c 100644 --- a/substrate/frame/transaction-storage/src/weights.rs +++ b/substrate/frame/transaction-storage/src/weights.rs @@ -46,7 +46,8 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +// use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use frame::weights_prelude::*; use core::marker::PhantomData; /// Weight functions needed for `pallet_transaction_storage`.