Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Export PSBT getter types
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Apr 27, 2020
1 parent 361ea7c commit de0bbf5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ts_src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as script from './script';
export { ECPair, address, bip32, crypto, networks, payments, script };

export { Block } from './block';
export { Psbt } from './psbt';
export { Psbt, PsbtTxInput, PsbtTxOutput } from './psbt';
export { OPS as opcodes } from './script';
export { Transaction } from './transaction';
export { TransactionBuilder } from './transaction_builder';
Expand Down
13 changes: 10 additions & 3 deletions ts_src/psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Transaction as ITransaction,
TransactionFromBuffer,
TransactionInput,
TransactionOutput,
} from 'bip174/src/lib/interfaces';
import { checkForInput, checkForOutput } from 'bip174/src/lib/utils';
import { fromOutputScript, toOutputScript } from './address';
Expand All @@ -27,6 +26,14 @@ import * as payments from './payments';
import * as bscript from './script';
import { Output, Transaction } from './transaction';

export interface PsbtTxInput extends TransactionInput {
hash: Buffer;
}

export interface PsbtTxOutput extends Output {
address: string;
}

/**
* These are the default arguments for a Psbt instance.
*/
Expand Down Expand Up @@ -146,15 +153,15 @@ export class Psbt {
this.setLocktime(locktime);
}

get txInputs(): TransactionInput[] {
get txInputs(): PsbtTxInput[] {
return this.__CACHE.__TX.ins.map(input => ({
hash: cloneBuffer(input.hash),
index: input.index,
sequence: input.sequence,
}));
}

get txOutputs(): TransactionOutput[] {
get txOutputs(): PsbtTxOutput[] {
return this.__CACHE.__TX.outs.map(output => ({
script: cloneBuffer(output.script),
value: output.value,
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as payments from './payments';
import * as script from './script';
export { ECPair, address, bip32, crypto, networks, payments, script };
export { Block } from './block';
export { Psbt } from './psbt';
export { Psbt, PsbtTxInput, PsbtTxOutput } from './psbt';
export { OPS as opcodes } from './script';
export { Transaction } from './transaction';
export { TransactionBuilder } from './transaction_builder';
Expand Down
14 changes: 10 additions & 4 deletions types/psbt.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Psbt as PsbtBase } from 'bip174';
import { KeyValue, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate, TransactionInput, TransactionOutput } from 'bip174/src/lib/interfaces';
import { KeyValue, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate, TransactionInput } from 'bip174/src/lib/interfaces';
import { Signer, SignerAsync } from './ecpair';
import { Network } from './networks';
import { Transaction } from './transaction';
import { Output, Transaction } from './transaction';
export interface PsbtTxInput extends TransactionInput {
hash: Buffer;
}
export interface PsbtTxOutput extends Output {
address: string;
}
/**
* Psbt class can parse and generate a PSBT binary based off of the BIP174.
* There are 6 roles that this class fulfills. (Explained in BIP174)
Expand Down Expand Up @@ -46,8 +52,8 @@ export declare class Psbt {
readonly inputCount: number;
version: number;
locktime: number;
readonly txInputs: TransactionInput[];
readonly txOutputs: TransactionOutput[];
readonly txInputs: PsbtTxInput[];
readonly txOutputs: PsbtTxOutput[];
combine(...those: Psbt[]): this;
clone(): Psbt;
setMaximumFeeRate(satoshiPerByte: number): void;
Expand Down

0 comments on commit de0bbf5

Please sign in to comment.