【问题标题】:How to query substrate storage via `.entries` for partial items如何通过“.entries”查询基板存储以获取部分项目
【发布时间】:2020-09-13 17:37:00
【问题描述】:

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

来自 decl_storage 的 sn-p

/// 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,但我想用这个方法来获取全部或部分,这可能吗?

【问题讨论】:

    标签: substrate polkadot-js


    【解决方案1】:

    .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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      • 2014-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多