mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
31 lines
902 B
JavaScript
31 lines
902 B
JavaScript
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===");
|