【问题标题】:How to access Storage from frame_system::Config?如何从 frame_system::Config 访问存储?
【发布时间】:2021-06-09 12:02:13
【问题描述】:

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

这是一个在 <Number<T>> 处出错的 sn-p(因为 Number 是私有的?)。

#[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()的线路,我相信这相当于the block_number getter of FRAME v2。构建运行时即可访问:

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 上的存储值,没有 construct_runtime!

【问题讨论】:

    标签: rust substrate


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 2019-05-25
      • 2020-09-07
      • 1970-01-01
      • 2023-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多