From 139567d6c5c3afaba9d64eddc2edaa6cc0cf5060 Mon Sep 17 00:00:00 2001 From: junderw Date: Wed, 7 Aug 2019 17:37:52 +0900 Subject: [PATCH] Fix addInput and addOuput for Psbt --- ts_src/psbt.ts | 13 +++++++++---- types/psbt.d.ts | 14 +++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ts_src/psbt.ts b/ts_src/psbt.ts index eb09155..a83ced3 100644 --- a/ts_src/psbt.ts +++ b/ts_src/psbt.ts @@ -6,6 +6,7 @@ import { PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, + PsbtOutput, PsbtOutputUpdate, Transaction as ITransaction, TransactionFromBuffer, @@ -176,12 +177,12 @@ export class Psbt { return this; } - addInputs(inputDatas: TransactionInput[]): this { + addInputs(inputDatas: PsbtInputExtended[]): this { inputDatas.forEach(inputData => this.addInput(inputData)); return this; } - addInput(inputData: TransactionInput): this { + addInput(inputData: PsbtInputExtended): this { checkInputsForPartialSig(this.data.inputs, 'addInput'); const c = this.__CACHE; this.data.addInput(inputData); @@ -198,12 +199,12 @@ export class Psbt { return this; } - addOutputs(outputDatas: TransactionOutput[]): this { + addOutputs(outputDatas: PsbtOutputExtended[]): this { outputDatas.forEach(outputData => this.addOutput(outputData)); return this; } - addOutput(outputData: TransactionOutput): this { + addOutput(outputData: PsbtOutputExtended): this { checkInputsForPartialSig(this.data.inputs, 'addOutput'); const { address } = outputData as any; if (typeof address === 'string') { @@ -622,6 +623,10 @@ interface PsbtOpts { maximumFeeRate: number; } +interface PsbtInputExtended extends PsbtInput, TransactionInput {} + +interface PsbtOutputExtended extends PsbtOutput, TransactionOutput {} + interface HDSignerBase { /** * DER format compressed publicKey buffer diff --git a/types/psbt.d.ts b/types/psbt.d.ts index 04a3cfd..6a56636 100644 --- a/types/psbt.d.ts +++ b/types/psbt.d.ts @@ -1,6 +1,6 @@ /// import { Psbt as PsbtBase } from 'bip174'; -import { KeyValue, PsbtGlobalUpdate, PsbtInputUpdate, PsbtOutputUpdate, TransactionInput, TransactionOutput } from 'bip174/src/lib/interfaces'; +import { KeyValue, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate, TransactionInput, TransactionOutput } from 'bip174/src/lib/interfaces'; import { Signer, SignerAsync } from './ecpair'; import { Network } from './networks'; import { Transaction } from './transaction'; @@ -51,10 +51,10 @@ export declare class Psbt { setVersion(version: number): this; setLocktime(locktime: number): this; setInputSequence(inputIndex: number, sequence: number): this; - addInputs(inputDatas: TransactionInput[]): this; - addInput(inputData: TransactionInput): this; - addOutputs(outputDatas: TransactionOutput[]): this; - addOutput(outputData: TransactionOutput): this; + addInputs(inputDatas: PsbtInputExtended[]): this; + addInput(inputData: PsbtInputExtended): this; + addOutputs(outputDatas: PsbtOutputExtended[]): this; + addOutput(outputData: PsbtOutputExtended): this; extractTransaction(disableFeeCheck?: boolean): Transaction; getFeeRate(): number; finalizeAllInputs(): this; @@ -84,6 +84,10 @@ interface PsbtOptsOptional { network?: Network; maximumFeeRate?: number; } +interface PsbtInputExtended extends PsbtInput, TransactionInput { +} +interface PsbtOutputExtended extends PsbtOutput, TransactionOutput { +} interface HDSignerBase { /** * DER format compressed publicKey buffer