mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +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() +
|
||||
'?limit=2000&after=' +
|
||||
maxHeight +
|
||||
((useBlockcypherTokens && '&token=' + this.getRandomBlockcypherToken()) || ''),
|
||||
((useBlockcypherTokens &&
|
||||
'&token=' + this.getRandomBlockcypherToken()) ||
|
||||
''),
|
||||
);
|
||||
json = response.body;
|
||||
if (
|
||||
@ -190,6 +192,18 @@ export class LegacyWallet extends AbstractWallet {
|
||||
// how much came out
|
||||
value = 0;
|
||||
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) {
|
||||
// found our address in outs of this TX
|
||||
value -= inp.output_value;
|
||||
|
@ -28,4 +28,16 @@ export class SegwitBech32Wallet extends LegacyWallet {
|
||||
|
||||
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)';
|
||||
}
|
||||
|
||||
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() {
|
||||
if (this._address) return this._address;
|
||||
let address;
|
||||
|
Loading…
Reference in New Issue
Block a user