From f96ea249ad2e45e23facee18d1932c5df0cdca39 Mon Sep 17 00:00:00 2001 From: Duddino Date: Sun, 27 Nov 2022 17:41:46 +0100 Subject: [PATCH] Fixed undelegation --- index.html | 4 +--- scripts/network.js | 38 +++++++++++++------------------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/index.html b/index.html index 4453428f0..78fde6727 100644 --- a/index.html +++ b/index.html @@ -1708,9 +1708,7 @@

Signed Raw Transaction

} // The primary Standard-to-Cold output - // Until we can get blockbook to tell us which address are involved in cold staking - // We will only use the first key - cTx.addcoldstakingoutput(await masterKey.getAddress(getDerivationPath(masterKey.isHardwareWallet)), coldAddr, nValue / COIN); + cTx.addcoldstakingoutput(await getNewAddress(), coldAddr, nValue / COIN); // Debug-only verbose response if (debug) domHumanReadable.innerHTML = "Balance: " + (nBalance / COIN) + "
Fee: " + (nFee / COIN) + "
To: " + coldAddr + "
Sent: " + (nValue / COIN) + (nChange > 0 ? "
Change Address: " + changeAddress + "
Change: " + (nChange / COIN) : ""); diff --git a/scripts/network.js b/scripts/network.js index ff22ed67f..c60505350 100644 --- a/scripts/network.js +++ b/scripts/network.js @@ -248,31 +248,19 @@ var getUTXOsHeavy = async function() { for (const cOut of cTx.vout) { if (cOut.spent) continue; // We don't care about spent outputs const paths = cOut.addresses.map(strAddr => mapPaths.get(strAddr)).filter(v => v); - // If an absence of any address, or a Cold Staking address is detected, we mark this as a delegated UTXO - if (cOut.addresses.length === 0 || cOut.addresses.some(strAddr => strAddr.startsWith(cChainParams.current.STAKING_PREFIX))) { - arrDelegatedUTXOs.push({ - 'id': cTx.txid, - 'vout': cOut.n, - 'sats': parseInt(cOut.value), - 'script': cOut.hex, - // Until we can get blockbook to tell us which address are involved in cold staking - // We will only use the first key - 'path': getDerivationPath(masterKey.isHardwareWallet), - }); - } - // Otherwise, an address matches one of ours - else if (paths.length > 0) { - // Blockbook still returns 119' as the coinType, even in testnet - let path = paths[0].split("/"); - path[2] = (masterKey.isHardwareWallet ? cChainParams.current.BIP44_TYPE_LEDGER : cChainParams.current.BIP44_TYPE) + "'"; - cachedUTXOs.push({ - 'id': cTx.txid, - 'vout': cOut.n, - 'sats': parseInt(cOut.value), - 'script': cOut.hex, - 'path': path.join("/"), - }); - } + // No addresses match ours + if (!paths.length) continue; + const arrToPush = cOut.addresses.some(strAddr => strAddr.startsWith(cChainParams.current.STAKING_PREFIX)) ? arrDelegatedUTXOs : cachedUTXOs; + // Blockbook still returns 119' as the coinType, even in testnet + let path = paths[0].split("/"); + path[2] = (masterKey.isHardwareWallet ? cChainParams.current.BIP44_TYPE_LEDGER : cChainParams.current.BIP44_TYPE) + "'"; + arrToPush.push({ + 'id': cTx.txid, + 'vout': cOut.n, + 'sats': parseInt(cOut.value), + 'script': cOut.hex, + 'path': path.join("/"), + }); } } // Update UI