Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(async () => {
for (let i = 0; i < lastFoundActiveAddressIndex + addressGapScanDepth; i++) {
// get address
const orderPublickey = hdPublickey.deriveChild(accountDerivation + i.toFixed());
// @ts-ignore
const pubkey = new bitcore.PublicKey(orderPublickey.publicKey);
// @ts-ignore
const address = bitcore.Address.fromPublicKey(pubkey, bitcore.Networks.mainnet).toString();
console.log(address);
//const cashAddr = Utils.toCashAddress(address);
//console.log(cashAddr);
const res = await gprc.getAddressTransactions({address});
if (res.getConfirmedTransactionsList().length > 0) {
lastFoundActiveAddressIndex = i;
transactionHistory.push(...res.getConfirmedTransactionsList());
console.log("Has transactions!");
}
console.log(transactionHistory.length);
}
})();
function getAddress(walletObj, network=null, cashAddress=false) {
if (network == null) {
network = bitcoin.networks.mainnet;
}
if (cashAddress == true) {
var publicKey = bitcoreCash.PublicKey(walletObj.publicKey);
var address = new bitcoreCash.Address(publicKey, network);
return (address.toString());
} else {
return (bitcoin.payments.p2pkh({pubkey:walletObj.publicKey, network:network}).address);
}
}
getAddress(walletObj, network="main", cashAddress=false) {
network = network.toLowerCase();
if (cashAddress == true) {
var publicKey = bitcoreCash.PublicKey(walletObj.publicKey);
switch (network) {
case "main":
var address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "mainnet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "livenet":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.livenet);
break;
case "test":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;
case "test3":
address = new bitcoreCash.Address(publicKey, bitcoreCash.Networks.testnet);
break;