mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-07-30 02:20:42 +00:00
HP smart contract nodejs library. (#101)
This commit is contained in:
30
examples/nodejs_contract/echo_contract.js
Normal file
30
examples/nodejs_contract/echo_contract.js
Normal 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===");
|
||||
Reference in New Issue
Block a user