Add getters for Psbt.{txVersion,txLocktime,txInputs,txOutputs}

This commit is contained in:
Luke Childs 2020-04-26 14:30:13 +07:00
parent c95e15de01
commit 854c601342
3 changed files with 43 additions and 0 deletions

View file

@ -97,6 +97,18 @@ class Psbt {
get inputCount() {
return this.data.inputs.length;
}
get txVersion() {
return this.__CACHE.__TX.version;
}
get txLocktime() {
return this.__CACHE.__TX.locktime;
}
get txInputs() {
return deepClone(this.__CACHE.__TX.ins);
}
get txOutputs() {
return deepClone(this.__CACHE.__TX.outs);
}
combine(...those) {
this.data.combine(...those.map(o => o.data));
return this;
@ -579,6 +591,11 @@ class PsbtTransaction {
return this.tx.toBuffer();
}
}
function deepClone(obj) {
return JSON.parse(JSON.stringify(obj), (_, value) =>
value.type === 'Buffer' ? Buffer.from(value.data) : value,
);
}
function canFinalize(input, script, scriptType) {
switch (scriptType) {
case 'pubkey':