Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getRawTokenBalances(url, tokens, address) {
const addrScriptHash = u.reverseHex(wallet.getScriptHashFromAddress(address));
const sb = new sc.ScriptBuilder();
tokens.forEach(({ scriptHash }) => {
sb.emitAppCall(scriptHash, 'balanceOf', [addrScriptHash]);
});
return rpc.Query.invokeScript(sb.str, false)
.execute(url)
.then((res) => {
const tokenList = {};
if (res && res.result && res.result.stack && res.result.stack.length >= 1) {
for (let i = 0; i < res.result.stack.length; i += 1) {
const { scriptHash, decimals } = tokens[i];
const value = parseHexNum(res.result.stack[i].value);
if (value !== 0 || scriptHash === NOS) {
expression ${wallet.isAddress} ${() => u.reverseHex(wallet.getScriptHashFromAddress(arg))}
expression ${Array.isArray} ${() => encodeArgs(arg)}
function parseHexNum(hex) {
return hex ? parseInt(u.reverseHex(hex), 16) : 0;
}
tokenEntries.forEach(({ address, amount, symbol }) => {
const toAcct = new wallet.Account(address)
const { scriptHash, decimals } = tokensBalanceMap[symbol]
const args = [
u.reverseHex(fromAcct.scriptHash),
u.reverseHex(toAcct.scriptHash),
sc.ContractParam.byteArray(toNumber(amount), 'fixed8', decimals),
]
scriptBuilder.emitAppCall(scriptHash, 'transfer', args)
})