Updated nodejs contract lib for streamed input reading. (#110)

This commit is contained in:
Ravin Perera
2020-08-21 15:27:25 +05:30
committed by GitHub
parent baf5d8b14a
commit 465573ad29
7 changed files with 93 additions and 50 deletions

View File

@@ -12,19 +12,16 @@ if (!hpc.readonly)
Object.keys(hpc.users).forEach(function (key) {
const user = hpc.users[key];
const inputBuf = user.readInput();
if (inputBuf) {
const userInput = inputBuf.toString("utf8");
user.readInput().then(inputBuf => {
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);
}
if (userInput == "ts")
user.sendOutput(fs.readFileSync("exects.txt"));
else
user.sendOutput("Echoing: " + userInput);
}
})
});
//console.log("===Echo contract ended===");