Implemented contract read requests. (#98)

This commit is contained in:
Ravin Perera
2020-06-19 21:52:03 +05:30
committed by GitHub
parent 04e230c82e
commit 817ccd6a88
17 changed files with 760 additions and 587 deletions

View File

@@ -4,36 +4,45 @@ process.on('uncaughtException', (err) => {
const fs = require('fs')
//console.log("===Sample contract started===");
//console.log("Contract args received from hp: " + input);
let hpargs = JSON.parse(fs.readFileSync(0, 'utf8'));
//console.log(hpargs);
// We just save execution args as an example state file change.
fs.appendFileSync("exects.txt", "ts:" + hpargs.ts + "\n");
if (!hpargs.readonly)
fs.appendFileSync("exects.txt", "ts:" + hpargs.ts + "\n");
Object.keys(hpargs.usrfd).forEach(function (key, index) {
let userfds = hpargs.usrfd[key];
if (userfds[0] != -1) {
let userinput = fs.readFileSync(userfds[0], 'utf8');
// Append user input to a state file.
fs.appendFileSync("userinputs.txt", userinput + "\n");
fs.writeSync(userfds[1], "Echoing: " + userinput);
// Append user input to a state file if not in read only mode.
if (!hpargs.readonly)
fs.appendFileSync("userinputs.txt", userinput + "\n");
if (userinput == "ts")
fs.writeSync(userfds[1], fs.readFileSync("exects.txt"));
else
fs.writeSync(userfds[1], "Echoing: " + userinput);
}
});
if (hpargs.nplfd[0] != -1) {
let nplinput = fs.readFileSync(hpargs.nplfd[0], 'utf8');
console.log("Input received from peers:");
console.log(nplinput);
fs.writeSync(hpargs.nplfd[1], "Echoing: " + nplinput);
}
if (!hpargs.readonly) {
if (hpargs.hpfd[0] != -1) {
let hpinput = fs.readFileSync(hpargs.hpfd[0], 'utf8');
console.log("Input received from hp:");
console.log(hpinput);
fs.writeSync(hpargs.hpfd[1], "Echoing: " + hpinput);
if (hpargs.nplfd[0] != -1) {
let nplinput = fs.readFileSync(hpargs.nplfd[0], 'utf8');
console.log("Input received from peers:");
console.log(nplinput);
fs.writeSync(hpargs.nplfd[1], "Echoing: " + nplinput);
}
if (hpargs.hpfd[0] != -1) {
let hpinput = fs.readFileSync(hpargs.hpfd[0], 'utf8');
console.log("Input received from hp:");
console.log(hpinput);
fs.writeSync(hpargs.hpfd[1], "Echoing: " + hpinput);
}
}
//console.log("===Sample contract ended===");