Skip to content

Instantly share code, notes, and snippets.

@nicola-attico
Created May 14, 2020 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicola-attico/84be6a46459e6cd93b2938b15944d22b to your computer and use it in GitHub Desktop.
Save nicola-attico/84be6a46459e6cd93b2938b15944d22b to your computer and use it in GitHub Desktop.
User Balances Def V2
(function executeQuery(v_table, v_query) {
var foo = new ECCCommandV2();
var json = new JSON();
var xmlDoc = new XMLDocument2();
var w = new GlideRecord('u_wallet');
var warr = [];
w.addQuery("u_company","");
var a = 0;
w.query();
while (w.next()) {
warr[a] = {
"sysid": w.getValue("sys_id"),
"u_address": w.getValue("u_address")
};
a++;
}
// gs.log(JSON.stringify(warr), "777warr");
var t = new GlideRecord('u_token_registry');
var tarr = [];
var b = 0;
// t.addQuery('u_status', '=', 'deployed');
t.query();
while (t.next()) {
tarr[b] = {
"sysid": t.getValue("sys_id"),
"u_contract_address": t.getValue("u_contract_address")
};
b++;
}
for (x = 0; x < warr.length; x++) {
for (y = 0; y < tarr.length; y++) {
var commandReturn = foo.runCommand("geth2", 'node /home/nicola/nowtoken/getBalances.js ' + tarr[y].u_contract_address + ' ' + warr[x].u_address);
var xmlPayload = commandReturn.response_payload_xml;
xmlDoc.parseXML(xmlPayload);
var myResponse = xmlDoc.getFirstNode('/results/result/stdout').getTextContent().toString();
var myJSON = json.decode(myResponse);
gs.log("myJSON" + json.encode(myJSON), "myJSON");
var map = {};
map['u_wallet'] = warr[x].sysid;
map['u_token'] = tarr[y].sysid;
map['u_balance'] = myJSON.balance.slice(0, -18) || 0;
v_table.addRow(map);
}
}
})(v_table, v_query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment