Skip to content

Commit 4896765

Browse files
lukechildsjunderw
authored andcommitted
Handle non-standard output types in Psbt.txOutputs
1 parent 85ee2a3 commit 4896765

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 5.1.9
2+
__fixed__
3+
- Fixed errors for psbt.txOutputs getter (#1578)
4+
15
# 5.1.8
26
__fixed__
37
- Throw errors when p2wsh or p2wpkh contain uncompressed pubkeys (#1573)

src/psbt.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,17 @@ class Psbt {
117117
}));
118118
}
119119
get txOutputs() {
120-
return this.__CACHE.__TX.outs.map(output => ({
121-
script: bufferutils_1.cloneBuffer(output.script),
122-
value: output.value,
123-
address: address_1.fromOutputScript(output.script, this.opts.network),
124-
}));
120+
return this.__CACHE.__TX.outs.map(output => {
121+
let address;
122+
try {
123+
address = address_1.fromOutputScript(output.script, this.opts.network);
124+
} catch (_) {}
125+
return {
126+
script: bufferutils_1.cloneBuffer(output.script),
127+
value: output.value,
128+
address,
129+
};
130+
});
125131
}
126132
combine(...those) {
127133
this.data.combine(...those.map(o => o.data));

ts_src/psbt.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,17 @@ export class Psbt {
155155
}
156156

157157
get txOutputs(): TransactionOutput[] {
158-
return this.__CACHE.__TX.outs.map(output => ({
159-
script: cloneBuffer(output.script),
160-
value: output.value,
161-
address: fromOutputScript(output.script, this.opts.network),
162-
}));
158+
return this.__CACHE.__TX.outs.map(output => {
159+
let address;
160+
try {
161+
address = fromOutputScript(output.script, this.opts.network);
162+
} catch (_) {}
163+
return {
164+
script: cloneBuffer(output.script),
165+
value: output.value,
166+
address,
167+
};
168+
});
163169
}
164170

165171
combine(...those: Psbt[]): this {

0 commit comments

Comments
 (0)