difftreelog
fix separate povinfo RPC
in: master
8 files changed
client/rpc/src/pov_estimate.rsdiffbeforeafterboth--- a/client/rpc/src/pov_estimate.rs
+++ b/client/rpc/src/pov_estimate.rs
@@ -122,7 +122,7 @@
#[rpc(server)]
#[async_trait]
pub trait PovEstimateApi<BlockHash> {
- #[method(name = "unique_estimateExtrinsicPoV")]
+ #[method(name = "povinfo_estimateExtrinsicPoV")]
fn estimate_extrinsic_pov(
&self,
encoded_xts: Vec<Bytes>,
tests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-rpc.ts
+++ b/tests/src/interfaces/augment-api-rpc.ts
@@ -436,6 +436,12 @@
**/
queryInfo: AugmentedRpc<(extrinsic: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<RuntimeDispatchInfoV1>>;
};
+ povinfo: {
+ /**
+ * Estimate PoV size of encoded signed extrinsics
+ **/
+ estimateExtrinsicPoV: AugmentedRpc<(encodedXt: Vec<Bytes> | (Bytes | string | Uint8Array)[], at?: Hash | string | Uint8Array) => Observable<UpPovEstimateRpcPovInfo>>;
+ };
rmrk: {
/**
* Get tokens owned by an account in a collection
@@ -725,10 +731,6 @@
* Get effective collection limits
**/
effectiveCollectionLimits: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<UpDataStructsCollectionLimits>>>;
- /**
- * Estimate PoV size of an encoded extrinsic
- **/
- estimateExtrinsicPoV: AugmentedRpc<(encodedXt: Vec<Bytes> | (Bytes | string | Uint8Array)[], at?: Hash | string | Uint8Array) => Observable<UpPovEstimateRpcPovInfo>>;
/**
* Get the last token ID created in a collection
**/
tests/src/interfaces/definitions.tsdiffbeforeafterboth--- a/tests/src/interfaces/definitions.ts
+++ b/tests/src/interfaces/definitions.ts
@@ -17,4 +17,5 @@
export {default as unique} from './unique/definitions';
export {default as appPromotion} from './appPromotion/definitions';
export {default as rmrk} from './rmrk/definitions';
-export {default as default} from './default/definitions';
\ No newline at end of file
+export {default as povinfo} from './povinfo/definitions';
+export {default as default} from './default/definitions';
tests/src/interfaces/povinfo/definitions.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/interfaces/povinfo/definitions.ts
@@ -0,0 +1,40 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+type RpcParam = {
+ name: string;
+ type: string;
+ isOptional?: true;
+};
+
+const atParam = {name: 'at', type: 'Hash', isOptional: true};
+
+const fun = (description: string, params: RpcParam[], type: string) => ({
+ description,
+ params: [...params, atParam],
+ type,
+});
+
+export default {
+ types: {},
+ rpc: {
+ estimateExtrinsicPoV: fun(
+ 'Estimate PoV size of encoded signed extrinsics',
+ [{name: 'encodedXt', type: 'Vec<Bytes>'}],
+ 'UpPovEstimateRpcPovInfo',
+ ),
+ },
+};
tests/src/interfaces/povinfo/index.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/interfaces/povinfo/index.ts
@@ -0,0 +1,4 @@
+// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
+/* eslint-disable */
+
+export * from './types';
tests/src/interfaces/povinfo/types.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/interfaces/povinfo/types.ts
@@ -0,0 +1,4 @@
+// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
+/* eslint-disable */
+
+export type PHANTOM_POVINFO = 'povinfo';
tests/src/interfaces/types.tsdiffbeforeafterboth--- a/tests/src/interfaces/types.ts
+++ b/tests/src/interfaces/types.ts
@@ -4,4 +4,5 @@
export * from './unique/types';
export * from './appPromotion/types';
export * from './rmrk/types';
+export * from './povinfo/types';
export * from './default/types';
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {stringToU8a} from '@polkadot/util';5import {encodeAddress, mnemonicGenerate} from '@polkadot/util-crypto';6import {UniqueHelper, MoonbeamHelper, ChainHelperBase, AcalaHelper, RelayHelper, WestmintHelper} from './unique';7import {ApiPromise, Keyring, WsProvider} from '@polkadot/api';8import * as defs from '../../interfaces/definitions';9import {IKeyringPair} from '@polkadot/types/types';10import {EventRecord} from '@polkadot/types/interfaces';11import {ICrossAccountId, IPovInfo, TSigner} from './types';12import {FrameSystemEventRecord} from '@polkadot/types/lookup';13import {VoidFn} from '@polkadot/api/types';14import {Pallets} from '..';15import {spawnSync} from 'child_process';1617export class SilentLogger {18 log(_msg: any, _level: any): void { }19 level = {20 ERROR: 'ERROR' as const,21 WARNING: 'WARNING' as const,22 INFO: 'INFO' as const,23 };24}2526export class SilentConsole {27 // TODO: Remove, this is temporary: Filter unneeded API output28 // (Jaco promised it will be removed in the next version)29 consoleErr: any;30 consoleLog: any;31 consoleWarn: any;3233 constructor() {34 this.consoleErr = console.error;35 this.consoleLog = console.log;36 this.consoleWarn = console.warn;37 }3839 enable() {40 const outFn = (printer: any) => (...args: any[]) => {41 for (const arg of args) {42 if (typeof arg !== 'string')43 continue;44 if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis:') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')45 return;46 }47 printer(...args);48 };4950 console.error = outFn(this.consoleErr.bind(console));51 console.log = outFn(this.consoleLog.bind(console));52 console.warn = outFn(this.consoleWarn.bind(console));53 }5455 disable() {56 console.error = this.consoleErr;57 console.log = this.consoleLog;58 console.warn = this.consoleWarn;59 }60}6162export class DevUniqueHelper extends UniqueHelper {63 /**64 * Arrange methods for tests65 */66 arrange: ArrangeGroup;67 wait: WaitGroup;68 admin: AdminGroup;69 testUtils: TestUtilGroup;7071 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {72 options.helperBase = options.helperBase ?? DevUniqueHelper;7374 super(logger, options);75 this.arrange = new ArrangeGroup(this);76 this.wait = new WaitGroup(this);77 this.admin = new AdminGroup(this);78 this.testUtils = new TestUtilGroup(this);79 }8081 async connect(wsEndpoint: string, _listeners?: any): Promise<void> {82 const wsProvider = new WsProvider(wsEndpoint);83 this.api = new ApiPromise({84 provider: wsProvider,85 signedExtensions: {86 ContractHelpers: {87 extrinsic: {},88 payload: {},89 },90 CheckMaintenance: {91 extrinsic: {},92 payload: {},93 },94 FakeTransactionFinalizer: {95 extrinsic: {},96 payload: {},97 },98 },99 rpc: {100 unique: defs.unique.rpc,101 appPromotion: defs.appPromotion.rpc,102 rmrk: defs.rmrk.rpc,103 eth: {104 feeHistory: {105 description: 'Dummy',106 params: [],107 type: 'u8',108 },109 maxPriorityFeePerGas: {110 description: 'Dummy',111 params: [],112 type: 'u8',113 },114 },115 },116 });117 await this.api.isReadyOrError;118 this.network = await UniqueHelper.detectNetwork(this.api);119 }120}121122export class DevRelayHelper extends RelayHelper {123 wait: WaitGroup;124125 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {126 options.helperBase = options.helperBase ?? DevRelayHelper;127128 super(logger, options);129 this.wait = new WaitGroup(this);130 }131}132133export class DevWestmintHelper extends WestmintHelper {134 wait: WaitGroup;135136 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {137 options.helperBase = options.helperBase ?? DevWestmintHelper;138139 super(logger, options);140 this.wait = new WaitGroup(this);141 }142}143144export class DevStatemineHelper extends DevWestmintHelper {}145146export class DevStatemintHelper extends DevWestmintHelper {}147148export class DevMoonbeamHelper extends MoonbeamHelper {149 account: MoonbeamAccountGroup;150 wait: WaitGroup;151152 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {153 options.helperBase = options.helperBase ?? DevMoonbeamHelper;154 options.notePreimagePallet = options.notePreimagePallet ?? 'democracy';155156 super(logger, options);157 this.account = new MoonbeamAccountGroup(this);158 this.wait = new WaitGroup(this);159 }160}161162export class DevMoonriverHelper extends DevMoonbeamHelper {163 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {164 options.notePreimagePallet = options.notePreimagePallet ?? 'preimage';165 super(logger, options);166 }167}168169export class DevAcalaHelper extends AcalaHelper {170 wait: WaitGroup;171172 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {173 options.helperBase = options.helperBase ?? DevAcalaHelper;174175 super(logger, options);176 this.wait = new WaitGroup(this);177 }178}179180export class DevKaruraHelper extends DevAcalaHelper {}181182class ArrangeGroup {183 helper: DevUniqueHelper;184185 scheduledIdSlider = 0;186187 constructor(helper: DevUniqueHelper) {188 this.helper = helper;189 }190191 /**192 * Generates accounts with the specified UNQ token balance193 * @param balances balances for generated accounts. Each balance will be multiplied by the token nominal.194 * @param donor donor account for balances195 * @returns array of newly created accounts196 * @example const [acc1, acc2, acc3] = await createAccounts([0n, 10n, 20n], donor);197 */198 createAccounts = async (balances: bigint[], donor: IKeyringPair): Promise<IKeyringPair[]> => {199 let nonce = await this.helper.chain.getNonce(donor.address);200 const wait = new WaitGroup(this.helper);201 const ss58Format = this.helper.chain.getChainProperties().ss58Format;202 const tokenNominal = this.helper.balance.getOneTokenNominal();203 const transactions = [];204 const accounts: IKeyringPair[] = [];205 for (const balance of balances) {206 const recipient = this.helper.util.fromSeed(mnemonicGenerate(), ss58Format);207 accounts.push(recipient);208 if (balance !== 0n) {209 const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recipient.address}, balance * tokenNominal]);210 transactions.push(this.helper.signTransaction(donor, tx, {nonce}, 'account generation'));211 nonce++;212 }213 }214215 await Promise.all(transactions).catch(_e => {});216217 //#region TODO remove this region, when nonce problem will be solved218 const checkBalances = async () => {219 let isSuccess = true;220 for (let i = 0; i < balances.length; i++) {221 const balance = await this.helper.balance.getSubstrate(accounts[i].address);222 if (balance !== balances[i] * tokenNominal) {223 isSuccess = false;224 break;225 }226 }227 return isSuccess;228 };229230 let accountsCreated = false;231 const maxBlocksChecked = await this.helper.arrange.isDevNode() ? 50 : 5;232 // checkBalances retry up to 5-50 blocks233 for (let index = 0; index < maxBlocksChecked; index++) {234 accountsCreated = await checkBalances();235 if(accountsCreated) break;236 await wait.newBlocks(1);237 }238239 if (!accountsCreated) throw Error('Accounts generation failed');240 //#endregion241242 return accounts;243 };244245 // TODO combine this method and createAccounts into one246 createCrowd = async (accountsToCreate: number, withBalance: bigint, donor: IKeyringPair): Promise<IKeyringPair[]> => {247 const createAsManyAsCan = async () => {248 let transactions: any = [];249 const accounts: IKeyringPair[] = [];250 let nonce = await this.helper.chain.getNonce(donor.address);251 const tokenNominal = this.helper.balance.getOneTokenNominal();252 for (let i = 0; i < accountsToCreate; i++) {253 if (i === 500) { // if there are too many accounts to create254 await Promise.allSettled(transactions); // wait while first 500 (should be 100 for devnode) tx will be settled255 transactions = []; //256 nonce = await this.helper.chain.getNonce(donor.address); // update nonce257 }258 const recepient = this.helper.util.fromSeed(mnemonicGenerate());259 accounts.push(recepient);260 if (withBalance !== 0n) {261 const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recepient.address}, withBalance * tokenNominal]);262 transactions.push(this.helper.signTransaction(donor, tx, {nonce}, 'account generation'));263 nonce++;264 }265 }266267 const fullfilledAccounts = [];268 await Promise.allSettled(transactions);269 for (const account of accounts) {270 const accountBalance = await this.helper.balance.getSubstrate(account.address);271 if (accountBalance === withBalance * tokenNominal) {272 fullfilledAccounts.push(account);273 }274 }275 return fullfilledAccounts;276 };277278279 const crowd: IKeyringPair[] = [];280 // do up to 5 retries281 for (let index = 0; index < 5 && accountsToCreate !== 0; index++) {282 const asManyAsCan = await createAsManyAsCan();283 crowd.push(...asManyAsCan);284 accountsToCreate -= asManyAsCan.length;285 }286287 if (accountsToCreate !== 0) throw Error(`Crowd generation failed: ${accountsToCreate} accounts left`);288289 return crowd;290 };291292 isDevNode = async () => {293 let blockNumber = (await this.helper.callRpc('api.query.system.number')).toJSON();294 if (blockNumber == 0) {295 await this.helper.wait.newBlocks(1);296 blockNumber = (await this.helper.callRpc('api.query.system.number')).toJSON();297 }298 const block2 = await this.helper.callRpc('api.rpc.chain.getBlock', [await this.helper.callRpc('api.rpc.chain.getBlockHash', [blockNumber])]);299 const block1 = await this.helper.callRpc('api.rpc.chain.getBlock', [await this.helper.callRpc('api.rpc.chain.getBlockHash', [blockNumber - 1])]);300 const findCreationDate = (block: any) => {301 const humanBlock = block.toHuman();302 let date;303 humanBlock.block.extrinsics.forEach((ext: any) => {304 if(ext.method.section === 'timestamp') {305 date = Number(ext.method.args.now.replaceAll(',', ''));306 }307 });308 return date;309 };310 const block1date = await findCreationDate(block1);311 const block2date = await findCreationDate(block2);312 if(block2date! - block1date! < 9000) return true;313 };314315 async calculcateFee(payer: ICrossAccountId, promise: () => Promise<any>): Promise<bigint> {316 const address = payer.Substrate ? payer.Substrate : await this.helper.address.ethToSubstrate(payer.Ethereum!);317 let balance = await this.helper.balance.getSubstrate(address);318319 await promise();320321 balance -= await this.helper.balance.getSubstrate(address);322323 return balance;324 }325326 async calculatePoVInfo(txs: any[]): Promise<IPovInfo> {327 const rawPovInfo = await this.helper.callRpc('api.rpc.unique.estimateExtrinsicPoV', [txs]);328329 const kvJson: {[key: string]: string} = {};330331 for (const kv of rawPovInfo.keyValues) {332 kvJson[kv.key.toHex()] = kv.value.toHex();333 }334335 const kvStr = JSON.stringify(kvJson);336337 const chainql = spawnSync(338 'chainql', 339 [340 `--tla-code=data=${kvStr}`,341 '-e', 'function(data) cql.dump(cql.chain("wss://ws-opal.unique.network:443").latest._meta, data, {omit_empty:true})',342 ],343 );344345 return {346 proofSize: rawPovInfo.proofSize.toNumber(),347 compactProofSize: rawPovInfo.compactProofSize.toNumber(),348 compressedProofSize: rawPovInfo.compressedProofSize.toNumber(),349 results: rawPovInfo.results,350 kv: JSON.parse(chainql.stdout.toString()),351 };352 }353354 calculatePalletAddress(palletId: any) {355 const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));356 return encodeAddress(address, this.helper.chain.getChainProperties().ss58Format);357 }358359 makeScheduledIds(num: number): string[] {360 function makeId(slider: number) {361 const scheduledIdSize = 64;362 const hexId = slider.toString(16);363 const prefixSize = scheduledIdSize - hexId.length;364365 const scheduledId = '0x' + '0'.repeat(prefixSize) + hexId;366367 return scheduledId;368 }369370 const ids = [];371 for (let i = 0; i < num; i++) {372 ids.push(makeId(this.scheduledIdSlider));373 this.scheduledIdSlider += 1;374 }375376 return ids;377 }378379 makeScheduledId(): string {380 return (this.makeScheduledIds(1))[0];381 }382383 async captureEvents(eventSection: string, eventMethod: string): Promise<EventCapture> {384 const capture = new EventCapture(this.helper, eventSection, eventMethod);385 await capture.startCapture();386387 return capture;388 }389}390391class MoonbeamAccountGroup {392 helper: MoonbeamHelper;393394 keyring: Keyring;395 _alithAccount: IKeyringPair;396 _baltatharAccount: IKeyringPair;397 _dorothyAccount: IKeyringPair;398399 constructor(helper: MoonbeamHelper) {400 this.helper = helper;401402 this.keyring = new Keyring({type: 'ethereum'});403 const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';404 const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';405 const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';406407 this._alithAccount = this.keyring.addFromUri(alithPrivateKey, undefined, 'ethereum');408 this._baltatharAccount = this.keyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');409 this._dorothyAccount = this.keyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');410 }411412 alithAccount() {413 return this._alithAccount;414 }415416 baltatharAccount() {417 return this._baltatharAccount;418 }419420 dorothyAccount() {421 return this._dorothyAccount;422 }423424 create() {425 return this.keyring.addFromUri(mnemonicGenerate());426 }427}428429class WaitGroup {430 helper: ChainHelperBase;431432 constructor(helper: ChainHelperBase) {433 this.helper = helper;434 }435436 sleep(milliseconds: number) {437 return new Promise((resolve) => setTimeout(resolve, milliseconds));438 }439440 private async waitWithTimeout(promise: Promise<any>, timeout: number) {441 let isBlock = false;442 promise.then(() => isBlock = true).catch(() => isBlock = true);443 let totalTime = 0;444 const step = 100;445 while(!isBlock) {446 await this.sleep(step);447 totalTime += step;448 if(totalTime >= timeout) throw Error('Blocks production failed');449 }450 return promise;451 }452453 /**454 * Wait for specified number of blocks455 * @param blocksCount number of blocks to wait456 * @returns457 */458 async newBlocks(blocksCount = 1, timeout?: number): Promise<void> {459 timeout = timeout ?? blocksCount * 60_000;460 // eslint-disable-next-line no-async-promise-executor461 const promise = new Promise<void>(async (resolve) => {462 const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads(() => {463 if (blocksCount > 0) {464 blocksCount--;465 } else {466 unsubscribe();467 resolve();468 }469 });470 });471 await this.waitWithTimeout(promise, timeout);472 return promise;473 }474475 async forParachainBlockNumber(blockNumber: bigint | number, timeout?: number) {476 timeout = timeout ?? 30 * 60 * 1000;477 // eslint-disable-next-line no-async-promise-executor478 const promise = new Promise<void>(async (resolve) => {479 const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads((data: any) => {480 if (data.number.toNumber() >= blockNumber) {481 unsubscribe();482 resolve();483 }484 });485 });486 await this.waitWithTimeout(promise, timeout);487 return promise;488 }489490 async forRelayBlockNumber(blockNumber: bigint | number, timeout?: number) {491 timeout = timeout ?? 30 * 60 * 1000;492 // eslint-disable-next-line no-async-promise-executor493 const promise = new Promise<void>(async (resolve) => {494 const unsubscribe = await this.helper.getApi().query.parachainSystem.validationData((data: any) => {495 if (data.value.relayParentNumber.toNumber() >= blockNumber) {496 // @ts-ignore497 unsubscribe();498 resolve();499 }500 });501 });502 await this.waitWithTimeout(promise, timeout);503 return promise;504 }505506 noScheduledTasks() {507 const api = this.helper.getApi();508509 // eslint-disable-next-line no-async-promise-executor510 const promise = new Promise<void>(async resolve => {511 const unsubscribe = await api.rpc.chain.subscribeNewHeads(async () => {512 const areThereScheduledTasks = await api.query.scheduler.lookup.entries();513514 if(areThereScheduledTasks.length == 0) {515 unsubscribe();516 resolve();517 }518 });519 });520521 return promise;522 }523524 event(maxBlocksToWait: number, eventSection: string, eventMethod: string) {525 // eslint-disable-next-line no-async-promise-executor526 const promise = new Promise<EventRecord | null>(async (resolve) => {527 const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads(async header => {528 const blockNumber = header.number.toHuman();529 const blockHash = header.hash;530 const eventIdStr = `${eventSection}.${eventMethod}`;531 const waitLimitStr = `wait blocks remaining: ${maxBlocksToWait}`;532533 this.helper.logger.log(`[Block #${blockNumber}] Waiting for event \`${eventIdStr}\` (${waitLimitStr})`);534535 const apiAt = await this.helper.getApi().at(blockHash);536 const eventRecords = (await apiAt.query.system.events()) as any;537538 const neededEvent = eventRecords.toArray().find((r: FrameSystemEventRecord) => {539 return r.event.section == eventSection && r.event.method == eventMethod;540 });541542 if (neededEvent) {543 unsubscribe();544 resolve(neededEvent);545 } else if (maxBlocksToWait > 0) {546 maxBlocksToWait--;547 } else {548 this.helper.logger.log(`Event \`${eventIdStr}\` is NOT found`);549 unsubscribe();550 resolve(null);551 }552 });553 });554 return promise;555 }556}557558class TestUtilGroup {559 helper: DevUniqueHelper;560561 constructor(helper: DevUniqueHelper) {562 this.helper = helper;563 }564565 async enable() {566 if (this.helper.fetchMissingPalletNames([Pallets.TestUtils]).length != 0) {567 return;568 }569570 const signer = this.helper.util.fromSeed('//Alice');571 await this.helper.getSudo<DevUniqueHelper>().executeExtrinsic(signer, 'api.tx.testUtils.enable', [], true);572 }573574 async setTestValue(signer: TSigner, testVal: number) {575 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.setTestValue', [testVal], true);576 }577578 async incTestValue(signer: TSigner) {579 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.incTestValue', [], true);580 }581582 async setTestValueAndRollback(signer: TSigner, testVal: number) {583 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.setTestValueAndRollback', [testVal], true);584 }585586 async testValue(blockIdx?: number) {587 const api = blockIdx588 ? await this.helper.getApi().at(await this.helper.callRpc('api.rpc.chain.getBlockHash', [blockIdx]))589 : this.helper.getApi();590591 return (await api.query.testUtils.testValue()).toJSON();592 }593594 async justTakeFee(signer: TSigner) {595 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.justTakeFee', [], true);596 }597598 async selfCancelingInc(signer: TSigner, scheduledId: string, maxTestVal: number) {599 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.selfCancelingInc', [scheduledId, maxTestVal], true);600 }601}602603class EventCapture {604 helper: DevUniqueHelper;605 eventSection: string;606 eventMethod: string;607 events: EventRecord[] = [];608 unsubscribe: VoidFn | null = null;609610 constructor(611 helper: DevUniqueHelper,612 eventSection: string,613 eventMethod: string,614 ) {615 this.helper = helper;616 this.eventSection = eventSection;617 this.eventMethod = eventMethod;618 }619620 async startCapture() {621 this.stopCapture();622 this.unsubscribe = (await this.helper.getApi().query.system.events((eventRecords: FrameSystemEventRecord[]) => {623 const newEvents = eventRecords.filter(r => {624 return r.event.section == this.eventSection && r.event.method == this.eventMethod;625 });626627 this.events.push(...newEvents);628 })) as any;629 }630631 stopCapture() {632 if (this.unsubscribe !== null) {633 this.unsubscribe();634 }635 }636637 extractCapturedEvents() {638 return this.events;639 }640}641642class AdminGroup {643 helper: UniqueHelper;644645 constructor(helper: UniqueHelper) {646 this.helper = helper;647 }648649 async payoutStakers(signer: IKeyringPair, stakersToPayout: number) {650 const payoutResult = await this.helper.executeExtrinsic(signer, 'api.tx.appPromotion.payoutStakers', [stakersToPayout], true);651 return payoutResult.result.events.filter(e => e.event.method === 'StakingRecalculation').map(e => {652 return {653 staker: e.event.data[0].toString(),654 stake: e.event.data[1].toBigInt(),655 payout: e.event.data[2].toBigInt(),656 };657 });658 }659}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {stringToU8a} from '@polkadot/util';5import {encodeAddress, mnemonicGenerate} from '@polkadot/util-crypto';6import {UniqueHelper, MoonbeamHelper, ChainHelperBase, AcalaHelper, RelayHelper, WestmintHelper} from './unique';7import {ApiPromise, Keyring, WsProvider} from '@polkadot/api';8import * as defs from '../../interfaces/definitions';9import {IKeyringPair} from '@polkadot/types/types';10import {EventRecord} from '@polkadot/types/interfaces';11import {ICrossAccountId, IPovInfo, TSigner} from './types';12import {FrameSystemEventRecord} from '@polkadot/types/lookup';13import {VoidFn} from '@polkadot/api/types';14import {Pallets} from '..';15import {spawnSync} from 'child_process';1617export class SilentLogger {18 log(_msg: any, _level: any): void { }19 level = {20 ERROR: 'ERROR' as const,21 WARNING: 'WARNING' as const,22 INFO: 'INFO' as const,23 };24}2526export class SilentConsole {27 // TODO: Remove, this is temporary: Filter unneeded API output28 // (Jaco promised it will be removed in the next version)29 consoleErr: any;30 consoleLog: any;31 consoleWarn: any;3233 constructor() {34 this.consoleErr = console.error;35 this.consoleLog = console.log;36 this.consoleWarn = console.warn;37 }3839 enable() {40 const outFn = (printer: any) => (...args: any[]) => {41 for (const arg of args) {42 if (typeof arg !== 'string')43 continue;44 if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis:') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')45 return;46 }47 printer(...args);48 };4950 console.error = outFn(this.consoleErr.bind(console));51 console.log = outFn(this.consoleLog.bind(console));52 console.warn = outFn(this.consoleWarn.bind(console));53 }5455 disable() {56 console.error = this.consoleErr;57 console.log = this.consoleLog;58 console.warn = this.consoleWarn;59 }60}6162export class DevUniqueHelper extends UniqueHelper {63 /**64 * Arrange methods for tests65 */66 arrange: ArrangeGroup;67 wait: WaitGroup;68 admin: AdminGroup;69 testUtils: TestUtilGroup;7071 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {72 options.helperBase = options.helperBase ?? DevUniqueHelper;7374 super(logger, options);75 this.arrange = new ArrangeGroup(this);76 this.wait = new WaitGroup(this);77 this.admin = new AdminGroup(this);78 this.testUtils = new TestUtilGroup(this);79 }8081 async connect(wsEndpoint: string, _listeners?: any): Promise<void> {82 const wsProvider = new WsProvider(wsEndpoint);83 this.api = new ApiPromise({84 provider: wsProvider,85 signedExtensions: {86 ContractHelpers: {87 extrinsic: {},88 payload: {},89 },90 CheckMaintenance: {91 extrinsic: {},92 payload: {},93 },94 FakeTransactionFinalizer: {95 extrinsic: {},96 payload: {},97 },98 },99 rpc: {100 unique: defs.unique.rpc,101 appPromotion: defs.appPromotion.rpc,102 povinfo: defs.povinfo.rpc,103 rmrk: defs.rmrk.rpc,104 eth: {105 feeHistory: {106 description: 'Dummy',107 params: [],108 type: 'u8',109 },110 maxPriorityFeePerGas: {111 description: 'Dummy',112 params: [],113 type: 'u8',114 },115 },116 },117 });118 await this.api.isReadyOrError;119 this.network = await UniqueHelper.detectNetwork(this.api);120 }121}122123export class DevRelayHelper extends RelayHelper {124 wait: WaitGroup;125126 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {127 options.helperBase = options.helperBase ?? DevRelayHelper;128129 super(logger, options);130 this.wait = new WaitGroup(this);131 }132}133134export class DevWestmintHelper extends WestmintHelper {135 wait: WaitGroup;136137 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {138 options.helperBase = options.helperBase ?? DevWestmintHelper;139140 super(logger, options);141 this.wait = new WaitGroup(this);142 }143}144145export class DevStatemineHelper extends DevWestmintHelper {}146147export class DevStatemintHelper extends DevWestmintHelper {}148149export class DevMoonbeamHelper extends MoonbeamHelper {150 account: MoonbeamAccountGroup;151 wait: WaitGroup;152153 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {154 options.helperBase = options.helperBase ?? DevMoonbeamHelper;155 options.notePreimagePallet = options.notePreimagePallet ?? 'democracy';156157 super(logger, options);158 this.account = new MoonbeamAccountGroup(this);159 this.wait = new WaitGroup(this);160 }161}162163export class DevMoonriverHelper extends DevMoonbeamHelper {164 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {165 options.notePreimagePallet = options.notePreimagePallet ?? 'preimage';166 super(logger, options);167 }168}169170export class DevAcalaHelper extends AcalaHelper {171 wait: WaitGroup;172173 constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {174 options.helperBase = options.helperBase ?? DevAcalaHelper;175176 super(logger, options);177 this.wait = new WaitGroup(this);178 }179}180181export class DevKaruraHelper extends DevAcalaHelper {}182183class ArrangeGroup {184 helper: DevUniqueHelper;185186 scheduledIdSlider = 0;187188 constructor(helper: DevUniqueHelper) {189 this.helper = helper;190 }191192 /**193 * Generates accounts with the specified UNQ token balance194 * @param balances balances for generated accounts. Each balance will be multiplied by the token nominal.195 * @param donor donor account for balances196 * @returns array of newly created accounts197 * @example const [acc1, acc2, acc3] = await createAccounts([0n, 10n, 20n], donor);198 */199 createAccounts = async (balances: bigint[], donor: IKeyringPair): Promise<IKeyringPair[]> => {200 let nonce = await this.helper.chain.getNonce(donor.address);201 const wait = new WaitGroup(this.helper);202 const ss58Format = this.helper.chain.getChainProperties().ss58Format;203 const tokenNominal = this.helper.balance.getOneTokenNominal();204 const transactions = [];205 const accounts: IKeyringPair[] = [];206 for (const balance of balances) {207 const recipient = this.helper.util.fromSeed(mnemonicGenerate(), ss58Format);208 accounts.push(recipient);209 if (balance !== 0n) {210 const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recipient.address}, balance * tokenNominal]);211 transactions.push(this.helper.signTransaction(donor, tx, {nonce}, 'account generation'));212 nonce++;213 }214 }215216 await Promise.all(transactions).catch(_e => {});217218 //#region TODO remove this region, when nonce problem will be solved219 const checkBalances = async () => {220 let isSuccess = true;221 for (let i = 0; i < balances.length; i++) {222 const balance = await this.helper.balance.getSubstrate(accounts[i].address);223 if (balance !== balances[i] * tokenNominal) {224 isSuccess = false;225 break;226 }227 }228 return isSuccess;229 };230231 let accountsCreated = false;232 const maxBlocksChecked = await this.helper.arrange.isDevNode() ? 50 : 5;233 // checkBalances retry up to 5-50 blocks234 for (let index = 0; index < maxBlocksChecked; index++) {235 accountsCreated = await checkBalances();236 if(accountsCreated) break;237 await wait.newBlocks(1);238 }239240 if (!accountsCreated) throw Error('Accounts generation failed');241 //#endregion242243 return accounts;244 };245246 // TODO combine this method and createAccounts into one247 createCrowd = async (accountsToCreate: number, withBalance: bigint, donor: IKeyringPair): Promise<IKeyringPair[]> => {248 const createAsManyAsCan = async () => {249 let transactions: any = [];250 const accounts: IKeyringPair[] = [];251 let nonce = await this.helper.chain.getNonce(donor.address);252 const tokenNominal = this.helper.balance.getOneTokenNominal();253 for (let i = 0; i < accountsToCreate; i++) {254 if (i === 500) { // if there are too many accounts to create255 await Promise.allSettled(transactions); // wait while first 500 (should be 100 for devnode) tx will be settled256 transactions = []; //257 nonce = await this.helper.chain.getNonce(donor.address); // update nonce258 }259 const recepient = this.helper.util.fromSeed(mnemonicGenerate());260 accounts.push(recepient);261 if (withBalance !== 0n) {262 const tx = this.helper.constructApiCall('api.tx.balances.transfer', [{Id: recepient.address}, withBalance * tokenNominal]);263 transactions.push(this.helper.signTransaction(donor, tx, {nonce}, 'account generation'));264 nonce++;265 }266 }267268 const fullfilledAccounts = [];269 await Promise.allSettled(transactions);270 for (const account of accounts) {271 const accountBalance = await this.helper.balance.getSubstrate(account.address);272 if (accountBalance === withBalance * tokenNominal) {273 fullfilledAccounts.push(account);274 }275 }276 return fullfilledAccounts;277 };278279280 const crowd: IKeyringPair[] = [];281 // do up to 5 retries282 for (let index = 0; index < 5 && accountsToCreate !== 0; index++) {283 const asManyAsCan = await createAsManyAsCan();284 crowd.push(...asManyAsCan);285 accountsToCreate -= asManyAsCan.length;286 }287288 if (accountsToCreate !== 0) throw Error(`Crowd generation failed: ${accountsToCreate} accounts left`);289290 return crowd;291 };292293 isDevNode = async () => {294 let blockNumber = (await this.helper.callRpc('api.query.system.number')).toJSON();295 if (blockNumber == 0) {296 await this.helper.wait.newBlocks(1);297 blockNumber = (await this.helper.callRpc('api.query.system.number')).toJSON();298 }299 const block2 = await this.helper.callRpc('api.rpc.chain.getBlock', [await this.helper.callRpc('api.rpc.chain.getBlockHash', [blockNumber])]);300 const block1 = await this.helper.callRpc('api.rpc.chain.getBlock', [await this.helper.callRpc('api.rpc.chain.getBlockHash', [blockNumber - 1])]);301 const findCreationDate = (block: any) => {302 const humanBlock = block.toHuman();303 let date;304 humanBlock.block.extrinsics.forEach((ext: any) => {305 if(ext.method.section === 'timestamp') {306 date = Number(ext.method.args.now.replaceAll(',', ''));307 }308 });309 return date;310 };311 const block1date = await findCreationDate(block1);312 const block2date = await findCreationDate(block2);313 if(block2date! - block1date! < 9000) return true;314 };315316 async calculcateFee(payer: ICrossAccountId, promise: () => Promise<any>): Promise<bigint> {317 const address = payer.Substrate ? payer.Substrate : await this.helper.address.ethToSubstrate(payer.Ethereum!);318 let balance = await this.helper.balance.getSubstrate(address);319320 await promise();321322 balance -= await this.helper.balance.getSubstrate(address);323324 return balance;325 }326327 async calculatePoVInfo(txs: any[]): Promise<IPovInfo> {328 const rawPovInfo = await this.helper.callRpc('api.rpc.povinfo.estimateExtrinsicPoV', [txs]);329330 const kvJson: {[key: string]: string} = {};331332 for (const kv of rawPovInfo.keyValues) {333 kvJson[kv.key.toHex()] = kv.value.toHex();334 }335336 const kvStr = JSON.stringify(kvJson);337338 const chainql = spawnSync(339 'chainql', 340 [341 `--tla-code=data=${kvStr}`,342 '-e', 'function(data) cql.dump(cql.chain("wss://ws-opal.unique.network:443").latest._meta, data, {omit_empty:true})',343 ],344 );345346 if (!chainql.stdout) {347 throw Error('unable to get an output from the `chainql`');348 }349350 return {351 proofSize: rawPovInfo.proofSize.toNumber(),352 compactProofSize: rawPovInfo.compactProofSize.toNumber(),353 compressedProofSize: rawPovInfo.compressedProofSize.toNumber(),354 results: rawPovInfo.results,355 kv: JSON.parse(chainql.stdout.toString()),356 };357 }358359 calculatePalletAddress(palletId: any) {360 const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));361 return encodeAddress(address, this.helper.chain.getChainProperties().ss58Format);362 }363364 makeScheduledIds(num: number): string[] {365 function makeId(slider: number) {366 const scheduledIdSize = 64;367 const hexId = slider.toString(16);368 const prefixSize = scheduledIdSize - hexId.length;369370 const scheduledId = '0x' + '0'.repeat(prefixSize) + hexId;371372 return scheduledId;373 }374375 const ids = [];376 for (let i = 0; i < num; i++) {377 ids.push(makeId(this.scheduledIdSlider));378 this.scheduledIdSlider += 1;379 }380381 return ids;382 }383384 makeScheduledId(): string {385 return (this.makeScheduledIds(1))[0];386 }387388 async captureEvents(eventSection: string, eventMethod: string): Promise<EventCapture> {389 const capture = new EventCapture(this.helper, eventSection, eventMethod);390 await capture.startCapture();391392 return capture;393 }394}395396class MoonbeamAccountGroup {397 helper: MoonbeamHelper;398399 keyring: Keyring;400 _alithAccount: IKeyringPair;401 _baltatharAccount: IKeyringPair;402 _dorothyAccount: IKeyringPair;403404 constructor(helper: MoonbeamHelper) {405 this.helper = helper;406407 this.keyring = new Keyring({type: 'ethereum'});408 const alithPrivateKey = '0x5fb92d6e98884f76de468fa3f6278f8807c48bebc13595d45af5bdc4da702133';409 const baltatharPrivateKey = '0x8075991ce870b93a8870eca0c0f91913d12f47948ca0fd25b49c6fa7cdbeee8b';410 const dorothyPrivateKey = '0x39539ab1876910bbf3a223d84a29e28f1cb4e2e456503e7e91ed39b2e7223d68';411412 this._alithAccount = this.keyring.addFromUri(alithPrivateKey, undefined, 'ethereum');413 this._baltatharAccount = this.keyring.addFromUri(baltatharPrivateKey, undefined, 'ethereum');414 this._dorothyAccount = this.keyring.addFromUri(dorothyPrivateKey, undefined, 'ethereum');415 }416417 alithAccount() {418 return this._alithAccount;419 }420421 baltatharAccount() {422 return this._baltatharAccount;423 }424425 dorothyAccount() {426 return this._dorothyAccount;427 }428429 create() {430 return this.keyring.addFromUri(mnemonicGenerate());431 }432}433434class WaitGroup {435 helper: ChainHelperBase;436437 constructor(helper: ChainHelperBase) {438 this.helper = helper;439 }440441 sleep(milliseconds: number) {442 return new Promise((resolve) => setTimeout(resolve, milliseconds));443 }444445 private async waitWithTimeout(promise: Promise<any>, timeout: number) {446 let isBlock = false;447 promise.then(() => isBlock = true).catch(() => isBlock = true);448 let totalTime = 0;449 const step = 100;450 while(!isBlock) {451 await this.sleep(step);452 totalTime += step;453 if(totalTime >= timeout) throw Error('Blocks production failed');454 }455 return promise;456 }457458 /**459 * Wait for specified number of blocks460 * @param blocksCount number of blocks to wait461 * @returns462 */463 async newBlocks(blocksCount = 1, timeout?: number): Promise<void> {464 timeout = timeout ?? blocksCount * 60_000;465 // eslint-disable-next-line no-async-promise-executor466 const promise = new Promise<void>(async (resolve) => {467 const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads(() => {468 if (blocksCount > 0) {469 blocksCount--;470 } else {471 unsubscribe();472 resolve();473 }474 });475 });476 await this.waitWithTimeout(promise, timeout);477 return promise;478 }479480 async forParachainBlockNumber(blockNumber: bigint | number, timeout?: number) {481 timeout = timeout ?? 30 * 60 * 1000;482 // eslint-disable-next-line no-async-promise-executor483 const promise = new Promise<void>(async (resolve) => {484 const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads((data: any) => {485 if (data.number.toNumber() >= blockNumber) {486 unsubscribe();487 resolve();488 }489 });490 });491 await this.waitWithTimeout(promise, timeout);492 return promise;493 }494495 async forRelayBlockNumber(blockNumber: bigint | number, timeout?: number) {496 timeout = timeout ?? 30 * 60 * 1000;497 // eslint-disable-next-line no-async-promise-executor498 const promise = new Promise<void>(async (resolve) => {499 const unsubscribe = await this.helper.getApi().query.parachainSystem.validationData((data: any) => {500 if (data.value.relayParentNumber.toNumber() >= blockNumber) {501 // @ts-ignore502 unsubscribe();503 resolve();504 }505 });506 });507 await this.waitWithTimeout(promise, timeout);508 return promise;509 }510511 noScheduledTasks() {512 const api = this.helper.getApi();513514 // eslint-disable-next-line no-async-promise-executor515 const promise = new Promise<void>(async resolve => {516 const unsubscribe = await api.rpc.chain.subscribeNewHeads(async () => {517 const areThereScheduledTasks = await api.query.scheduler.lookup.entries();518519 if(areThereScheduledTasks.length == 0) {520 unsubscribe();521 resolve();522 }523 });524 });525526 return promise;527 }528529 event(maxBlocksToWait: number, eventSection: string, eventMethod: string) {530 // eslint-disable-next-line no-async-promise-executor531 const promise = new Promise<EventRecord | null>(async (resolve) => {532 const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads(async header => {533 const blockNumber = header.number.toHuman();534 const blockHash = header.hash;535 const eventIdStr = `${eventSection}.${eventMethod}`;536 const waitLimitStr = `wait blocks remaining: ${maxBlocksToWait}`;537538 this.helper.logger.log(`[Block #${blockNumber}] Waiting for event \`${eventIdStr}\` (${waitLimitStr})`);539540 const apiAt = await this.helper.getApi().at(blockHash);541 const eventRecords = (await apiAt.query.system.events()) as any;542543 const neededEvent = eventRecords.toArray().find((r: FrameSystemEventRecord) => {544 return r.event.section == eventSection && r.event.method == eventMethod;545 });546547 if (neededEvent) {548 unsubscribe();549 resolve(neededEvent);550 } else if (maxBlocksToWait > 0) {551 maxBlocksToWait--;552 } else {553 this.helper.logger.log(`Event \`${eventIdStr}\` is NOT found`);554 unsubscribe();555 resolve(null);556 }557 });558 });559 return promise;560 }561}562563class TestUtilGroup {564 helper: DevUniqueHelper;565566 constructor(helper: DevUniqueHelper) {567 this.helper = helper;568 }569570 async enable() {571 if (this.helper.fetchMissingPalletNames([Pallets.TestUtils]).length != 0) {572 return;573 }574575 const signer = this.helper.util.fromSeed('//Alice');576 await this.helper.getSudo<DevUniqueHelper>().executeExtrinsic(signer, 'api.tx.testUtils.enable', [], true);577 }578579 async setTestValue(signer: TSigner, testVal: number) {580 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.setTestValue', [testVal], true);581 }582583 async incTestValue(signer: TSigner) {584 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.incTestValue', [], true);585 }586587 async setTestValueAndRollback(signer: TSigner, testVal: number) {588 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.setTestValueAndRollback', [testVal], true);589 }590591 async testValue(blockIdx?: number) {592 const api = blockIdx593 ? await this.helper.getApi().at(await this.helper.callRpc('api.rpc.chain.getBlockHash', [blockIdx]))594 : this.helper.getApi();595596 return (await api.query.testUtils.testValue()).toJSON();597 }598599 async justTakeFee(signer: TSigner) {600 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.justTakeFee', [], true);601 }602603 async selfCancelingInc(signer: TSigner, scheduledId: string, maxTestVal: number) {604 await this.helper.executeExtrinsic(signer, 'api.tx.testUtils.selfCancelingInc', [scheduledId, maxTestVal], true);605 }606}607608class EventCapture {609 helper: DevUniqueHelper;610 eventSection: string;611 eventMethod: string;612 events: EventRecord[] = [];613 unsubscribe: VoidFn | null = null;614615 constructor(616 helper: DevUniqueHelper,617 eventSection: string,618 eventMethod: string,619 ) {620 this.helper = helper;621 this.eventSection = eventSection;622 this.eventMethod = eventMethod;623 }624625 async startCapture() {626 this.stopCapture();627 this.unsubscribe = (await this.helper.getApi().query.system.events((eventRecords: FrameSystemEventRecord[]) => {628 const newEvents = eventRecords.filter(r => {629 return r.event.section == this.eventSection && r.event.method == this.eventMethod;630 });631632 this.events.push(...newEvents);633 })) as any;634 }635636 stopCapture() {637 if (this.unsubscribe !== null) {638 this.unsubscribe();639 }640 }641642 extractCapturedEvents() {643 return this.events;644 }645}646647class AdminGroup {648 helper: UniqueHelper;649650 constructor(helper: UniqueHelper) {651 this.helper = helper;652 }653654 async payoutStakers(signer: IKeyringPair, stakersToPayout: number) {655 const payoutResult = await this.helper.executeExtrinsic(signer, 'api.tx.appPromotion.payoutStakers', [stakersToPayout], true);656 return payoutResult.result.events.filter(e => e.event.method === 'StakingRecalculation').map(e => {657 return {658 staker: e.event.data[0].toString(),659 stake: e.event.data[1].toBigInt(),660 payout: e.event.data[2].toBigInt(),661 };662 });663 }664}