From 7bd6f44eab78dcfd9fd8eafc73e8e02b4fe0be4e Mon Sep 17 00:00:00 2001 From: Nodari Chkuaselidze Date: Mon, 2 Jun 2025 15:26:59 +0400 Subject: [PATCH] pkg: normalize exports. --- lib/blockstore/index-browser.js | 2 +- lib/blockstore/index.js | 2 +- test/util/migrations.js | 26 +++++++++++++++++--------- test/util/pagination.js | 2 +- test/util/primitives.js | 14 +++++++------- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/lib/blockstore/index-browser.js b/lib/blockstore/index-browser.js index a5df0956..dae3b8cc 100644 --- a/lib/blockstore/index-browser.js +++ b/lib/blockstore/index-browser.js @@ -15,7 +15,7 @@ const LevelBlockStore = require('./level'); * @module blockstore */ -exports.create = (options) => { +exports.create = function create(options) { const location = join(options.prefix, 'blocks'); return new LevelBlockStore({ diff --git a/lib/blockstore/index.js b/lib/blockstore/index.js index df1cbc35..1eae7168 100644 --- a/lib/blockstore/index.js +++ b/lib/blockstore/index.js @@ -16,7 +16,7 @@ const FileBlockStore = require('./file'); * @module blockstore */ -exports.create = (options) => { +exports.create = function create(options) { if (options.memory) { return new LevelBlockStore({ network: options.network, diff --git a/test/util/migrations.js b/test/util/migrations.js index 08095fcf..6b48765a 100644 --- a/test/util/migrations.js +++ b/test/util/migrations.js @@ -13,6 +13,10 @@ const consensus = require('../../lib/protocol/consensus'); const BlockTemplate = require('../../lib/mining/template'); const bdb = require('bdb'); +/** @typedef {import('../../lib/blockchain/chain')} Chain */ +/** @typedef {import('../../lib/mining/miner')} Miner */ +/** @typedef {import('../../lib/primitives/address')} Address */ + let Migrator = class {}; try { @@ -190,7 +194,7 @@ exports.mockLayout = mockLayout; exports.oldMockLayout = oldMockLayout; exports.DB_FLAG_ERROR = DB_FLAG_ERROR; -exports.migrationError = (migrations, ids, flagError) => { +exports.migrationError = function migrationError(migrations, ids, flagError) { let error = 'Database needs migration(s):\n'; for (const id of ids) { @@ -207,8 +211,12 @@ exports.prefix2hex = function prefix2hex(prefix) { return Buffer.from(prefix, 'ascii').toString('hex'); }; -exports.dumpDB = async (db, prefixes) => { +exports.dumpDB = async function dumpDB(db, prefixes) { const data = await db.dump(); + return exports.filteredObject(data, prefixes); +}; + +exports.filteredObject = function filteredObject(data, prefixes) { const filtered = {}; for (const [key, value] of Object.entries(data)) { @@ -223,7 +231,7 @@ exports.dumpDB = async (db, prefixes) => { return filtered; }; -exports.dumpChainDB = async (chaindb, prefixes) => { +exports.dumpChainDB = async function dumpChainDB(chaindb, prefixes) { return exports.dumpDB(chaindb.db, prefixes); }; @@ -238,7 +246,7 @@ exports.dumpChainDB = async (chaindb, prefixes) => { * @returns {Promise} - errors. */ -exports.checkEntries = async (ldb, options) => { +exports.checkEntries = async function checkEntries(ldb, options) { const errors = []; options.before = options.before || {}; @@ -296,7 +304,7 @@ exports.checkEntries = async (ldb, options) => { return errors; }; -exports.fillEntries = async (ldb, data) => { +exports.fillEntries = async function fillEntries(ldb, data) { const batch = await ldb.batch(); for (const [key, value] of Object.entries(data)) { @@ -309,7 +317,7 @@ exports.fillEntries = async (ldb, data) => { await batch.write(); }; -exports.writeVersion = (b, key, name, version) => { +exports.writeVersion = function writeVersion(b, key, name, version) { const value = Buffer.alloc(name.length + 4); value.write(name, 0, 'ascii'); @@ -318,7 +326,7 @@ exports.writeVersion = (b, key, name, version) => { b.put(key, value); }; -exports.getVersion = (data, name) => { +exports.getVersion = function getVersion(data, name) { const error = 'version mismatch'; if (data.length !== name.length + 4) @@ -330,7 +338,7 @@ exports.getVersion = (data, name) => { return data.readUInt32LE(name.length); }; -exports.checkVersion = async (ldb, versionDBKey, expectedVersion) => { +exports.checkVersion = async function checkVersion(ldb, versionDBKey, expectedVersion) { const data = await ldb.get(versionDBKey); const version = exports.getVersion(data, 'wallet'); @@ -352,7 +360,7 @@ const getBlockTime = height => REGTEST_TIME + (height * 10 * 60); * @returns {BlockTemplate} */ -exports.createBlock = async (options) => { +exports.createBlock = async function createBlock(options) { const { chain, miner, diff --git a/test/util/pagination.js b/test/util/pagination.js index 32777cc1..57badaf9 100644 --- a/test/util/pagination.js +++ b/test/util/pagination.js @@ -3,7 +3,7 @@ const assert = require('bsert'); const {forEventCondition} = require('./common'); -exports.generateInitialBlocks = async (options) => { +exports.generateInitialBlocks = async function generateInitialBlocks(options) { const { nodeCtx, coinbase, diff --git a/test/util/primitives.js b/test/util/primitives.js index 4b844c24..99e7bca5 100644 --- a/test/util/primitives.js +++ b/test/util/primitives.js @@ -13,16 +13,16 @@ const Covenant = require('../../lib/primitives/covenant'); /** @typedef {import('../../lib/types').Hash} Hash */ -exports.coinbaseInput = () => { +exports.coinbaseInput = function coinbaseInput() { return Input.fromOutpoint(new Outpoint()); }; -exports.dummyInput = () => { +exports.dummyInput = function dummyInput () { const hash = random.randomBytes(32); return Input.fromOutpoint(new Outpoint(hash, 0)); }; -exports.deterministicInput = (id) => { +exports.deterministicInput = function deterministicInput(id) { const hash = blake2b.digest(fromU32(id)); return Input.fromOutpoint(new Outpoint(hash, 0)); }; @@ -39,7 +39,7 @@ exports.deterministicInput = (id) => { * @returns {Output} */ -exports.makeOutput = (options) => { +exports.makeOutput = function makeOutput(options) { const address = options.address || exports.randomP2PKAddress(); const output = new Output(); output.address = address; @@ -66,7 +66,7 @@ exports.makeOutput = (options) => { * @returns {Covenant} */ -exports.makeCovenant = (options) => { +exports.makeCovenant = function makeCovenant(options) { const covenant = new Covenant(); covenant.type = options.type || Covenant.types.NONE; @@ -165,7 +165,7 @@ exports.makeCovenant = (options) => { return covenant; }; -exports.randomP2PKAddress = () => { +exports.randomP2PKAddress = function randomP2PKAddress() { const key = random.randomBytes(33); return Address.fromPubkey(key); }; @@ -187,7 +187,7 @@ exports.randomP2PKAddress = () => { * @returns {Coin} */ -exports.makeCoin = (options) => { +exports.makeCoin = function makeCoin(options) { return Coin.fromOptions({ hash: options.hash || random.randomBytes(32), address: options.address || Address.fromPubkey(random.randomBytes(33)),