UNPKG

lisk-framework

Version:

Lisk blockchain application platform

45 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createStoreGetter = exports.removeDB = exports.createStateDB = exports.createDB = exports.getDBPath = exports.waitUntilBlockHeight = void 0; const os = require("os"); const path = require("path"); const fs = require("fs-extra"); const lisk_db_1 = require("@liskhq/lisk-db"); const events_1 = require("../engine/events"); const waitUntilBlockHeight = async ({ apiClient, height, timeout, }) => new Promise((resolve, reject) => { if (timeout) { setTimeout(() => { reject(new Error(`'waitUntilBlockHeight' timed out after ${timeout} ms`)); }, timeout); } apiClient.subscribe(events_1.EVENT_CHAIN_BLOCK_NEW, data => { const { block } = data; const { header } = apiClient.block.decode(block); if (header.height >= height) { resolve(); } }); }); exports.waitUntilBlockHeight = waitUntilBlockHeight; const defaultDatabasePath = path.join(os.tmpdir(), 'lisk-framework', Date.now().toString()); const getDBPath = (name, dbPath = defaultDatabasePath) => path.join(dbPath, `${name}.db`); exports.getDBPath = getDBPath; const createDB = (name, dbPath = defaultDatabasePath) => { fs.ensureDirSync(dbPath); const filePath = (0, exports.getDBPath)(name, dbPath); return new lisk_db_1.Database(filePath); }; exports.createDB = createDB; const createStateDB = (name, dbPath = defaultDatabasePath) => { fs.ensureDirSync(dbPath); const filePath = (0, exports.getDBPath)(name, dbPath); return new lisk_db_1.StateDB(filePath); }; exports.createStateDB = createStateDB; const removeDB = (dbPath = defaultDatabasePath) => ['module', 'blockchain', 'node', 'state', 'generator'].forEach(name => fs.removeSync((0, exports.getDBPath)(name, dbPath))); exports.removeDB = removeDB; const createStoreGetter = (stateStore) => ({ getStore: (p1, p2) => stateStore.getStore(p1, p2), }); exports.createStoreGetter = createStoreGetter; //# sourceMappingURL=utils.js.map