Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("balanceOf", () => {
const resultFunction = abi.balanceOf(scriptHash, fromAddr);
const resultScript = resultFunction().str;
expect(resultScript).toBe(
`14${u.reverseHex(
wallet.getScriptHashFromAddress(fromAddr)
)}51c10962616c616e63654f6667${u.reverseHex(scriptHash)}`
);
});
function addressToScriptHash(address: string): string {
return u.reverseHex(wallet.getScriptHashFromAddress(address));
}
newTx.inputs.push(new TransactionInput({
prevIndex: item.n,
prevHash: item.txid.startsWith('0x') && item.txid.length === 66 ?
item.txid.substring(2) : item.txid
}));
if (curr >= fee) {
break;
}
}
const payback = this.global.mathSub(curr, fee);
if (payback < 0) {
reject('no enough GAS to fee');
return;
}
if (payback > 0) {
const fromScript = wallet.getScriptHashFromAddress(from);
let gasAssetId = res[0].asset_id;
if (gasAssetId.startsWith('0x') && gasAssetId.length === 66) {
gasAssetId = gasAssetId.substring(2);
}
newTx.addOutput({ assetId: gasAssetId, value: this.global.mathSub(curr, fee), scriptHash: fromScript });
}
resolve(newTx);
});
});
return new Promise(async (resolve, reject) => {
const fromScript = wallet.getScriptHashFromAddress(this.neon.address);
const toScript = this.scriptHash.startsWith('0x') && this.scriptHash.length === 42 ? this.scriptHash.substring(2) : this.scriptHash;
let newTx = new tx.InvocationTransaction();
if (this.scriptHash.length !== 42 && this.scriptHash.length !== 40) {
this.chrome.windowCallback({
error: ERRORS.MALFORMED_INPUT,
return: requestTarget.Invoke,
ID: this.messageID
});
this.loading = false;
this.loadingMsg = '';
window.close();
return null;
}
try {
newTx.script = sc.createScript({
scriptHash: this.scriptHash.startsWith('0x') && this.scriptHash.length === 42 ? this.scriptHash.substring(2) : this.scriptHash,
for (const item of res) {
curr = this.global.mathAdd(curr, parseFloat(item.value) || 0);
newTx.inputs.push(new TransactionInput({
prevIndex: item.n,
prevHash: item.txid.startsWith('0x') && item.txid.length === 66 ?
item.txid.substring(2) : item.txid }));
if (curr >= fee) {
break;
}
}
const payback = this.global.mathSub(curr, fee);
if (payback < 0) {
observer.error('no enough GAS to fee');
}
if (payback > 0) {
const fromScript = wallet.getScriptHashFromAddress(from);
let gasAssetId = res[0].asset_id;
if (gasAssetId.startsWith('0x') && gasAssetId.length === 66) {
gasAssetId = gasAssetId.substring(2);
}
newTx.addOutput({ assetId: gasAssetId, value: this.global.mathSub(curr, fee), scriptHash: fromScript });
}
observer.next(newTx);
observer.complete();
});
});
scriptHashArray.forEach(scriptHash => {
if (address) {
const addrScriptHash = u.reverseHex(
wallet.getScriptHashFromAddress(address)
);
sb.emitAppCall(scriptHash, "name")
.emitAppCall(scriptHash, "symbol")
.emitAppCall(scriptHash, "decimals")
.emitAppCall(scriptHash, "totalSupply")
.emitAppCall(scriptHash, "balanceOf", [addrScriptHash]);
} else {
sb.emitAppCall(scriptHash, "name")
.emitAppCall(scriptHash, "symbol")
.emitAppCall(scriptHash, "decimals")
.emitAppCall(scriptHash, "totalSupply");
}
});
if (curr >= fee) {
break;
}
}
const payback = this.global.mathSub(curr, fee);
if (payback < 0) {
reject('no enough GAS to fee');
this.chrome.windowCallback({
error: ERRORS.INSUFFICIENT_FUNDS,
return: requestTarget.Deploy,
ID: this.messageID
});
window.close();
}
if (payback > 0) {
const fromScript = wallet.getScriptHashFromAddress(from);
let gasAssetId = res[0].asset_id;
if (gasAssetId.startsWith('0x') && gasAssetId.length === 66) {
gasAssetId = gasAssetId.substring(2);
}
newTx.addOutput({ assetId: gasAssetId, value: this.global.mathSub(curr, fee), scriptHash: fromScript });
}
resolve(newTx);
});
});