Add getters for Psbt.{txVersion,txLocktime,txInputs,txOutputs}
This commit is contained in:
parent
c95e15de01
commit
854c601342
3 changed files with 43 additions and 0 deletions
17
src/psbt.js
17
src/psbt.js
|
@ -97,6 +97,18 @@ class Psbt {
|
||||||
get inputCount() {
|
get inputCount() {
|
||||||
return this.data.inputs.length;
|
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) {
|
combine(...those) {
|
||||||
this.data.combine(...those.map(o => o.data));
|
this.data.combine(...those.map(o => o.data));
|
||||||
return this;
|
return this;
|
||||||
|
@ -579,6 +591,11 @@ class PsbtTransaction {
|
||||||
return this.tx.toBuffer();
|
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) {
|
function canFinalize(input, script, scriptType) {
|
||||||
switch (scriptType) {
|
switch (scriptType) {
|
||||||
case 'pubkey':
|
case 'pubkey':
|
||||||
|
|
|
@ -129,6 +129,22 @@ export class Psbt {
|
||||||
return this.data.inputs.length;
|
return this.data.inputs.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get txVersion(): number {
|
||||||
|
return this.__CACHE.__TX.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
get txLocktime(): number {
|
||||||
|
return this.__CACHE.__TX.locktime;
|
||||||
|
}
|
||||||
|
|
||||||
|
get txInputs(): TransactionInput[] {
|
||||||
|
return deepClone(this.__CACHE.__TX.ins);
|
||||||
|
}
|
||||||
|
|
||||||
|
get txOutputs(): TransactionInput[] {
|
||||||
|
return deepClone(this.__CACHE.__TX.outs);
|
||||||
|
}
|
||||||
|
|
||||||
combine(...those: Psbt[]): this {
|
combine(...those: Psbt[]): this {
|
||||||
this.data.combine(...those.map(o => o.data));
|
this.data.combine(...those.map(o => o.data));
|
||||||
return this;
|
return this;
|
||||||
|
@ -757,6 +773,12 @@ class PsbtTransaction implements ITransaction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deepClone(obj: any): any {
|
||||||
|
return JSON.parse(JSON.stringify(obj), (_, value) =>
|
||||||
|
value.type === 'Buffer' ? Buffer.from(value.data) : value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function canFinalize(
|
function canFinalize(
|
||||||
input: PsbtInput,
|
input: PsbtInput,
|
||||||
script: Buffer,
|
script: Buffer,
|
||||||
|
|
4
types/psbt.d.ts
vendored
4
types/psbt.d.ts
vendored
|
@ -44,6 +44,10 @@ export declare class Psbt {
|
||||||
private opts;
|
private opts;
|
||||||
constructor(opts?: PsbtOptsOptional, data?: PsbtBase);
|
constructor(opts?: PsbtOptsOptional, data?: PsbtBase);
|
||||||
readonly inputCount: number;
|
readonly inputCount: number;
|
||||||
|
readonly txVersion: number;
|
||||||
|
readonly txLocktime: number;
|
||||||
|
readonly txInputs: TransactionInput[];
|
||||||
|
readonly txOutputs: TransactionInput[];
|
||||||
combine(...those: Psbt[]): this;
|
combine(...those: Psbt[]): this;
|
||||||
clone(): Psbt;
|
clone(): Psbt;
|
||||||
setMaximumFeeRate(satoshiPerByte: number): void;
|
setMaximumFeeRate(satoshiPerByte: number): void;
|
||||||
|
|
Loading…
Add table
Reference in a new issue