HP smart contract nodejs library. (#101)

This commit is contained in:
Ravin Perera
2020-07-20 13:38:08 +05:30
committed by GitHub
parent 09e72ef8bb
commit 311d20aba6
33 changed files with 154 additions and 528 deletions

View File

@@ -0,0 +1,30 @@
const { HotPocketContract } = require("./hp-contract-lib");
const fs = require('fs');
const hpc = new HotPocketContract();
//console.log("===Echo contract started===");
// We just save execution timestamp as an example state file change.
if (!hpc.readonly)
fs.appendFileSync("exects.txt", "ts:" + hpc.timestamp + "\n");
Object.keys(hpc.users).forEach(function (key) {
const user = hpc.users[key];
const inputBuf = user.readInput();
if (inputBuf) {
const userInput = inputBuf.toString("utf8");
// Append user input to a state file if not in read only mode.
if (!hpc.readonly)
fs.appendFileSync("userinputs.txt", userInput + "\n");
if (userInput == "ts")
user.sendOutput(fs.readFileSync("exects.txt"));
else
user.sendOutput("Echoing: " + userInput);
}
});
//console.log("===Echo contract ended===");