问题描述
当我知道用于存储数据的ID列表时,如何通过storage
查询.entries
?
decl_storage中的片段
/// PoE Proofs
Proofs get(fn proofs): map hasher(blake2_128_concat) GenericId=> ProofInfo<Proof,T::AccountId,T::BlockNumber>;
打字稿代码,我试图获取仅有的几个条目
type IncomingParam = [StorageKey,ProofInfo]
type SnGenericIds = GenericId[]
export async function getAll (
items: SnGenericIds = []
): Promise<IncomingParam[]> {
const api = getApi()
return await api.query.poe.proofs.entries(items)
}
// items is [ '0x6261666b313332313365616465617364' ]
当我在浏览器中使用polkadot.js应用程序并传递该ID时,我得到了记录,并且只有一个,上面的TS代码返回了所有记录,我已经检查过https://polkadot.js.org/api/start/api.query.other.html#map-keys-entries,并且如果我在上面正确理解了代码应该。工作
我知道multi
,但我想使用此方法来获取全部或部分内容,这是否有可能?
解决方法
.entries(args)
仅可与double_map
一起使用和过滤,其中args
是与double_map
的第一个参数匹配的单个字符串
上面的rust代码没有过滤功能,因此RPC和API将检索所有条目。
因此锈代码如下:
/// PoE Proofs
pub Proofs get(fn proofs): double_map hasher(blake2_128_concat) GenericId,hasher(twox_64_concat) T::AccountId => ProofInfo<Proof,T::AccountId,T::BlockNumber>;
这允许使用以下方法进行过滤
api.query.poe.proofs.entries('0x1231233132312')
可以找到其他信息here