diff --git a/lib/core/fs.js b/lib/core/fs.js index 12a90806..6d7a1410 100644 --- a/lib/core/fs.js +++ b/lib/core/fs.js @@ -114,6 +114,10 @@ function writeJson() { return restrictPath(fs.writeJson, fs.writeJson, 1, arguments); } +function ensureFileSync() { + return restrictPath(fs.ensureFileSync, fs.ensureFileSync, 1, arguments); +} + function existsSync() { return restrictPath(fs.existsSync, fs.existsSync, 1, arguments); } @@ -208,5 +212,6 @@ module.exports = { dappPath, pkgPath, outputFileSync, + ensureFileSync, writeJson }; diff --git a/lib/modules/console_listener/index.js b/lib/modules/console_listener/index.js index e778c8ca..8a153eef 100644 --- a/lib/modules/console_listener/index.js +++ b/lib/modules/console_listener/index.js @@ -1,4 +1,5 @@ const utils = require('../../utils/utils.js'); +const fs = require('../../core/fs'); class ConsoleListener { constructor(embark, options) { @@ -16,6 +17,8 @@ class ConsoleListener { this.outputDone = true; }); this._registerAPI(); + this.transactionPath = fs.dappPath('.embark', 'transactions.json'); + fs.ensureFileSync(this.transactionPath); this.events.on("contractsDeployed", () => { this.contractsDeployed = true; @@ -97,7 +100,15 @@ class ConsoleListener { gasUsed = utils.hexToNumber(gasUsed); blockNumber = utils.hexToNumber(blockNumber); - this.logs.push(Object.assign({}, request, {name, functionName, paramString, gasUsed, blockNumber})); + let transactions; + try { + transactions = JSON.parse(fs.readFileSync(this.transactionPath, 'utf-8')); + } catch { + transactions = {}; + } + const transaction = Object.assign({}, request, {name, functionName, paramString, gasUsed, blockNumber}); + transactions[transactionHash] = transaction; + fs.writeFileSync(this.transactionPath, JSON.stringify(transactions)); this.events.emit('contracts:log', this.logs[this.logs.length - 1]); this.logger.info(`Blockchain>`.underline + ` ${name}.${functionName}(${paramString})`.bold + ` | ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`);