mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
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:
@@ -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===");
|
||||
|
||||
Reference in New Issue
Block a user