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
before · tests/src/util/playgrounds/types.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';56export interface IEvent {7  section: string;8  method: string;9  index: [number, number] | string;10  data: any[];11  phase: {applyExtrinsic: number} | 'Initialization',12}1314export interface ITransactionResult {15  status: 'Fail' | 'Success';16  result: {17      dispatchError: any,18      events: {19        phase: any, // {ApplyExtrinsic: number} | 'Initialization',20        event: IEvent;21      }[];22  },23  moduleError?: string;24}2526export interface ISubscribeBlockEventsData {27  number: number;28  hash: string;29  timestamp: number;30  events: IEvent[];31}3233export interface ILogger {34  log: (msg: any, level?: string) => void;35  level: {36    ERROR: 'ERROR';37    WARNING: 'WARNING';38    INFO: 'INFO';39    [key: string]: string;40  }41}4243export interface IUniqueHelperLog {44  executedAt: number;45  executionTime: number;46  type: 'extrinsic' | 'rpc';47  status: 'Fail' | 'Success';48  call: string;49  params: any[];50  moduleError?: string;51  dispatchError?: any;52  events?: any;53}5455export interface IApiListeners {56  connected?: (...args: any[]) => any;57  disconnected?: (...args: any[]) => any;58  error?: (...args: any[]) => any;59  ready?: (...args: any[]) => any;60  decorated?: (...args: any[]) => any;61}6263export interface ICrossAccountId {64  Substrate?: TSubstrateAccount;65  Ethereum?: TEthereumAccount;66}6768export interface ICrossAccountIdLower {69  substrate?: TSubstrateAccount;70  ethereum?: TEthereumAccount;71}7273export interface IEthCrossAccountId {74  0: TEthereumAccount;75  1: TSubstrateAccount;76  eth: TEthereumAccount;77  sub: TSubstrateAccount;78}7980export interface ICollectionLimits {81  accountTokenOwnershipLimit?: number | null;82  sponsoredDataSize?: number | null;83  sponsoredDataRateLimit?: {blocks: number} | {sponsoringDisabled: null} | null;84  tokenLimit?: number | null;85  sponsorTransferTimeout?: number | null;86  sponsorApproveTimeout?: number | null;87  ownerCanTransfer?: boolean | null;88  ownerCanDestroy?: boolean | null;89  transfersEnabled?: boolean | null;90}9192export interface INestingPermissions {93  tokenOwner?: boolean;94  collectionAdmin?: boolean;95  restricted?: number[] | null;96}9798export interface ICollectionPermissions {99  access?: 'Normal' | 'AllowList';100  mintMode?: boolean;101  nesting?: INestingPermissions;102}103104export interface IProperty {105  key: string;106  value?: string;107}108109export interface ITokenPropertyPermission {110  key: string;111  permission: {112    mutable?: boolean;113    tokenOwner?: boolean;114    collectionAdmin?: boolean;115  }116}117118export interface IToken {119  collectionId: number;120  tokenId: number;121}122123export interface IBlock {124  extrinsics: IExtrinsic[]125  header: {126    parentHash: string,127    number: number,128  };129}130131export interface IExtrinsic {132  isSigned: boolean,133  method: {134    method: string,135    section: string,136    args: any[]137  }138}139140export interface ICollectionCreationOptions {141  name?: string | number[];142  description?: string | number[];143  tokenPrefix?: string | number[];144  mode?: {145    nft?: null;146    refungible?: null;147    fungible?: number;148  }149  permissions?: ICollectionPermissions;150  properties?: IProperty[];151  tokenPropertyPermissions?: ITokenPropertyPermission[];152  limits?: ICollectionLimits;153  pendingSponsor?: TSubstrateAccount;154}155156export interface IChainProperties {157  ss58Format: number;158  tokenDecimals: number[];159  tokenSymbol: string[]160}161162export interface ISubstrateBalance {163  free: bigint,164  reserved: bigint,165  miscFrozen: bigint,166  feeFrozen: bigint167}168169export interface IStakingInfo {170  block: bigint,171  amount: bigint,172}173174export interface ISchedulerOptions {175  scheduledId?: string,176  priority?: number,177  periodic?: {178    period: number,179    repetitions: number,180  },181}182183export interface IForeignAssetMetadata {184  name?: number | Uint8Array,185  symbol?: string,186  decimals?: number,187  minimalBalance?: bigint,188}189190export interface MoonbeamAssetInfo {191  location: any,192  metadata: {193    name: string,194    symbol: string,195    decimals: number,196    isFrozen: boolean,197    minimalBalance: bigint,198  },199  existentialDeposit: bigint,200  isSufficient: boolean,201  unitsPerSecond: bigint,202  numAssetsWeightHint: number,203}204205export interface AcalaAssetMetadata {206  name: string,207  symbol: string,208  decimals: number,209  minimalBalance: bigint,210}211212export interface DemocracyStandardAccountVote {213  balance: bigint,214  vote: {215    aye: boolean,216    conviction: number,217  },218}219220export type TSubstrateAccount = string;221export type TEthereumAccount = string;222export type TApiAllowedListeners = 'connected' | 'disconnected' | 'error' | 'ready' | 'decorated';223export type TUniqueNetworks = 'opal' | 'quartz' | 'unique';224export type TSiblingNetworkds = 'moonbeam' | 'moonriver' | 'acala' | 'karura' | 'westmint';225export type TRelayNetworks = 'rococo' | 'westend';226export type TNetworks = TUniqueNetworks | TSiblingNetworkds | TRelayNetworks;227export type TSigner = IKeyringPair; // | 'string'228export type TCollectionMode = 'nft' | 'rft' | 'ft';
after · tests/src/util/playgrounds/types.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034import {IKeyringPair} from '@polkadot/types/types';56export interface IEvent {7  section: string;8  method: string;9  index: [number, number] | string;10  data: any[];11  phase: {applyExtrinsic: number} | 'Initialization',12}1314export interface ITransactionResult {15  status: 'Fail' | 'Success';16  result: {17      dispatchError: any,18      events: {19        phase: any, // {ApplyExtrinsic: number} | 'Initialization',20        event: IEvent;21      }[];22  },23  moduleError?: string;24}2526export interface ISubscribeBlockEventsData {27  number: number;28  hash: string;29  timestamp: number;30  events: IEvent[];31}3233export interface ILogger {34  log: (msg: any, level?: string) => void;35  level: {36    ERROR: 'ERROR';37    WARNING: 'WARNING';38    INFO: 'INFO';39    [key: string]: string;40  }41}4243export interface IUniqueHelperLog {44  executedAt: number;45  executionTime: number;46  type: 'extrinsic' | 'rpc';47  status: 'Fail' | 'Success';48  call: string;49  params: any[];50  moduleError?: string;51  dispatchError?: any;52  events?: any;53}5455export interface IApiListeners {56  connected?: (...args: any[]) => any;57  disconnected?: (...args: any[]) => any;58  error?: (...args: any[]) => any;59  ready?: (...args: any[]) => any;60  decorated?: (...args: any[]) => any;61}6263export interface ICrossAccountId {64  Substrate?: TSubstrateAccount;65  Ethereum?: TEthereumAccount;66}6768export interface ICrossAccountIdLower {69  substrate?: TSubstrateAccount;70  ethereum?: TEthereumAccount;71}7273export interface IEthCrossAccountId {74  0: TEthereumAccount;75  1: TSubstrateAccount;76  eth: TEthereumAccount;77  sub: TSubstrateAccount;78}7980export interface ICollectionLimits {81  accountTokenOwnershipLimit?: number | null;82  sponsoredDataSize?: number | null;83  sponsoredDataRateLimit?: {blocks: number} | {sponsoringDisabled: null} | null;84  tokenLimit?: number | null;85  sponsorTransferTimeout?: number | null;86  sponsorApproveTimeout?: number | null;87  ownerCanTransfer?: boolean | null;88  ownerCanDestroy?: boolean | null;89  transfersEnabled?: boolean | null;90}9192export interface INestingPermissions {93  tokenOwner?: boolean;94  collectionAdmin?: boolean;95  restricted?: number[] | null;96}9798export interface ICollectionPermissions {99  access?: 'Normal' | 'AllowList';100  mintMode?: boolean;101  nesting?: INestingPermissions;102}103104export interface IProperty {105  key: string;106  value?: string;107}108109export interface ITokenPropertyPermission {110  key: string;111  permission: {112    mutable?: boolean;113    tokenOwner?: boolean;114    collectionAdmin?: boolean;115  }116}117118export interface IToken {119  collectionId: number;120  tokenId: number;121}122123export interface IBlock {124  extrinsics: IExtrinsic[]125  header: {126    parentHash: string,127    number: number,128  };129}130131export interface IExtrinsic {132  isSigned: boolean,133  method: {134    method: string,135    section: string,136    args: any[]137  }138}139140export interface ICollectionCreationOptions {141  name?: string | number[];142  description?: string | number[];143  tokenPrefix?: string | number[];144  mode?: {145    nft?: null;146    refungible?: null;147    fungible?: number;148  }149  permissions?: ICollectionPermissions;150  properties?: IProperty[];151  tokenPropertyPermissions?: ITokenPropertyPermission[];152  limits?: ICollectionLimits;153  pendingSponsor?: TSubstrateAccount;154}155156export interface IChainProperties {157  ss58Format: number;158  tokenDecimals: number[];159  tokenSymbol: string[]160}161162export interface ISubstrateBalance {163  free: bigint,164  reserved: bigint,165  miscFrozen: bigint,166  feeFrozen: bigint167}168169export interface IStakingInfo {170  block: bigint,171  amount: bigint,172}173174export interface IPovInfo {175  proofSize: number,176  compactProofSize: number,177  compressedProofSize: number,178  results: any[],179  kv: any,180}181182export interface ISchedulerOptions {183  scheduledId?: string,184  priority?: number,185  periodic?: {186    period: number,187    repetitions: number,188  },189}190191export interface IForeignAssetMetadata {192  name?: number | Uint8Array,193  symbol?: string,194  decimals?: number,195  minimalBalance?: bigint,196}197198export interface MoonbeamAssetInfo {199  location: any,200  metadata: {201    name: string,202    symbol: string,203    decimals: number,204    isFrozen: boolean,205    minimalBalance: bigint,206  },207  existentialDeposit: bigint,208  isSufficient: boolean,209  unitsPerSecond: bigint,210  numAssetsWeightHint: number,211}212213export interface AcalaAssetMetadata {214  name: string,215  symbol: string,216  decimals: number,217  minimalBalance: bigint,218}219220export interface DemocracyStandardAccountVote {221  balance: bigint,222  vote: {223    aye: boolean,224    conviction: number,225  },226}227228export type TSubstrateAccount = string;229export type TEthereumAccount = string;230export type TApiAllowedListeners = 'connected' | 'disconnected' | 'error' | 'ready' | 'decorated';231export type TUniqueNetworks = 'opal' | 'quartz' | 'unique';232export type TSiblingNetworkds = 'moonbeam' | 'moonriver' | 'acala' | 'karura' | 'westmint';233export type TRelayNetworks = 'rococo' | 'westend';234export type TNetworks = TUniqueNetworks | TSiblingNetworkds | TRelayNetworks;235export type TSigner = IKeyringPair; // | 'string'236export type TCollectionMode = 'nft' | 'rft' | 'ft';
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -8,10 +8,11 @@
 import * as defs from '../../interfaces/definitions';
 import {IKeyringPair} from '@polkadot/types/types';
 import {EventRecord} from '@polkadot/types/interfaces';
-import {ICrossAccountId, TSigner} from './types';
+import {ICrossAccountId, IPovInfo, TSigner} from './types';
 import {FrameSystemEventRecord} from '@polkadot/types/lookup';
 import {VoidFn} from '@polkadot/api/types';
 import {Pallets} from '..';
+import {spawnSync} from 'child_process';
 
 export class SilentLogger {
   log(_msg: any, _level: any): void { }
@@ -322,6 +323,34 @@
     return balance;
   }
 
+  async calculatePoVInfo(txs: any[]): Promise<IPovInfo> {
+    const rawPovInfo = await this.helper.callRpc('api.rpc.unique.estimateExtrinsicPoV', [txs]);
+
+    const kvJson: {[key: string]: string} = {};
+
+    for (const kv of rawPovInfo.keyValues) {
+      kvJson[kv.key.toHex()] = kv.value.toHex();
+    }
+
+    const kvStr = JSON.stringify(kvJson);
+
+    const chainql = spawnSync(
+      'chainql', 
+      [
+        `--tla-code=data=${kvStr}`,
+        '-e', 'function(data) cql.dump(cql.chain("wss://ws-opal.unique.network:443").latest._meta, data, {omit_empty:true})',
+      ],
+    );
+
+    return {
+      proofSize: rawPovInfo.proofSize.toNumber(),
+      compactProofSize: rawPovInfo.compactProofSize.toNumber(),
+      compressedProofSize: rawPovInfo.compressedProofSize.toNumber(),
+      results: rawPovInfo.results,
+      kv: JSON.parse(chainql.stdout.toString()),
+    };
+  }
+
   calculatePalletAddress(palletId: any) {
     const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));
     return encodeAddress(address, this.helper.chain.getChainProperties().ss58Format);
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -586,6 +586,20 @@
     });
   }
 
+  async signTransactionWithoutSending(signer: TSigner, tx: any) {
+    const api = this.getApi();
+    const signingInfo = await api.derive.tx.signingInfo(signer.address);
+
+    tx.sign(signer, {
+      blockHash: api.genesisHash,
+      genesisHash: api.genesisHash,
+      runtimeVersion: api.runtimeVersion,
+      nonce: signingInfo.nonce,
+    });
+
+    return tx.toHex();
+  }
+
   async getPaymentInfo(signer: TSigner, tx: any, len: number | null) {
     const api = this.getApi();
     const signingInfo = await api.derive.tx.signingInfo(signer.address);