Merge pull request #3939 from BlueWallet/fix-3877

FIX: support for electrum backed by bitcoin code 22+ (closes #3877)
This commit is contained in:
GLaDOS 2021-09-28 22:32:13 +01:00 committed by GitHub
commit 5f57986f53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -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)) {

View File

@ -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();
});