Files
hpcore/examples/nodejs_contract/hp-contract-lib.js
2020-07-20 13:38:08 +05:30

27 lines
679 B
JavaScript

const fs = require('fs');
function HotPocketContract() {
const hpargs = JSON.parse(fs.readFileSync(0, 'utf8'));
this.readonly = hpargs.readonly;
this.timestamp = hpargs.ts;
this.users = {};
Object.keys(hpargs.usrfd).forEach((userPubKey) => {
const userfds = hpargs.usrfd[userPubKey];
this.users[userPubKey] = new HotPocketChannel(userfds[0], userfds[1]);
});
}
function HotPocketChannel(infd, outfd) {
this.readInput = function () {
return infd == -1 ? null : fs.readFileSync(infd);
}
this.sendOutput = function (output) {
fs.writeFileSync(outfd, output);
}
}
module.exports = {
HotPocketContract
}