1234import {IKeyringPair} from '@polkadot/types/types';5import {UniqueHelper} from './unique';6import config from '../../config';7import '../../interfaces/augment-api-events';8import * as defs from '../../interfaces/definitions';9import {ApiPromise, WsProvider} from '@polkadot/api';101112class SilentLogger {13 log(msg: any, level: any): void {}14 level = {15 ERROR: 'ERROR' as const,16 WARNING: 'WARNING' as const,17 INFO: 'INFO' as const,18 };19}202122class DevUniqueHelper extends UniqueHelper {23 async connect(wsEndpoint: string, listeners?: any): Promise<void> {24 const wsProvider = new WsProvider(wsEndpoint);25 this.api = new ApiPromise({26 provider: wsProvider, 27 signedExtensions: {28 ContractHelpers: {29 extrinsic: {},30 payload: {},31 },32 FakeTransactionFinalizer: {33 extrinsic: {},34 payload: {},35 },36 },37 rpc: {38 unique: defs.unique.rpc,39 rmrk: defs.rmrk.rpc,40 eth: {41 feeHistory: {42 description: 'Dummy',43 params: [],44 type: 'u8',45 },46 maxPriorityFeePerGas: {47 description: 'Dummy',48 params: [],49 type: 'u8',50 },51 },52 },53 });54 await this.api.isReadyOrError;55 this.network = await UniqueHelper.detectNetwork(this.api);56 }57}5859export const usingPlaygrounds = async (code: (helper: UniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {60 61 62 const consoleErr = console.error;63 const consoleLog = console.log;64 const consoleWarn = console.warn;6566 const outFn = (printer: any) => (...args: any[]) => {67 for (const arg of args) {68 if (typeof arg !== 'string')69 continue;70 if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))71 return;72 }73 printer(...args);74 };7576 console.error = outFn(consoleErr.bind(console));77 console.log = outFn(consoleLog.bind(console));78 console.warn = outFn(consoleWarn.bind(console));79 const helper = new DevUniqueHelper(new SilentLogger());8081 try {82 await helper.connect(config.substrateUrl);83 const ss58Format = helper.chain.getChainProperties().ss58Format;84 const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);85 await code(helper, privateKey);86 } 87 finally {88 await helper.disconnect();89 console.error = consoleErr;90 console.log = consoleLog;91 console.warn = consoleWarn;92 }93};