Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ninegua committed Sep 3, 2021
1 parent 08f79b4 commit 0784806
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/bare-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ export async function send_message(message, update_status, sleep) {
let canister_id = new Principal(ingress.content.canister_id).toString();
let method_name = ingress.content.method_name;
let reply = await query(canister_id, ingress_content);
update_status(await try_decode(canister_id, method_name, reply.reply.arg, true), true);
update_status(
await try_decode(canister_id, method_name, reply.reply.arg, true),
true
);
} else {
// Update call, handle json format of both nano and dfx
const ingress_content = fromHexString(
Expand Down Expand Up @@ -271,14 +274,9 @@ export async function try_decode(canister_id, method_name, msg, isReply) {
let mod = await eval('import("' + dataUri + '")');
let services = mod.idlFactory({ IDL });
let func = lookup(services._fields, method_name);
let funcTypes = func.retTypes;
if (!isReply) {
funcTypes = func.argTypes;
}
let funcTypes = isReply ? func.retTypes : func.argTypes;
msg = IDL.decode(funcTypes, Buffer.from(msg));
msg = funcTypes
.map((t, i) => t.valueToString(msg[i]))
.toString();
msg = funcTypes.map((t, i) => t.valueToString(msg[i])).toString();
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,23 @@ async function prepare_send(message) {
return;
}
const canister_id = new Principal(ingress.content.canister_id);
const args = await try_decode(canister_id, ingress.content.method_name, ingress.content.arg, false);
const args = await try_decode(
canister_id,
ingress.content.method_name,
ingress.content.arg,
false
);
const text =
"Request type : " +
ingress.content.request_type +
"\nSender : " +
new Principal(ingress.content.sender).toString() +
"\nCanister id : " + canister_id.toString() +
"\nCanister id : " +
canister_id.toString() +
"\nMethod name : " +
ingress.content.method_name +
"\nArguments : " +
JSON.stringify(args, (_, v) => typeof v === 'bigint' ? `${v}n` : v);
(typeof args == "string" ? args : "(" + stringify(args, null, 2) + ")");
pre.innerText = text;
var button = document.getElementById("send");
if (!button) {
Expand Down

0 comments on commit 0784806

Please sign in to comment.