pkg: normalize exports.
This commit is contained in:
parent
86e024243c
commit
7bd6f44eab
5 changed files with 27 additions and 19 deletions
|
|
@ -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({
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<String[]>} - 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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue