git.delta.rocks / unique-network / refs/commits / 078678edc9f4

difftreelog

source

js-packages/scripts/calibrateApply.ts1.6 KiBsourcehistory
1import {readFile, writeFile} from 'fs/promises';2import path from 'path';3import {makeNames, usingPlaygrounds} from '@unique/test-utils/util.js';45const {dirname} = makeNames(import.meta.url);67const formatNumber = (num: string): string => num.split('').reverse().join('').replace(/([0-9]{3})/g, '$1_').split('').reverse().join('').replace(/^_/, '');89(async () => {10  let weightToFeeCoefficientOverride: string;11  let minGasPriceOverride: string;12  await usingPlaygrounds(async (helpers, _privateKey) => {13    weightToFeeCoefficientOverride = (await helpers.getApi().query.configuration.weightToFeeCoefficientOverride() as any).toBigInt().toString();14    minGasPriceOverride = (await helpers.getApi().query.configuration.minGasPriceOverride() as any).toBigInt().toString();15  });16  const constantsFile = path.resolve(dirname, '../../primitives/common/src/constants.rs');17  let constants = (await readFile(constantsFile)).toString();1819  let weight2feeFound = false;20  constants = constants.replace(/(\/\*<weight2fee>\*\/)[0-9_]+(\/\*<\/weight2fee>\*\/)/, (_f, p, s) => {21    weight2feeFound = true;22    return p+formatNumber(weightToFeeCoefficientOverride)+s;23  });24  if(!weight2feeFound) {25    throw new Error('failed to find weight2fee marker in source code');26  }2728  let minGasPriceFound = false;29  constants = constants.replace(/(\/\*<mingasprice>\*\/)[0-9_]+(\/\*<\/mingasprice>\*\/)/, (_f, p, s) => {30    minGasPriceFound = true;31    return p+formatNumber(minGasPriceOverride)+s;32  });33  if(!minGasPriceFound) {34    throw new Error('failed to find mingasprice marker in source code');35  }3637  await writeFile(constantsFile, constants);38})().catch(e => {39  console.log(e.stack);40});