首页 > 解决方案 > 如何从 frame_system::Config 访问存储?

问题描述

我正在尝试将utxo.rsSubstrate 的 utxo-workshop 转换为 FRAME v2。

这是一个错误的片段<Number<T>>(因为数字是私人的?)。

#[frame_support::pallet]
pub mod pallet {
    #[pallet::pallet]
    #[pallet::generate_store(pub(super) trait Store)]
    pub struct Pallet<T>(PhantomData<T>);

    #[pallet::config]
    pub trait Config: frame_system::Config {
        /// The overarching event type.
        type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

    }

    fn disperse_reward(authorities: &[H256]) {
      ...

      let hash = BlakeTwo256::hash_of(&(
        &utxo,
        <Number<T>>::get().unwrap().saturated_into::<u64>()
        ));

      ...
    }
}

按照调用block_number()的路线,我相信这相当于FRAME v2 的 block_number 吸气剂。构建运行时时可以访问它:

frame_support::construct_runtime!(
    pub enum Test 
    {
        System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
        ...
    }
);

fn testing() {
   let block_number = System::block_number();
}

但是frame_system::Config,有没有办法在没有的情况下访问 Storage 值construct_runtime!

标签: rustsubstrate

解决方案


一旦构建了运行时,您就可以访问运行时托盘的存储,该过程由宏完成construct_runtime!{}。正如您可以在此处阅读的那样https://substrate.dev/rustdocs/v3.0.0-monthly-2021-05/frame_support/macro.construct_runtime.html 未出现在该宏中的托盘不会成为您的运行时的一部分,因此它的存储将无法访问。


推荐阅读