Browse Source

Store reference to imported PSBT

psbt-support
Luke Childs 6 years ago
parent
commit
48e54514f4
  1. 10
      src/transaction_builder_v2.js
  2. 12
      ts_src/transaction_builder_v2.ts
  3. 1
      types/transaction_builder_v2.d.ts

10
src/transaction_builder_v2.js

@ -31,6 +31,7 @@ class TransactionBuilderV2 {
this.__INPUTS = []; this.__INPUTS = [];
this.__TX = new transaction_1.Transaction(); this.__TX = new transaction_1.Transaction();
this.__TX.version = 2; this.__TX.version = 2;
this.__PSBT = '';
this.__USE_LOW_R = false; this.__USE_LOW_R = false;
} }
static fromTransaction(transaction, network) { static fromTransaction(transaction, network) {
@ -88,8 +89,9 @@ class TransactionBuilderV2 {
tx.setWitness(vin, script_1.decompile(witnessElements)); 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() const txb = TransactionBuilderV2.fromTransaction(tx, network);
return TransactionBuilderV2.fromTransaction(tx, network); txb.__PSBT = psbtString;
return txb;
} }
setLowR(setting) { setLowR(setting) {
typeforce(typeforce.maybe(typeforce.Boolean), setting); typeforce(typeforce.maybe(typeforce.Boolean), setting);
@ -246,7 +248,9 @@ class TransactionBuilderV2 {
version, version,
}); });
// TODO: Add signature data to PSBT // 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'); return Buffer.from(psbt, 'hex').toString('base64');
} }
__addInputUnsafe(txHash, vout, options) { __addInputUnsafe(txHash, vout, options) {

12
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 __PREV_TX_SET: { [index: string]: boolean };
private __INPUTS: TxbInput[]; private __INPUTS: TxbInput[];
private __TX: Transaction; private __TX: Transaction;
private __PSBT: string;
private __USE_LOW_R: boolean; private __USE_LOW_R: boolean;
// WARNING: maximumFeeRate is __NOT__ to be relied on, // WARNING: maximumFeeRate is __NOT__ to be relied on,
@ -157,6 +160,7 @@ export class TransactionBuilderV2 {
this.__INPUTS = []; this.__INPUTS = [];
this.__TX = new Transaction(); this.__TX = new Transaction();
this.__TX.version = 2; this.__TX.version = 2;
this.__PSBT = '';
this.__USE_LOW_R = false; this.__USE_LOW_R = false;
} }
@ -364,7 +368,9 @@ export class TransactionBuilderV2 {
// TODO: Add signature data to PSBT // 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'); return Buffer.from(psbt, 'hex').toString('base64');
} }

1
types/transaction_builder_v2.d.ts

@ -10,6 +10,7 @@ export declare class TransactionBuilderV2 {
private __PREV_TX_SET; private __PREV_TX_SET;
private __INPUTS; private __INPUTS;
private __TX; private __TX;
private __PSBT;
private __USE_LOW_R; private __USE_LOW_R;
constructor(network?: Network, maximumFeeRate?: number); constructor(network?: Network, maximumFeeRate?: number);
setLowR(setting?: boolean): boolean; setLowR(setting?: boolean): boolean;

Loading…
Cancel
Save