@btc-vision/transaction 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
28
28
  protected priorityFee: bigint;
29
29
  protected gasSatFee: bigint;
30
30
  protected utxos: UTXO[];
31
+ protected optionalInputs: UTXO[];
31
32
  protected to: string | undefined;
32
33
  protected from: string;
33
34
  protected _maximumFeeRate: number;
@@ -8,6 +8,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
8
8
  utxos: UTXO[];
9
9
  nonWitnessUtxo?: Buffer;
10
10
  estimatedFees?: bigint;
11
+ optionalInputs?: UTXO[];
11
12
  optionalOutputs?: PsbtOutputExtended[];
12
13
  chainId?: ChainId;
13
14
  readonly feeRate: number;
@@ -1 +1 @@
1
- export declare const version = "1.3.2";
1
+ export declare const version = "1.3.3";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.3.2';
1
+ export const version = '1.3.3';
@@ -24,7 +24,11 @@ export class TransactionFactory {
24
24
  (await preTransaction.estimateTransactionFees()) +
25
25
  this.getPriorityFee(interactionParameters) +
26
26
  preTransaction.getOptionalOutputValue();
27
- const feeEstimationFundingTransaction = await this.createFundTransaction({ ...parameters });
27
+ const feeEstimationFundingTransaction = await this.createFundTransaction({
28
+ ...parameters,
29
+ optionalOutputs: [],
30
+ optionalInputs: [],
31
+ });
28
32
  if (!feeEstimationFundingTransaction) {
29
33
  throw new Error('Could not sign funding transaction.');
30
34
  }
@@ -80,6 +84,7 @@ export class TransactionFactory {
80
84
  const feeEstimationFundingTransaction = await this.createFundTransaction({
81
85
  ...parameters,
82
86
  optionalOutputs: [],
87
+ optionalInputs: [],
83
88
  });
84
89
  if (!feeEstimationFundingTransaction) {
85
90
  throw new Error('Could not sign funding transaction.');
@@ -88,6 +93,7 @@ export class TransactionFactory {
88
93
  const signedTransaction = await this.createFundTransaction({
89
94
  ...parameters,
90
95
  optionalOutputs: [],
96
+ optionalInputs: [],
91
97
  });
92
98
  if (!signedTransaction) {
93
99
  throw new Error('Could not sign funding transaction.');
@@ -119,7 +125,11 @@ export class TransactionFactory {
119
125
  (await preTransaction.estimateTransactionFees()) +
120
126
  this.getPriorityFee(deploymentParameters) +
121
127
  preTransaction.getOptionalOutputValue();
122
- const fundingTransaction = new FundingTransaction(parameters);
128
+ const fundingTransaction = new FundingTransaction({
129
+ ...parameters,
130
+ optionalInputs: [],
131
+ optionalOutputs: [],
132
+ });
123
133
  const signedTransaction = await fundingTransaction.signTransaction();
124
134
  if (!signedTransaction) {
125
135
  throw new Error('Could not sign funding transaction.');
@@ -141,6 +151,7 @@ export class TransactionFactory {
141
151
  preimage: preTransaction.getPreimage(),
142
152
  nonWitnessUtxo: signedTransaction.toBuffer(),
143
153
  optionalOutputs: [],
154
+ optionalInputs: [],
144
155
  };
145
156
  const finalTransaction = new DeploymentTransaction(newParams);
146
157
  const outTx = await finalTransaction.signTransaction();
@@ -28,6 +28,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
28
28
  protected priorityFee: bigint;
29
29
  protected gasSatFee: bigint;
30
30
  protected utxos: UTXO[];
31
+ protected optionalInputs: UTXO[];
31
32
  protected to: string | undefined;
32
33
  protected from: string;
33
34
  protected _maximumFeeRate: number;
@@ -26,6 +26,7 @@ export class TransactionBuilder extends TweakedTransaction {
26
26
  this.priorityFee = parameters.priorityFee ?? 0n;
27
27
  this.gasSatFee = parameters.gasSatFee ?? 0n;
28
28
  this.utxos = parameters.utxos;
29
+ this.optionalInputs = parameters.optionalInputs || [];
29
30
  this.to = parameters.to || undefined;
30
31
  this.isPubKeyDestination = this.to
31
32
  ? AddressVerificator.isValidPublicKey(this.to, this.network)
@@ -81,6 +82,7 @@ export class TransactionBuilder extends TweakedTransaction {
81
82
  from: this.from,
82
83
  amount: this.estimatedFees,
83
84
  optionalOutputs: this.optionalOutputs,
85
+ optionalInputs: this.optionalInputs,
84
86
  };
85
87
  }
86
88
  setDestinationAddress(address) {
@@ -254,6 +256,9 @@ export class TransactionBuilder extends TweakedTransaction {
254
256
  for (const utxo of this.utxos) {
255
257
  total += utxo.value;
256
258
  }
259
+ for (const utxo of this.optionalInputs) {
260
+ total += utxo.value;
261
+ }
257
262
  return total;
258
263
  }
259
264
  calculateTotalVOutAmount() {
@@ -261,6 +266,9 @@ export class TransactionBuilder extends TweakedTransaction {
261
266
  for (const utxo of this.utxos) {
262
267
  total += utxo.value;
263
268
  }
269
+ for (const utxo of this.optionalInputs) {
270
+ total += utxo.value;
271
+ }
264
272
  return total;
265
273
  }
266
274
  addOptionalOutputsAndGetAmount() {
@@ -284,6 +292,13 @@ export class TransactionBuilder extends TweakedTransaction {
284
292
  this.addInput(input);
285
293
  }
286
294
  }
295
+ if (this.optionalInputs) {
296
+ for (let i = 0; i < this.optionalInputs.length; i++) {
297
+ const utxo = this.optionalInputs[i];
298
+ const input = this.generatePsbtInputExtended(utxo, i);
299
+ this.addInput(input);
300
+ }
301
+ }
287
302
  }
288
303
  internalInit() {
289
304
  this.verifyUTXOValidity();
@@ -313,6 +328,11 @@ export class TransactionBuilder extends TweakedTransaction {
313
328
  throw new Error('Address is required');
314
329
  }
315
330
  }
331
+ for (const utxo of this.optionalInputs) {
332
+ if (!utxo.scriptPubKey) {
333
+ throw new Error('Address is required');
334
+ }
335
+ }
316
336
  }
317
337
  async setFeeOutput(output) {
318
338
  const initialValue = output.value;
@@ -8,6 +8,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
8
8
  utxos: UTXO[];
9
9
  nonWitnessUtxo?: Buffer;
10
10
  estimatedFees?: bigint;
11
+ optionalInputs?: UTXO[];
11
12
  optionalOutputs?: PsbtOutputExtended[];
12
13
  chainId?: ChainId;
13
14
  readonly feeRate: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.3.2",
4
+ "version": "1.3.3",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.3.2';
1
+ export const version = '1.3.3';
@@ -103,7 +103,12 @@ export class TransactionFactory {
103
103
  this.getPriorityFee(interactionParameters) +
104
104
  preTransaction.getOptionalOutputValue();
105
105
 
106
- const feeEstimationFundingTransaction = await this.createFundTransaction({ ...parameters });
106
+ const feeEstimationFundingTransaction = await this.createFundTransaction({
107
+ ...parameters,
108
+ optionalOutputs: [],
109
+ optionalInputs: [],
110
+ });
111
+
107
112
  if (!feeEstimationFundingTransaction) {
108
113
  throw new Error('Could not sign funding transaction.');
109
114
  }
@@ -189,7 +194,9 @@ export class TransactionFactory {
189
194
  const feeEstimationFundingTransaction = await this.createFundTransaction({
190
195
  ...parameters,
191
196
  optionalOutputs: [],
197
+ optionalInputs: [],
192
198
  });
199
+
193
200
  if (!feeEstimationFundingTransaction) {
194
201
  throw new Error('Could not sign funding transaction.');
195
202
  }
@@ -199,7 +206,9 @@ export class TransactionFactory {
199
206
  const signedTransaction = await this.createFundTransaction({
200
207
  ...parameters,
201
208
  optionalOutputs: [],
209
+ optionalInputs: [],
202
210
  });
211
+
203
212
  if (!signedTransaction) {
204
213
  throw new Error('Could not sign funding transaction.');
205
214
  }
@@ -259,7 +268,12 @@ export class TransactionFactory {
259
268
  this.getPriorityFee(deploymentParameters) +
260
269
  preTransaction.getOptionalOutputValue();
261
270
 
262
- const fundingTransaction: FundingTransaction = new FundingTransaction(parameters);
271
+ const fundingTransaction: FundingTransaction = new FundingTransaction({
272
+ ...parameters,
273
+ optionalInputs: [],
274
+ optionalOutputs: [],
275
+ });
276
+
263
277
  const signedTransaction: Transaction = await fundingTransaction.signTransaction();
264
278
  if (!signedTransaction) {
265
279
  throw new Error('Could not sign funding transaction.');
@@ -283,6 +297,7 @@ export class TransactionFactory {
283
297
  preimage: preTransaction.getPreimage(),
284
298
  nonWitnessUtxo: signedTransaction.toBuffer(),
285
299
  optionalOutputs: [],
300
+ optionalInputs: [],
286
301
  };
287
302
 
288
303
  const finalTransaction: DeploymentTransaction = new DeploymentTransaction(newParams);
@@ -118,6 +118,12 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
118
118
  */
119
119
  protected utxos: UTXO[];
120
120
 
121
+ /**
122
+ * @description The inputs of the transaction
123
+ * @protected
124
+ */
125
+ protected optionalInputs: UTXO[];
126
+
121
127
  /**
122
128
  * @description The address where the transaction is sent to
123
129
  * @protected
@@ -154,6 +160,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
154
160
  this.priorityFee = parameters.priorityFee ?? 0n;
155
161
  this.gasSatFee = parameters.gasSatFee ?? 0n;
156
162
  this.utxos = parameters.utxos;
163
+ this.optionalInputs = parameters.optionalInputs || [];
157
164
  this.to = parameters.to || undefined;
158
165
 
159
166
  this.isPubKeyDestination = this.to
@@ -236,6 +243,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
236
243
  from: this.from,
237
244
  amount: this.estimatedFees,
238
245
  optionalOutputs: this.optionalOutputs,
246
+ optionalInputs: this.optionalInputs,
239
247
  };
240
248
  }
241
249
 
@@ -551,6 +559,11 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
551
559
  for (const utxo of this.utxos) {
552
560
  total += utxo.value;
553
561
  }
562
+
563
+ for (const utxo of this.optionalInputs) {
564
+ total += utxo.value;
565
+ }
566
+
554
567
  return total;
555
568
  }
556
569
 
@@ -565,6 +578,10 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
565
578
  total += utxo.value;
566
579
  }
567
580
 
581
+ for (const utxo of this.optionalInputs) {
582
+ total += utxo.value;
583
+ }
584
+
568
585
  return total;
569
586
  }
570
587
 
@@ -607,6 +624,15 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
607
624
  this.addInput(input);
608
625
  }
609
626
  }
627
+
628
+ if (this.optionalInputs) {
629
+ for (let i = 0; i < this.optionalInputs.length; i++) {
630
+ const utxo = this.optionalInputs[i];
631
+ const input = this.generatePsbtInputExtended(utxo, i);
632
+
633
+ this.addInput(input);
634
+ }
635
+ }
610
636
  }
611
637
 
612
638
  /**
@@ -676,6 +702,12 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
676
702
  throw new Error('Address is required');
677
703
  }
678
704
  }
705
+
706
+ for (const utxo of this.optionalInputs) {
707
+ if (!utxo.scriptPubKey) {
708
+ throw new Error('Address is required');
709
+ }
710
+ }
679
711
  }
680
712
 
681
713
  /**
@@ -11,7 +11,8 @@ export interface ITransactionParameters extends ITweakedTransactionData {
11
11
 
12
12
  nonWitnessUtxo?: Buffer;
13
13
  estimatedFees?: bigint;
14
-
14
+
15
+ optionalInputs?: UTXO[];
15
16
  optionalOutputs?: PsbtOutputExtended[];
16
17
 
17
18
  chainId?: ChainId;