mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 18:00:17 +01:00
Merge pull request #3939 from BlueWallet/fix-3877
FIX: support for electrum backed by bitcoin code 22+ (closes #3877)
This commit is contained in:
commit
5f57986f53
@ -392,11 +392,17 @@ module.exports.getTransactionsFullByAddress = async function (address) {
|
||||
if (prevTxForVin.vout[input.vout].scriptPubKey && prevTxForVin.vout[input.vout].scriptPubKey.addresses) {
|
||||
input.addresses = prevTxForVin.vout[input.vout].scriptPubKey.addresses;
|
||||
}
|
||||
// in bitcoin core 22.0.0+ they removed `.addresses` and replaced it with plain `.address`:
|
||||
if (prevTxForVin.vout[input.vout]?.scriptPubKey?.address) {
|
||||
input.addresses = [prevTxForVin.vout[input.vout].scriptPubKey.address];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const output of full.vout) {
|
||||
if (output.scriptPubKey && output.scriptPubKey.addresses) output.addresses = output.scriptPubKey.addresses;
|
||||
// in bitcoin core 22.0.0+ they removed `.addresses` and replaced it with plain `.address`:
|
||||
if (output?.scriptPubKey?.address) output.addresses = [output.scriptPubKey.address];
|
||||
}
|
||||
full.inputs = full.vin;
|
||||
full.outputs = full.vout;
|
||||
@ -647,6 +653,13 @@ module.exports.multiGetTransactionByTxid = async function (txids, batchsize, ver
|
||||
}
|
||||
}
|
||||
|
||||
// in bitcoin core 22.0.0+ they removed `.addresses` and replaced it with plain `.address`:
|
||||
for (const txid of Object.keys(ret) ?? []) {
|
||||
for (const vout of ret[txid].vout ?? []) {
|
||||
if (vout?.scriptPubKey?.address) vout.scriptPubKey.addresses = [vout.scriptPubKey.address];
|
||||
}
|
||||
}
|
||||
|
||||
// saving cache:
|
||||
realm.write(() => {
|
||||
for (const txid of Object.keys(ret)) {
|
||||
|
@ -158,6 +158,7 @@ describe('BlueElectrum', () => {
|
||||
assert.ok(!tx.vin);
|
||||
assert.ok(!tx.vout);
|
||||
assert.ok(tx.inputs);
|
||||
assert.strictEqual(tx.inputs[0]?.addresses[0], 'bc1q7td49wcxfad9v42kmvg5refn9wcnvnru4395qw');
|
||||
assert.ok(tx.inputs[0].addresses.length > 0);
|
||||
assert.ok(tx.inputs[0].value > 0);
|
||||
assert.ok(tx.outputs);
|
||||
@ -263,6 +264,11 @@ describe('BlueElectrum', () => {
|
||||
assert.ok(txdatas['5e2fa84148a7389537434b3ad12fcae71ed43ce5fb0f016a7f154a9b99a973df'].vin);
|
||||
assert.ok(txdatas['5e2fa84148a7389537434b3ad12fcae71ed43ce5fb0f016a7f154a9b99a973df'].vout);
|
||||
assert.ok(txdatas['5e2fa84148a7389537434b3ad12fcae71ed43ce5fb0f016a7f154a9b99a973df'].blocktime);
|
||||
assert.strictEqual(
|
||||
txdatas['5e2fa84148a7389537434b3ad12fcae71ed43ce5fb0f016a7f154a9b99a973df']?.vout[0]?.scriptPubKey?.addresses[0],
|
||||
'bc1qp09gdem9xepasp4zxa2fxyvr8wazhms0wvtds9',
|
||||
);
|
||||
|
||||
assert.ok(Object.keys(txdatas).length === 4);
|
||||
if (disableBatching) BlueElectrum.setBatchingEnabled();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user