我有一个基板节点启动并运行,存储项目为:value(Hash): Option<AccountId>
。我的目标是提供哈希值(例如,0x0000000000000000000000000000000000000000000000000000000000000001
并获得相应的帐户 ID 作为回报)。
我想通过 RPC 调用执行相同的任务。看完这篇博文后,我意识到我的情况是阅读StorageMaps
,所以我开始运行一些查询。如果我没记错的话,模块是Substratekitties
,存储项是value
。映射将value
是AccountId
。
我打了前两个电话:
util_crypto.xxhashAsHex("Substratekitties", 128)
"0xe4a154b5ba85d6072b187ee66e4fef05"
util_crypto.xxhashAsHex("Value", 128)
"0x6b2f21989c43cc4e06ac1ad3e2027000"
但我对第三次调用编码感到困惑:编码文件 sha256 哈希。怎么做?运行util_crypto.blake2AsHex("0000000000000000000000000000000000000000000000000000000000000001", 256)
"0x16821de47d8b3b0fa4ca43e5db1028d75207cbd1c379a4738144972b105355aa"
将不起作用,也不起作用。
我的意思是说,我在执行此查询时得到“空”值。这是存储结构:
use frame_support::{decl_module, decl_storage, dispatch::result::Result, ensure, StorageMap};
use frame_system::ensure_signed;
use sp_runtime::DispatchError;
// pub trait Trait: balances::Trait {}
pub trait Trait: pallet_balances::Trait {}
decl_storage! {
trait Store for Module<T: Trait> as KittyStorage {
// Value: map T::Hash => Option<T::AccountId>;
// TODO: check whether this is the appropriate datatype(hash).
Value: map hasher(blake2_256) T::Hash => Option<T::AccountId>;
// Balances: map hasher(blake2_256) (T::AssetId, T::AccountId) => T::Balance;
}
}
decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
fn set_value(origin, value: T::Hash) -> Result<(), DispatchError> {
let sender = ensure_signed(origin)?;
ensure!(!<Value<T>>::contains_key(value), "key already exists");
<Value<T>>::insert(value, sender);
Ok(())
}
}
}
更新:我的文字查询:
curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "state_getStorage", "params": ["0x3fd011a1ea758d2e1b46ed3cec43fc86b2f21989c43cc4e06ac1ad3e2027000d3585436436a2253c5163fa0cfe54a648fa533ef32ea10dbd966ac438af77b71"]}' http://localhost:9933/
十六进制查询:
util_crypto.xxhashAsHex("KittyStorage", 128)
"0xe3fd011a1ea758d2e1b46ed3cec43fc8"
util_crypto.xxhashAsHex("Value", 128)
"0x6b2f21989c43cc4e06ac1ad3e2027000"
util_crypto.blake2AsHex("0x0000000000000000000000000000000000000000000000000000000000001234")
"0xd3585436436a2253c5163fa0cfe54a648fa533ef32ea10dbd966ac438af77b71"