Minor updates to echo contract and hpfs.

This commit is contained in:
ravinsp
2021-05-23 17:14:34 +05:30
parent 2bb6be0ce5
commit 6cfa47418c
2 changed files with 10 additions and 3 deletions

View File

@@ -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();
}));
}

Binary file not shown.