From 48e54514f417170663541bf56d2f6a8b105aee56 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 14 Jun 2019 15:19:24 +0700 Subject: [PATCH] Store reference to imported PSBT --- src/transaction_builder_v2.js | 10 +++++++--- ts_src/transaction_builder_v2.ts | 12 +++++++++--- types/transaction_builder_v2.d.ts | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/transaction_builder_v2.js b/src/transaction_builder_v2.js index 3cabe06..c4b744d 100644 --- a/src/transaction_builder_v2.js +++ b/src/transaction_builder_v2.js @@ -31,6 +31,7 @@ class TransactionBuilderV2 { this.__INPUTS = []; this.__TX = new transaction_1.Transaction(); this.__TX.version = 2; + this.__PSBT = ''; this.__USE_LOW_R = false; } static fromTransaction(transaction, network) { @@ -88,8 +89,9 @@ class TransactionBuilderV2 { tx.setWitness(vin, script_1.decompile(witnessElements)); } }); - // TODO: Store reference to imported PSBT so we we can merge metadata into the PSBT we export from toPsbtString() - return TransactionBuilderV2.fromTransaction(tx, network); + const txb = TransactionBuilderV2.fromTransaction(tx, network); + txb.__PSBT = psbtString; + return txb; } setLowR(setting) { typeforce(typeforce.maybe(typeforce.Boolean), setting); @@ -246,7 +248,9 @@ class TransactionBuilderV2 { version, }); // TODO: Add signature data to PSBT - // TODO: Merge with imported PSBT if exists so we don't lose data + if (this.__PSBT) { + // TODO: Merge with imported PSBT if exists so we don't lose data + } return Buffer.from(psbt, 'hex').toString('base64'); } __addInputUnsafe(txHash, vout, options) { diff --git a/ts_src/transaction_builder_v2.ts b/ts_src/transaction_builder_v2.ts index 9d9b29a..8f99a9e 100644 --- a/ts_src/transaction_builder_v2.ts +++ b/ts_src/transaction_builder_v2.ts @@ -137,14 +137,17 @@ export class TransactionBuilderV2 { } }); - // TODO: Store reference to imported PSBT so we we can merge metadata into the PSBT we export from toPsbtString() + const txb = TransactionBuilderV2.fromTransaction(tx, network); - return TransactionBuilderV2.fromTransaction(tx, network); + txb.__PSBT = psbtString; + + return txb; } private __PREV_TX_SET: { [index: string]: boolean }; private __INPUTS: TxbInput[]; private __TX: Transaction; + private __PSBT: string; private __USE_LOW_R: boolean; // WARNING: maximumFeeRate is __NOT__ to be relied on, @@ -157,6 +160,7 @@ export class TransactionBuilderV2 { this.__INPUTS = []; this.__TX = new Transaction(); this.__TX.version = 2; + this.__PSBT = ''; this.__USE_LOW_R = false; } @@ -364,7 +368,9 @@ export class TransactionBuilderV2 { // TODO: Add signature data to PSBT - // TODO: Merge with imported PSBT if exists so we don't lose data + if (this.__PSBT) { + // TODO: Merge with imported PSBT if exists so we don't lose data + } return Buffer.from(psbt, 'hex').toString('base64'); } diff --git a/types/transaction_builder_v2.d.ts b/types/transaction_builder_v2.d.ts index 903f8ca..29caa36 100644 --- a/types/transaction_builder_v2.d.ts +++ b/types/transaction_builder_v2.d.ts @@ -10,6 +10,7 @@ export declare class TransactionBuilderV2 { private __PREV_TX_SET; private __INPUTS; private __TX; + private __PSBT; private __USE_LOW_R; constructor(network?: Network, maximumFeeRate?: number); setLowR(setting?: boolean): boolean;