Fix addInput and addOuput for Psbt

This commit is contained in:
junderw 2019-08-07 17:37:52 +09:00
parent 099360a13d
commit 139567d6c5
No known key found for this signature in database
GPG key ID: B256185D3A971908
2 changed files with 18 additions and 9 deletions

View file

@ -6,6 +6,7 @@ import {
PsbtGlobalUpdate, PsbtGlobalUpdate,
PsbtInput, PsbtInput,
PsbtInputUpdate, PsbtInputUpdate,
PsbtOutput,
PsbtOutputUpdate, PsbtOutputUpdate,
Transaction as ITransaction, Transaction as ITransaction,
TransactionFromBuffer, TransactionFromBuffer,
@ -176,12 +177,12 @@ export class Psbt {
return this; return this;
} }
addInputs(inputDatas: TransactionInput[]): this { addInputs(inputDatas: PsbtInputExtended[]): this {
inputDatas.forEach(inputData => this.addInput(inputData)); inputDatas.forEach(inputData => this.addInput(inputData));
return this; return this;
} }
addInput(inputData: TransactionInput): this { addInput(inputData: PsbtInputExtended): this {
checkInputsForPartialSig(this.data.inputs, 'addInput'); checkInputsForPartialSig(this.data.inputs, 'addInput');
const c = this.__CACHE; const c = this.__CACHE;
this.data.addInput(inputData); this.data.addInput(inputData);
@ -198,12 +199,12 @@ export class Psbt {
return this; return this;
} }
addOutputs(outputDatas: TransactionOutput[]): this { addOutputs(outputDatas: PsbtOutputExtended[]): this {
outputDatas.forEach(outputData => this.addOutput(outputData)); outputDatas.forEach(outputData => this.addOutput(outputData));
return this; return this;
} }
addOutput(outputData: TransactionOutput): this { addOutput(outputData: PsbtOutputExtended): this {
checkInputsForPartialSig(this.data.inputs, 'addOutput'); checkInputsForPartialSig(this.data.inputs, 'addOutput');
const { address } = outputData as any; const { address } = outputData as any;
if (typeof address === 'string') { if (typeof address === 'string') {
@ -622,6 +623,10 @@ interface PsbtOpts {
maximumFeeRate: number; maximumFeeRate: number;
} }
interface PsbtInputExtended extends PsbtInput, TransactionInput {}
interface PsbtOutputExtended extends PsbtOutput, TransactionOutput {}
interface HDSignerBase { interface HDSignerBase {
/** /**
* DER format compressed publicKey buffer * DER format compressed publicKey buffer

14
types/psbt.d.ts vendored
View file

@ -1,6 +1,6 @@
/// <reference types="node" /> /// <reference types="node" />
import { Psbt as PsbtBase } from 'bip174'; 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 { Signer, SignerAsync } from './ecpair';
import { Network } from './networks'; import { Network } from './networks';
import { Transaction } from './transaction'; import { Transaction } from './transaction';
@ -51,10 +51,10 @@ export declare class Psbt {
setVersion(version: number): this; setVersion(version: number): this;
setLocktime(locktime: number): this; setLocktime(locktime: number): this;
setInputSequence(inputIndex: number, sequence: number): this; setInputSequence(inputIndex: number, sequence: number): this;
addInputs(inputDatas: TransactionInput[]): this; addInputs(inputDatas: PsbtInputExtended[]): this;
addInput(inputData: TransactionInput): this; addInput(inputData: PsbtInputExtended): this;
addOutputs(outputDatas: TransactionOutput[]): this; addOutputs(outputDatas: PsbtOutputExtended[]): this;
addOutput(outputData: TransactionOutput): this; addOutput(outputData: PsbtOutputExtended): this;
extractTransaction(disableFeeCheck?: boolean): Transaction; extractTransaction(disableFeeCheck?: boolean): Transaction;
getFeeRate(): number; getFeeRate(): number;
finalizeAllInputs(): this; finalizeAllInputs(): this;
@ -84,6 +84,10 @@ interface PsbtOptsOptional {
network?: Network; network?: Network;
maximumFeeRate?: number; maximumFeeRate?: number;
} }
interface PsbtInputExtended extends PsbtInput, TransactionInput {
}
interface PsbtOutputExtended extends PsbtOutput, TransactionOutput {
}
interface HDSignerBase { interface HDSignerBase {
/** /**
* DER format compressed publicKey buffer * DER format compressed publicKey buffer