Replaced contract I/O pipes with domain sockets. (#140)

This commit is contained in:
Savinda Senevirathne
2020-11-02 16:50:21 +05:30
committed by GitHub
parent 37cc27c5ce
commit 7a4515865d
4 changed files with 254 additions and 210 deletions

View File

@@ -9,16 +9,16 @@ const hpc = new HotPocketContract();
if (!hpc.readonly)
fs.appendFileSync("exects.txt", "ts:" + hpc.timestamp + "\n");
Object.keys(hpc.users).forEach(async (key) => {
const user = hpc.users[key];
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);
hpc.events.on("user_message", (pubKey, message) => {
const userInput = message.toString("utf8");
const user = hpc.users[pubKey];
if (userInput == "ts") {
user.sendOutput(fs.readFileSync("exects.txt"));
user.closeChannel();
}
else {
user.sendOutput("Echoing: " + userInput);
user.closeChannel();
}
});
@@ -30,6 +30,19 @@ if (npl) {
npl.closeNplChannel();
}
// HP <--> SC
const hp = hpc.control;
hp.closeControlChannel();
// let i = 0;
// hp.events.on('message', (msg) => {
// console.log('control msg - ' + msg);
// hp.sendOutput(msg);
// i++;
// if (i == 2)
// hp.closeControlChannel();
// })
// Npl message sending and receiving template.
// if (npl) {
// let i = 0;