rust - 如何从 frame_system::Config 访问存储?
问题描述
我正在尝试将utxo.rs
Substrate 的 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!
?
解决方案
一旦构建了运行时,您就可以访问运行时托盘的存储,该过程由宏完成construct_runtime!{}
。正如您可以在此处阅读的那样https://substrate.dev/rustdocs/v3.0.0-monthly-2021-05/frame_support/macro.construct_runtime.html
未出现在该宏中的托盘不会成为您的运行时的一部分,因此它的存储将无法访问。
推荐阅读
- php - Symfony 捆绑配置服务参数
- python - 如何将 Sqlalchemy ORM 查询结果转换为包含关系的单个联接表?
- swift - Swift UIAccessibility 知道之前关注的元素吗?
- docker - 在 windows docker 工具箱上运行融合平台时 kafka 连接数据生成的问题
- android - 导航到另一个 Fragment 时,Fragment 中的 RecyclerView 崩溃
- python - 用于从 FTP 服务器获取文件并复制到我计算机上的特定文件夹中的 Python 代码
- security - 浏览器如何保护进程内存免受 webassembly 编译代码的影响?
- r - 使用 RJSONIO 包 R 将 json 文件转换为数据框
- c# - 如何将 LINQ 中的两个集合与 MS SQL Server 的多个条件最佳组合
- javascript - jQuery .show(); 不在代码中工作,但在控制台中工作?