NPL message refactor. (#132)

* Implemented feeding and broadcasting npl messages from the contract execution in real-time.
* Replaced npl pipe with domain sockets.
* Refactored npl read and write in nodejs echo contract
This commit is contained in:
Chalith Desaman
2020-10-14 15:18:00 +05:30
committed by GitHub
parent cb4d0c4f59
commit 5f40aebf08
9 changed files with 298 additions and 187 deletions

View File

@@ -9,19 +9,44 @@ const hpc = new HotPocketContract();
if (!hpc.readonly)
fs.appendFileSync("exects.txt", "ts:" + hpc.timestamp + "\n");
Object.keys(hpc.users).forEach(function (key) {
Object.keys(hpc.users).forEach(async (key) => {
const user = hpc.users[key];
user.readInput().then(inputBuf => {
if (inputBuf) {
const userInput = inputBuf.toString("utf8");
if (userInput == "ts")
user.sendOutput(fs.readFileSync("exects.txt"));
else
user.sendOutput("Echoing: " + userInput);
}
})
const inputBuf = await user.readInput();
if (inputBuf) {
const userInput = inputBuf.toString("utf8");
if (userInput == "ts")
user.sendOutput(fs.readFileSync("exects.txt"));
else
user.sendOutput("Echoing: " + userInput);
}
});
const npl = hpc.npl;
// Npl channel always connected if contract is not in readonly mode.
// Smart contract developer has to mannually close the channel once the execution logic is complete.
if (npl) {
npl.closeNplChannel();
}
// Npl message sending and receiving template.
// if (npl) {
// let i = 0;
// let interval = setInterval(() => {
// npl.sendOutput(`npl${i} from contract`);
// if (i == 5) {
// clearInterval(interval);
// npl.closeNplChannel();
// }
// i++;
// }, 500);
// npl.events.on("message", msg => {
// if (msg) {
// console.log(msg);
// }
// });
// }
//console.log("===Echo contract ended===");