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,
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

14
types/psbt.d.ts vendored
View file

@ -1,6 +1,6 @@
/// <reference types="node" />
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