diff --git a/examples/c_contract/hotpocket_contract.h b/examples/c_contract/hotpocket_contract.h index 03136a99..11938a3a 100644 --- a/examples/c_contract/hotpocket_contract.h +++ b/examples/c_contract/hotpocket_contract.h @@ -436,7 +436,7 @@ void __hp_parse_args_json(const struct json_object_s *object) { __HP_ASSIGN_STRING(cctx->pubkey, elem); } - else if (strcmp(k->string, "ts") == 0) + else if (strcmp(k->string, "timestamp") == 0) { __HP_ASSIGN_UINT64(cctx->timestamp, elem); } @@ -448,7 +448,7 @@ void __hp_parse_args_json(const struct json_object_s *object) { __HP_ASSIGN_STRING(cctx->lcl, elem); } - else if (strcmp(k->string, "userinfd") == 0) + else if (strcmp(k->string, "user_in_fd") == 0) { __HP_ASSIGN_INT(cctx->users.in_fd, elem); } @@ -501,7 +501,7 @@ void __hp_parse_args_json(const struct json_object_s *object) } } } - else if (strcmp(k->string, "nplfd") == 0) + else if (strcmp(k->string, "npl_fd") == 0) { __HP_ASSIGN_INT(cctx->unl.npl_fd, elem); } @@ -526,7 +526,7 @@ void __hp_parse_args_json(const struct json_object_s *object) } } } - else if (strcmp(k->string, "controlfd") == 0) + else if (strcmp(k->string, "control_fd") == 0) { __HP_ASSIGN_INT(__hpc.control_fd, elem); } diff --git a/examples/nodejs_contract/echo_contract.js b/examples/nodejs_contract/echo_contract.js index cdd766eb..98fdaede 100644 --- a/examples/nodejs_contract/echo_contract.js +++ b/examples/nodejs_contract/echo_contract.js @@ -48,9 +48,6 @@ const echoContract = async (ctx) => { // }) // await ctx.unl.send("Hello"); // } - - // Update UNL example: - // ctx.updateUnl([""], [""]); } const hpc = new HotPocket.Contract(); diff --git a/examples/nodejs_contract/hp-contract-lib.js b/examples/nodejs_contract/hp-contract-lib.js index b2b611bf..6cfb7934 100644 --- a/examples/nodejs_contract/hp-contract-lib.js +++ b/examples/nodejs_contract/hp-contract-lib.js @@ -37,7 +37,7 @@ class HotPocketContract { const argsJson = fs.readFileSync(process.stdin.fd, 'utf8'); const hpargs = JSON.parse(argsJson); - this.#controlChannel = new ControlChannel(hpargs.controlfd); + this.#controlChannel = new ControlChannel(hpargs.control_fd); this.#executeContract(hpargs, contractFunc); return true; } @@ -45,11 +45,11 @@ class HotPocketContract { #executeContract = (hpargs, contractFunc) => { // Keeps track of all the tasks (promises) that must be awaited before the termination. const pendingTasks = []; - const nplChannel = new NplChannel(hpargs.nplfd); + const nplChannel = new NplChannel(hpargs.npl_fd); - const users = new UsersCollection(hpargs.userinfd, hpargs.users, this.#clientProtocol); + const users = new UsersCollection(hpargs.user_in_fd, hpargs.users, this.#clientProtocol); const unl = new UnlCollection(hpargs.readonly, hpargs.unl, nplChannel, pendingTasks); - const executionContext = new ContractExecutionContext(hpargs, users, unl, this.#controlChannel); + const executionContext = new ContractContext(hpargs, users, unl, this.#controlChannel); invokeCallback(contractFunc, executionContext).catch(errHandler).finally(() => { // Wait for any pending tasks added during execution. @@ -182,7 +182,7 @@ class PatchConfig { } } -class ContractExecutionContext { +class ContractContext { #controlChannel = null; #patchConfig = null; @@ -190,7 +190,7 @@ class ContractExecutionContext { constructor(hpargs, users, unl, controlChannel) { this.#controlChannel = controlChannel; this.readonly = hpargs.readonly; - this.timestamp = hpargs.ts; + this.timestamp = hpargs.timestamp; this.users = users; this.unl = unl; // Not available in readonly mode. this.lcl = hpargs.lcl; // Not available in readonly mode. diff --git a/src/sc.cpp b/src/sc.cpp index e6aa1764..eeeffa1c 100644 --- a/src/sc.cpp +++ b/src/sc.cpp @@ -208,14 +208,15 @@ namespace sc * Writes the contract args (JSON) into the stdin of the contract process. * Args format: * { - * "version":"", + * "hp_version":"", + * "contract_id": "", * "pubkey": "", - * "ts": , + * "timestamp": , * "readonly": , * "lcl": "", (eg: 169-a1d82eb4c9ed005ec2c4f4f82b6f0c2fd7543d66b1a0f6b8e58ae670b3e2bcfb) - * "controlfd": fd, - * "nplfd":fd, - * "userinfd":fd, // User inputs fd. + * "control_fd": fd, + * "npl_fd":fd, + * "user_in_fd":fd, // User inputs fd. * "users":{ "":[outfd, [msg1_off, msg1_len], ...], ... }, * "unl":[ "", ... ] * } @@ -227,20 +228,21 @@ namespace sc // json string manually. std::ostringstream os; - os << "{\"version\":\"" << util::HP_VERSION + os << "{\"hp_version\":\"" << util::HP_VERSION + << "\",\"contract_id\":\"" << conf::cfg.contract.id << "\",\"pubkey\":\"" << conf::cfg.node.public_key_hex - << "\",\"ts\":" << ctx.args.time + << "\",\"timestamp\":" << ctx.args.time << ",\"readonly\":" << (ctx.args.readonly ? "true" : "false"); if (!ctx.args.readonly) { os << ",\"lcl\":\"" << ctx.args.lcl - << "\",\"nplfd\":" << ctx.nplfds.scfd; + << "\",\"npl_fd\":" << ctx.nplfds.scfd; } - os << ",\"controlfd\":" << ctx.controlfds.scfd; + os << ",\"control_fd\":" << ctx.controlfds.scfd; - os << ",\"userinfd\":" << user_inputs_fd + os << ",\"user_in_fd\":" << user_inputs_fd << ",\"users\":{"; user_json_to_stream(ctx.userfds, ctx.args.userbufs, os);