如何通过“.entries”查询部分项目的基板存储

How to query substrate storage via `.entries` for partial items

当我知道用于存储数据的 ID 列表时,如何通过 .entries 查询 storage

来自 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 代码 returns 所有记录,我已经检查过 https://polkadot.js.org/api/start/api.query.other.html#map-keys-entries 如果我理解正确,上面的代码应该。工作

我知道 multi 但我想使用此方法获取全部或部分,这可能吗?

.entries(args) 只能与 double_map 一起使用和过滤,其中 args 是与 double_map[= 的第一个参数匹配的单个字符串17=]

上面的 Rust 代码没有过滤,因此 RPC 和 API 将检索所有条目。

所以 rust 代码如下:

/// 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