@btc-vision/transaction 1.0.86 → 1.0.88

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.
@@ -7,11 +7,13 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
7
7
  public readonly type: TransactionType.FUNDING = TransactionType.FUNDING;
8
8
 
9
9
  protected childTransactionRequiredFees: bigint;
10
+ protected splitInputsInto: number;
10
11
 
11
12
  constructor(parameters: IFundingTransactionParameters) {
12
13
  super(parameters);
13
14
 
14
15
  this.childTransactionRequiredFees = parameters.amount;
16
+ this.splitInputsInto = parameters.splitInputsInto ?? 1;
15
17
 
16
18
  this.internalInit();
17
19
  }
@@ -26,14 +28,33 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
26
28
  const amountSpent: bigint =
27
29
  this.getTransactionOPNetFee() + this.childTransactionRequiredFees;
28
30
 
29
- this.addOutput({
30
- value: Number(amountSpent),
31
- address: this.to,
32
- });
31
+ if(this.splitInputsInto > 1) {
32
+ await this.splitInputs(amountSpent);
33
+ } else {
34
+ this.addOutput({
35
+ value: Number(amountSpent),
36
+ address: this.to,
37
+ });
38
+ }
33
39
 
34
40
  await this.addRefundOutput(amountSpent);
35
41
  }
36
42
 
43
+ protected async splitInputs(amountSpent: bigint): Promise<void> {
44
+ if (!this.to) {
45
+ throw new Error('Recipient address is required');
46
+ }
47
+
48
+ const splitAmount = amountSpent / BigInt(this.splitInputsInto);
49
+
50
+ for (let i = 0; i < this.splitInputsInto; i++) {
51
+ this.addOutput({
52
+ value: Number(splitAmount),
53
+ address: this.to,
54
+ });
55
+ }
56
+ }
57
+
37
58
  protected override getSignerKey(): Signer {
38
59
  return this.signer;
39
60
  }
@@ -115,7 +115,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
115
115
  this.signer = parameters.signer;
116
116
  this.network = parameters.network;
117
117
  this.feeRate = parameters.feeRate;
118
- this.priorityFee = parameters.priorityFee;
118
+ this.priorityFee = parameters.priorityFee ?? 0n;
119
119
  this.utxos = parameters.utxos;
120
120
  this.to = parameters.to || undefined;
121
121
 
@@ -192,7 +192,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
192
192
  signer: this.signer,
193
193
  network: this.network,
194
194
  feeRate: this.feeRate,
195
- priorityFee: this.priorityFee,
195
+ priorityFee: this.priorityFee ?? 0n,
196
196
  from: this.from,
197
197
  amount: this.estimatedFees,
198
198
  };
@@ -1,59 +1,61 @@
1
- import { UTXO } from '../../utxo/interfaces/IUTXO.js';
2
- import { Address } from '@btc-vision/bsi-binary';
3
- import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
4
- import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
5
- import { VaultUTXOs } from '../processor/PsbtTransaction.js';
6
- import { ChainId } from '../../network/ChainId.js';
7
-
8
- export interface ITransactionParameters extends ITweakedTransactionData {
9
- readonly from?: Address;
10
- readonly to?: Address | undefined;
11
- utxos: UTXO[];
12
-
13
- nonWitnessUtxo?: Buffer | undefined;
14
- estimatedFees?: bigint;
15
-
16
- chainId?: ChainId;
17
-
18
- readonly feeRate: number;
19
- readonly priorityFee: bigint;
20
- }
21
-
22
- export interface IFundingTransactionParameters extends ITransactionParameters {
23
- amount: bigint;
24
- }
25
-
26
- export interface SharedInteractionParameters extends ITransactionParameters {
27
- calldata?: Buffer | undefined;
28
- disableAutoRefund?: boolean;
29
-
30
- readonly randomBytes?: Buffer;
31
- }
32
-
33
- export interface IInteractionParameters extends SharedInteractionParameters {
34
- readonly calldata: Buffer;
35
-
36
- readonly to: Address;
37
- }
38
-
39
- export interface IWrapParameters extends SharedInteractionParameters {
40
- readonly to?: Address;
41
-
42
- readonly from: Address;
43
- readonly amount: bigint;
44
- readonly receiver?: Address;
45
-
46
- readonly generationParameters: WrappedGeneration;
47
- }
48
-
49
- export interface IUnwrapParameters extends SharedInteractionParameters {
50
- readonly unwrapUTXOs: VaultUTXOs[];
51
- readonly amount: bigint;
52
- }
53
-
54
- export interface IDeploymentParameters extends ITransactionParameters {
55
- readonly bytecode: Buffer;
56
-
57
- readonly to?: undefined;
58
- readonly randomBytes?: Buffer;
59
- }
1
+ import { UTXO } from '../../utxo/interfaces/IUTXO.js';
2
+ import { Address } from '@btc-vision/bsi-binary';
3
+ import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
4
+ import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
5
+ import { VaultUTXOs } from '../processor/PsbtTransaction.js';
6
+ import { ChainId } from '../../network/ChainId.js';
7
+
8
+ export interface ITransactionParameters extends ITweakedTransactionData {
9
+ readonly from?: Address;
10
+ readonly to?: Address | undefined;
11
+ utxos: UTXO[];
12
+
13
+ nonWitnessUtxo?: Buffer | undefined;
14
+ estimatedFees?: bigint;
15
+
16
+ chainId?: ChainId;
17
+
18
+ readonly feeRate: number;
19
+ readonly priorityFee?: bigint;
20
+ }
21
+
22
+ export interface IFundingTransactionParameters extends ITransactionParameters {
23
+ amount: bigint;
24
+
25
+ splitInputsInto?: number;
26
+ }
27
+
28
+ export interface SharedInteractionParameters extends ITransactionParameters {
29
+ calldata?: Buffer | undefined;
30
+ disableAutoRefund?: boolean;
31
+
32
+ readonly randomBytes?: Buffer;
33
+ }
34
+
35
+ export interface IInteractionParameters extends SharedInteractionParameters {
36
+ readonly calldata: Buffer;
37
+
38
+ readonly to: Address;
39
+ }
40
+
41
+ export interface IWrapParameters extends SharedInteractionParameters {
42
+ readonly to?: Address;
43
+
44
+ readonly from: Address;
45
+ readonly amount: bigint;
46
+ readonly receiver?: Address;
47
+
48
+ readonly generationParameters: WrappedGeneration;
49
+ }
50
+
51
+ export interface IUnwrapParameters extends SharedInteractionParameters {
52
+ readonly unwrapUTXOs: VaultUTXOs[];
53
+ readonly amount: bigint;
54
+ }
55
+
56
+ export interface IDeploymentParameters extends ITransactionParameters {
57
+ readonly bytecode: Buffer;
58
+
59
+ readonly to?: undefined;
60
+ readonly randomBytes?: Buffer;
61
+ }