mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 18:00:17 +01:00
Merge pull request #6184 from BlueWallet/ref-_utxo
REF: unify this.utxo and this._utxo
This commit is contained in:
commit
e6b0240153
@ -912,17 +912,15 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet {
|
||||
this._utxo = this._utxo.concat(arr);
|
||||
}
|
||||
|
||||
// backward compatibility TODO: remove when we make sure `.utxo` is not used
|
||||
this.utxo = this._utxo;
|
||||
// this belongs in `.getUtxo()`
|
||||
for (const u of this.utxo) {
|
||||
for (const u of this._utxo) {
|
||||
u.txid = u.txId;
|
||||
u.amount = u.value;
|
||||
u.wif = this._getWifForAddress(u.address);
|
||||
if (!u.confirmations && u.height) u.confirmations = BlueElectrum.estimateCurrentBlockheight() - u.height;
|
||||
}
|
||||
|
||||
this.utxo = this.utxo.sort((a, b) => Number(a.amount) - Number(b.amount));
|
||||
this._utxo = this._utxo.sort((a, b) => Number(a.amount) - Number(b.amount));
|
||||
// more consistent, so txhex in unit tests wont change
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ export class AbstractWallet {
|
||||
balance: number;
|
||||
unconfirmed_balance: number;
|
||||
_address: string | false;
|
||||
utxo: Utxo[];
|
||||
_utxo: Utxo[];
|
||||
_lastTxFetch: number;
|
||||
_lastBalanceFetch: number;
|
||||
preferredBalanceUnit: BitcoinUnit;
|
||||
@ -63,7 +63,7 @@ export class AbstractWallet {
|
||||
this.balance = 0;
|
||||
this.unconfirmed_balance = 0;
|
||||
this._address = false; // cache
|
||||
this.utxo = [];
|
||||
this._utxo = [];
|
||||
this._lastTxFetch = 0;
|
||||
this._lastBalanceFetch = 0;
|
||||
this.preferredBalanceUnit = BitcoinUnit.BTC;
|
||||
|
@ -127,26 +127,26 @@ export class LegacyWallet extends AbstractWallet {
|
||||
const address = this.getAddress();
|
||||
if (!address) throw new Error('LegacyWallet: Invalid address');
|
||||
const utxos = await BlueElectrum.multiGetUtxoByAddress([address]);
|
||||
this.utxo = [];
|
||||
this._utxo = [];
|
||||
for (const arr of Object.values(utxos)) {
|
||||
this.utxo = this.utxo.concat(arr);
|
||||
this._utxo = this._utxo.concat(arr);
|
||||
}
|
||||
|
||||
// now we need to fetch txhash for each input as required by PSBT
|
||||
if (LegacyWallet.type !== this.type) return; // but only for LEGACY single-address wallets
|
||||
const txhexes = await BlueElectrum.multiGetTransactionByTxid(
|
||||
this.utxo.map(u => u.txId),
|
||||
this._utxo.map(u => u.txId),
|
||||
50,
|
||||
false,
|
||||
);
|
||||
|
||||
const newUtxos = [];
|
||||
for (const u of this.utxo) {
|
||||
for (const u of this._utxo) {
|
||||
if (txhexes[u.txId]) u.txhex = txhexes[u.txId];
|
||||
newUtxos.push(u);
|
||||
}
|
||||
|
||||
this.utxo = newUtxos;
|
||||
this._utxo = newUtxos;
|
||||
} catch (error) {
|
||||
console.warn(error);
|
||||
}
|
||||
@ -169,7 +169,7 @@ export class LegacyWallet extends AbstractWallet {
|
||||
*/
|
||||
getUtxo(respectFrozen = false): Utxo[] {
|
||||
let ret: Utxo[] = [];
|
||||
for (const u of this.utxo) {
|
||||
for (const u of this._utxo) {
|
||||
if (u.txId) u.txid = u.txId;
|
||||
if (!u.confirmations && u.height) u.confirmations = BlueElectrum.estimateCurrentBlockheight() - u.height;
|
||||
ret.push(u);
|
||||
|
@ -59,12 +59,12 @@ it('HD (BIP49) can create TX', async () => {
|
||||
|
||||
await hd.fetchBalance();
|
||||
await hd.fetchUtxo();
|
||||
assert.ok(typeof hd.utxo[0].confirmations === 'number');
|
||||
assert.ok(hd.utxo[0].txid);
|
||||
assert.ok(hd.utxo[0].vout !== undefined);
|
||||
assert.ok(hd.utxo[0].amount);
|
||||
assert.ok(hd.utxo[0].address);
|
||||
assert.ok(hd.utxo[0].wif);
|
||||
assert.ok(typeof hd._utxo[0].confirmations === 'number');
|
||||
assert.ok(hd._utxo[0].txid);
|
||||
assert.ok(hd._utxo[0].vout !== undefined);
|
||||
assert.ok(hd._utxo[0].amount);
|
||||
assert.ok(hd._utxo[0].address);
|
||||
assert.ok(hd._utxo[0].wif);
|
||||
|
||||
let txNew = hd.createTransaction(
|
||||
hd.getUtxo(),
|
||||
@ -178,10 +178,10 @@ it('Segwit HD (BIP49) can fetch balance with many used addresses in hierarchy',
|
||||
assert.strictEqual(hd.getBalance(), 51432);
|
||||
|
||||
await hd.fetchUtxo();
|
||||
assert.ok(hd.utxo.length > 0);
|
||||
assert.ok(hd.utxo[0].txid);
|
||||
assert.ok(hd.utxo[0].vout === 0);
|
||||
assert.ok(hd.utxo[0].amount);
|
||||
assert.ok(hd._utxo.length > 0);
|
||||
assert.ok(hd._utxo[0].txid);
|
||||
assert.ok(hd._utxo[0].vout === 0);
|
||||
assert.ok(hd._utxo[0].amount);
|
||||
|
||||
await hd.fetchTransactions();
|
||||
assert.strictEqual(hd.getTransactions().length, 107);
|
||||
|
@ -99,7 +99,7 @@ describe('LegacyWallet', function () {
|
||||
const w = new LegacyWallet();
|
||||
w._address = '12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX';
|
||||
await w.fetchUtxo();
|
||||
assert.ok(w.utxo.length > 0, 'unexpected empty UTXO');
|
||||
assert.ok(w._utxo.length > 0, 'unexpected empty UTXO');
|
||||
assert.ok(w.getUtxo().length > 0, 'unexpected empty UTXO');
|
||||
|
||||
assert.ok(w.getUtxo()[0].value);
|
||||
|
@ -1988,7 +1988,6 @@ describe('multisig-wallet (native segwit)', () => {
|
||||
'UR:CRYPTO-OUTPUT/TAADMETAADMSOEADAOAOLSTAADDLOLAOWKAXHDCLAOCEBDFLNNTKJTIOJSFSURBNFXRPEEHKDLGYRTEMRPYTGYZOCASWENCYMKPAVWJKHYAAHDCXJEFTGSZOIMFEYNDYHYZEJTBAMSJEHLDSRDDIYLSRFYTSZTKNRNYLRNDPAMTLDPZCAHTAADEHOEADAEAOAEAMTAADDYOTADLOCSDYYKAEYKAEYKAOYKAOCYUOHFJPKOAXAAAYCYCSYASAVDTAADDLOLAOWKAXHDCLAXMSZTWZDIGERYDKFSFWTYDPFNDKLNAYSWTTMUHYZTOXHSETPEWSFXPEAYWLJSDEMTAAHDCXSPLTSTDPNTLESANSUTTLPRPFHNVSPFCNMHESOYGASTLRPYVAATNNDKFYHLQZPKLEAHTAADEHOEADAEAOAEAMTAADDYOTADLOCSDYYKAEYKAEYKAOYKAOCYWZFEPLETAXAAAYCYCPCKRENBTAADDLOLAOWKAXHDCLAOLSFWYKYLKTFHJLPYEMGLCEDPFNSNRDDSRFASEOZTGWIALFLUIYDNFXHGVESFEMMEAAHDCXHTZETLJNKPHHAYLSCXWPNDSWPSTPGTEOJKKGHDAELSKPNNBKBSYAWZJTFWNNBDKTAHTAADEHOEADAEAOAEAMTAADDYOTADLOCSDYYKAEYKAEYKAOYKAOCYSKTPJPMSAXAAAYCYCEBKWLAMTDWZGRZE\n';
|
||||
const decoder = new BlueURDecoder();
|
||||
decoder.receivePart(payload);
|
||||
console.log(decoder.isComplete());
|
||||
|
||||
const data = decoder.toString();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user