mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 09:50:15 +01:00
FIX: better input address parsing
This commit is contained in:
parent
11078d9bf7
commit
5cb8bf04da
@ -115,7 +115,9 @@ export class LegacyWallet extends AbstractWallet {
|
|||||||
this.getAddress() +
|
this.getAddress() +
|
||||||
'?limit=2000&after=' +
|
'?limit=2000&after=' +
|
||||||
maxHeight +
|
maxHeight +
|
||||||
((useBlockcypherTokens && '&token=' + this.getRandomBlockcypherToken()) || ''),
|
((useBlockcypherTokens &&
|
||||||
|
'&token=' + this.getRandomBlockcypherToken()) ||
|
||||||
|
''),
|
||||||
);
|
);
|
||||||
json = response.body;
|
json = response.body;
|
||||||
if (
|
if (
|
||||||
@ -190,6 +192,18 @@ export class LegacyWallet extends AbstractWallet {
|
|||||||
// how much came out
|
// how much came out
|
||||||
value = 0;
|
value = 0;
|
||||||
for (let inp of tx.inputs) {
|
for (let inp of tx.inputs) {
|
||||||
|
if (!inp.addresses) {
|
||||||
|
console.log('inp.addresses empty');
|
||||||
|
console.log('got witness', inp.witness); // TODO
|
||||||
|
|
||||||
|
inp.addresses = [];
|
||||||
|
if (inp.witness && inp.witness[1]) {
|
||||||
|
let address = SegwitBech32Wallet.witnessToAddress(inp.witness[1]);
|
||||||
|
inp.addresses.push(address);
|
||||||
|
} else {
|
||||||
|
inp.addresses.push('???');
|
||||||
|
}
|
||||||
|
}
|
||||||
if (inp.addresses.indexOf(this.getAddress()) !== -1) {
|
if (inp.addresses.indexOf(this.getAddress()) !== -1) {
|
||||||
// found our address in outs of this TX
|
// found our address in outs of this TX
|
||||||
value -= inp.output_value;
|
value -= inp.output_value;
|
||||||
|
@ -28,4 +28,16 @@ export class SegwitBech32Wallet extends LegacyWallet {
|
|||||||
|
|
||||||
return this._address;
|
return this._address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static witnessToAddress(witness) {
|
||||||
|
const pubKey = Buffer.from(witness, 'hex');
|
||||||
|
const pubKeyHash = bitcoin.crypto.hash160(pubKey);
|
||||||
|
const scriptPubKey = bitcoin.script.witnessPubKeyHash.output.encode(
|
||||||
|
pubKeyHash,
|
||||||
|
);
|
||||||
|
return bitcoin.address.fromOutputScript(
|
||||||
|
scriptPubKey,
|
||||||
|
bitcoin.networks.bitcoin,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,22 @@ export class SegwitP2SHWallet extends LegacyWallet {
|
|||||||
return 'SegWit (P2SH)';
|
return 'SegWit (P2SH)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static witnessToAddress(witness) {
|
||||||
|
const pubKey = Buffer.from(witness, 'hex');
|
||||||
|
const pubKeyHash = bitcoin.crypto.hash160(pubKey);
|
||||||
|
const redeemScript = bitcoin.script.witnessPubKeyHash.output.encode(
|
||||||
|
pubKeyHash,
|
||||||
|
);
|
||||||
|
const redeemScriptHash = bitcoin.crypto.hash160(redeemScript);
|
||||||
|
const scriptPubkey = bitcoin.script.scriptHash.output.encode(
|
||||||
|
redeemScriptHash,
|
||||||
|
);
|
||||||
|
return bitcoin.address.fromOutputScript(
|
||||||
|
scriptPubkey,
|
||||||
|
bitcoin.networks.bitcoin,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
getAddress() {
|
getAddress() {
|
||||||
if (this._address) return this._address;
|
if (this._address) return this._address;
|
||||||
let address;
|
let address;
|
||||||
|
Loading…
Reference in New Issue
Block a user