UNPKG

@requestnetwork/data-access

Version:
48 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataAccessWrite = void 0; const tslib_1 = require("tslib"); const events_1 = require("events"); const block_1 = require("./block"); class DataAccessWrite { constructor(storage, pendingStore) { this.storage = storage; this.pendingStore = pendingStore; this.pendingStore = pendingStore; } initialize() { return tslib_1.__awaiter(this, void 0, void 0, function* () { return; }); } close() { return tslib_1.__awaiter(this, void 0, void 0, function* () { return; }); } persistTransaction(transaction, channelId, topics) { var _a; return tslib_1.__awaiter(this, void 0, void 0, function* () { const updatedBlock = block_1.default.pushTransaction(block_1.default.createEmptyBlock(), transaction, channelId, topics); const storageResult = yield this.storage.append(JSON.stringify(updatedBlock)); const eventEmitter = new events_1.EventEmitter(); (_a = this.pendingStore) === null || _a === void 0 ? void 0 : _a.add(channelId, { transaction, storageResult, topics: topics || [] }); const result = { meta: { transactionStorageLocation: storageResult.id, storageMeta: storageResult.meta, topics: topics || [], }, result: {}, }; storageResult.on('confirmed', (r) => { result.meta.storageMeta = r.meta; eventEmitter.emit('confirmed', result); }); storageResult.on('error', (err) => eventEmitter.emit('error', err)); return Object.assign(eventEmitter, result); }); } } exports.DataAccessWrite = DataAccessWrite; //# sourceMappingURL=data-write.js.map