git.delta.rocks / unique-network / refs/commits / 52ec20b9c55b

difftreelog

feat calculatePovInfo playgrnd method

Daniel Shiposha2022-11-24parent: #2aae8ed.patch.diff
in: master

3 files changed

modifiedtests/src/util/playgrounds/types.tsdiffbeforeafterboth
171 amount: bigint,171 amount: bigint,
172}172}
173
174export interface IPovInfo {
175 proofSize: number,
176 compactProofSize: number,
177 compressedProofSize: number,
178 results: any[],
179 kv: any,
180}
173181
174export interface ISchedulerOptions {182export interface ISchedulerOptions {
175 scheduledId?: string,183 scheduledId?: string,
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
8import * as defs from '../../interfaces/definitions';8import * as defs from '../../interfaces/definitions';
9import {IKeyringPair} from '@polkadot/types/types';9import {IKeyringPair} from '@polkadot/types/types';
10import {EventRecord} from '@polkadot/types/interfaces';10import {EventRecord} from '@polkadot/types/interfaces';
11import {ICrossAccountId, TSigner} from './types';11import {ICrossAccountId, IPovInfo, TSigner} from './types';
12import {FrameSystemEventRecord} from '@polkadot/types/lookup';12import {FrameSystemEventRecord} from '@polkadot/types/lookup';
13import {VoidFn} from '@polkadot/api/types';13import {VoidFn} from '@polkadot/api/types';
14import {Pallets} from '..';14import {Pallets} from '..';
15import {spawnSync} from 'child_process';
1516
16export class SilentLogger {17export class SilentLogger {
17 log(_msg: any, _level: any): void { }18 log(_msg: any, _level: any): void { }
322 return balance;323 return balance;
323 }324 }
325
326 async calculatePoVInfo(txs: any[]): Promise<IPovInfo> {
327 const rawPovInfo = await this.helper.callRpc('api.rpc.unique.estimateExtrinsicPoV', [txs]);
328
329 const kvJson: {[key: string]: string} = {};
330
331 for (const kv of rawPovInfo.keyValues) {
332 kvJson[kv.key.toHex()] = kv.value.toHex();
333 }
334
335 const kvStr = JSON.stringify(kvJson);
336
337 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 );
344
345 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 }
324353
325 calculatePalletAddress(palletId: any) {354 calculatePalletAddress(palletId: any) {
326 const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));355 const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
586 });586 });
587 }587 }
588
589 async signTransactionWithoutSending(signer: TSigner, tx: any) {
590 const api = this.getApi();
591 const signingInfo = await api.derive.tx.signingInfo(signer.address);
592
593 tx.sign(signer, {
594 blockHash: api.genesisHash,
595 genesisHash: api.genesisHash,
596 runtimeVersion: api.runtimeVersion,
597 nonce: signingInfo.nonce,
598 });
599
600 return tx.toHex();
601 }
588602
589 async getPaymentInfo(signer: TSigner, tx: any, len: number | null) {603 async getPaymentInfo(signer: TSigner, tx: any, len: number | null) {
590 const api = this.getApi();604 const api = this.getApi();