From 6cfa47418c9a4d15cf4e7334d87454478cedc92e Mon Sep 17 00:00:00 2001 From: ravinsp <33562092+ravinsp@users.noreply.github.com> Date: Sun, 23 May 2021 17:14:34 +0530 Subject: [PATCH] Minor updates to echo contract and hpfs. --- examples/nodejs_contract/echo_contract.js | 13 ++++++++++--- test/bin/hpfs | Bin 350368 -> 350368 bytes 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/nodejs_contract/echo_contract.js b/examples/nodejs_contract/echo_contract.js index 9f266fe5..102a97ed 100644 --- a/examples/nodejs_contract/echo_contract.js +++ b/examples/nodejs_contract/echo_contract.js @@ -1,13 +1,20 @@ const HotPocket = require("./hp-contract-lib"); const fs = require('fs'); +const exectsFile = "exects.txt"; + // HP smart contract is defined as a function which takes HP ExecutionContext as an argument. // HP considers execution as complete, when this function completes and all the NPL message callbacks are complete. const echoContract = async (ctx) => { // We just save execution timestamp as an example state file change. - if (!ctx.readonly) - fs.appendFileSync("exects.txt", "ts:" + ctx.timestamp + "\n"); + if (!ctx.readonly) { + fs.appendFileSync(exectsFile, "ts:" + ctx.timestamp + "\n"); + + const stats = fs.statSync(exectsFile); + if (stats.size > 100 * 1024 * 1024) // If more than 100 MB, empty the file. + fs.truncateSync(exectsFile); + } // Collection of per-user promises to wait for. Each promise completes when inputs for that user is processed. const userHandlers = []; @@ -31,7 +38,7 @@ const echoContract = async (ctx) => { } - // The promise gets complete when all inputs for this user are processed. + // The promise gets completed when all inputs for this user are processed. resolve(); })); } diff --git a/test/bin/hpfs b/test/bin/hpfs index 64287be6bf37f0369aebfc12a60f8072a2faae59..f9549d3e178d4352d9ed799fe71b27ee6c02ace5 100755 GIT binary patch delta 322 zcmZ3mQFOsZ(G4w3B5SuPH7+atD!l7f$-5|BDUY_r+f15gFm0c~#CT=_M4eprslcze76lRYD^fJblh1O^5MelZsnj_C@LOk&#)3Nq<1GESZT zPKap+P*=M!vMwnRrpt`Rmf02_o!JI;EI`u2quWJA!=t-KCBvinfQEv p(oBhH8m3>6Vfx9qeEKO_u=->>LnVm$x=