通过帐户获取验证者的奖励积分

问题描述

我正在尝试查找属于验证者的奖励积分。我从这里开始:

const activeEra = await api.query.staking.activeEra()

const rewardPoints = await api.query.staking.erasRewardPoints(activeEra.unwrap().index)
const individualRewardPoints = activeEraRewardPoints.individual

现在,看来individualRewardPoints是某种由验证者帐户输入密码的地图,但是我找不到如何获取特定物品的方法(我不想遍历地图)。有一个字符串,我尝试了这些:

const alice = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'

individualRewardPoints.get(alice)
individualRewardPoints.get(Buffer.from(alice))

这看起来很有希望,但仍然行不通:

{ decodeAddress } = require ('@polkadot/keyring')
individualRewardPoints.get(decodeAddress(alice))

它们全部返回undefined。如何获得验证者的奖励积分?

解决方法

我碰到了同样的挑战,不幸的是我没有发现迭代过程。

eraRewardPoints.individuala BTreeMap<AccountId,RewardPoint>,因此密钥应为AccountId。 BTreeMap的内幕是represented by a JS Map,在TS中我们看到它以AccountId作为其键类型。要创建该类型,我们可以执行api.createType('AccountId',alice)。但是,对于我来说,创建类型并使用它来键入无法正常工作。我的猜测是,它将创建一个新对象,而JS无法将其识别为与地图中相同的AccountId对象。

所以我的解决方法是:

for (const [id,points] of eraRewardPoints.individual.entries()) {
  if (id.toString() === validatorId) {
    return points;
  }
}

您可以在substrate-api-sidecar中找到确切的代码,该代码具有一个端点(accounts/{accountId}/staking-payouts),该端点使用在Rust中进行的算术运算得出地址的付款:https://github.com/paritytech/substrate-api-sidecar/blob/ee0a0488bf8100a42e713fc287f08d72394677b9/src/services/accounts/AccountsStakingPayoutsService.ts#L301

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...