@btc-vision/transaction 1.0.88 → 1.0.89
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.
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/transaction/TransactionFactory.d.ts +18 -5
- package/browser/transaction/builders/FundingTransaction.d.ts +1 -1
- package/browser/transaction/builders/TransactionBuilder.d.ts +2 -2
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/transaction/TransactionFactory.d.ts +18 -5
- package/build/transaction/TransactionFactory.js +22 -2
- package/build/transaction/builders/FundingTransaction.d.ts +1 -1
- package/build/transaction/builders/FundingTransaction.js +11 -3
- package/build/transaction/builders/TransactionBuilder.d.ts +2 -2
- package/build/transaction/builders/TransactionBuilder.js +12 -9
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/metadata/tokens.ts +135 -135
- package/src/transaction/TransactionFactory.ts +56 -12
- package/src/transaction/builders/FundingTransaction.ts +11 -5
- package/src/transaction/builders/TransactionBuilder.ts +26 -21
|
@@ -6,13 +6,13 @@ import { TransactionBuilder } from './TransactionBuilder.js';
|
|
|
6
6
|
export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
|
|
7
7
|
public readonly type: TransactionType.FUNDING = TransactionType.FUNDING;
|
|
8
8
|
|
|
9
|
-
protected
|
|
9
|
+
protected amount: bigint;
|
|
10
10
|
protected splitInputsInto: number;
|
|
11
11
|
|
|
12
12
|
constructor(parameters: IFundingTransactionParameters) {
|
|
13
13
|
super(parameters);
|
|
14
14
|
|
|
15
|
-
this.
|
|
15
|
+
this.amount = parameters.amount;
|
|
16
16
|
this.splitInputsInto = parameters.splitInputsInto ?? 1;
|
|
17
17
|
|
|
18
18
|
this.internalInit();
|
|
@@ -25,10 +25,16 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
|
|
|
25
25
|
|
|
26
26
|
this.addInputsFromUTXO();
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
let amountSpent: bigint = this.amount;
|
|
29
|
+
if (this.getTransactionOPNetFee() === TransactionBuilder.MINIMUM_DUST) {
|
|
30
|
+
if (amountSpent < TransactionBuilder.MINIMUM_DUST) {
|
|
31
|
+
amountSpent += TransactionBuilder.MINIMUM_DUST;
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
amountSpent += this.getTransactionOPNetFee();
|
|
35
|
+
}
|
|
30
36
|
|
|
31
|
-
if(this.splitInputsInto > 1) {
|
|
37
|
+
if (this.splitInputsInto > 1) {
|
|
32
38
|
await this.splitInputs(amountSpent);
|
|
33
39
|
} else {
|
|
34
40
|
this.addOutput({
|
|
@@ -119,6 +119,10 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
119
119
|
this.utxos = parameters.utxos;
|
|
120
120
|
this.to = parameters.to || undefined;
|
|
121
121
|
|
|
122
|
+
if (!this.utxos.length) {
|
|
123
|
+
throw new Error('No UTXOs specified');
|
|
124
|
+
}
|
|
125
|
+
|
|
122
126
|
this.from = TransactionBuilder.getFrom(
|
|
123
127
|
parameters.from,
|
|
124
128
|
this.signer as ECPairInterface,
|
|
@@ -372,6 +376,27 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
372
376
|
this.transaction = psbt;
|
|
373
377
|
}
|
|
374
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Returns the inputs of the transaction.
|
|
381
|
+
* @protected
|
|
382
|
+
* @returns {PsbtInputExtended[]}
|
|
383
|
+
*/
|
|
384
|
+
public getInputs(): PsbtInputExtended[] {
|
|
385
|
+
return this.inputs;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Returns the outputs of the transaction.
|
|
390
|
+
* @protected
|
|
391
|
+
* @returns {PsbtOutputExtended[]}
|
|
392
|
+
*/
|
|
393
|
+
public getOutputs(): PsbtOutputExtended[] {
|
|
394
|
+
const outputs: PsbtOutputExtended[] = [...this.outputs];
|
|
395
|
+
if (this.feeOutput) outputs.push(this.feeOutput);
|
|
396
|
+
|
|
397
|
+
return outputs;
|
|
398
|
+
}
|
|
399
|
+
|
|
375
400
|
/**
|
|
376
401
|
* @description Adds the refund output to the transaction
|
|
377
402
|
* @param {bigint} amountSpent - The amount spent
|
|
@@ -381,6 +406,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
381
406
|
protected async addRefundOutput(amountSpent: bigint): Promise<void> {
|
|
382
407
|
/** Add the refund output */
|
|
383
408
|
const sendBackAmount: bigint = this.totalInputAmount - amountSpent;
|
|
409
|
+
|
|
384
410
|
if (sendBackAmount >= TransactionBuilder.MINIMUM_DUST) {
|
|
385
411
|
if (AddressVerificator.isValidP2TRAddress(this.from, this.network)) {
|
|
386
412
|
await this.setFeeOutput({
|
|
@@ -548,27 +574,6 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
548
574
|
return this.tapData.output;
|
|
549
575
|
}
|
|
550
576
|
|
|
551
|
-
/**
|
|
552
|
-
* Returns the inputs of the transaction.
|
|
553
|
-
* @protected
|
|
554
|
-
* @returns {PsbtInputExtended[]}
|
|
555
|
-
*/
|
|
556
|
-
protected getInputs(): PsbtInputExtended[] {
|
|
557
|
-
return this.inputs;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* Returns the outputs of the transaction.
|
|
562
|
-
* @protected
|
|
563
|
-
* @returns {PsbtOutputExtended[]}
|
|
564
|
-
*/
|
|
565
|
-
protected getOutputs(): PsbtOutputExtended[] {
|
|
566
|
-
const outputs: PsbtOutputExtended[] = [...this.outputs];
|
|
567
|
-
if (this.feeOutput) outputs.push(this.feeOutput);
|
|
568
|
-
|
|
569
|
-
return outputs;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
577
|
/**
|
|
573
578
|
* Verifies that the utxos are valid.
|
|
574
579
|
* @protected
|