From 48967652cac325c621edf556249a59329277fe7e Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 29 May 2020 13:40:53 +0700 Subject: [PATCH] Handle non-standard output types in Psbt.txOutputs --- CHANGELOG.md | 4 ++++ src/psbt.js | 16 +++++++++++----- ts_src/psbt.ts | 16 +++++++++++----- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81884f6..f19cc62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 5.1.9 +__fixed__ +- Fixed errors for psbt.txOutputs getter (#1578) + # 5.1.8 __fixed__ - Throw errors when p2wsh or p2wpkh contain uncompressed pubkeys (#1573) diff --git a/src/psbt.js b/src/psbt.js index 134be87..bb41899 100644 --- a/src/psbt.js +++ b/src/psbt.js @@ -117,11 +117,17 @@ class Psbt { })); } get txOutputs() { - return this.__CACHE.__TX.outs.map(output => ({ - script: bufferutils_1.cloneBuffer(output.script), - value: output.value, - address: address_1.fromOutputScript(output.script, this.opts.network), - })); + return this.__CACHE.__TX.outs.map(output => { + let address; + try { + address = address_1.fromOutputScript(output.script, this.opts.network); + } catch (_) {} + return { + script: bufferutils_1.cloneBuffer(output.script), + value: output.value, + address, + }; + }); } combine(...those) { this.data.combine(...those.map(o => o.data)); diff --git a/ts_src/psbt.ts b/ts_src/psbt.ts index 89491b9..a09ee0c 100644 --- a/ts_src/psbt.ts +++ b/ts_src/psbt.ts @@ -155,11 +155,17 @@ export class Psbt { } get txOutputs(): TransactionOutput[] { - return this.__CACHE.__TX.outs.map(output => ({ - script: cloneBuffer(output.script), - value: output.value, - address: fromOutputScript(output.script, this.opts.network), - })); + return this.__CACHE.__TX.outs.map(output => { + let address; + try { + address = fromOutputScript(output.script, this.opts.network); + } catch (_) {} + return { + script: cloneBuffer(output.script), + value: output.value, + address, + }; + }); } combine(...those: Psbt[]): this {