@btc-vision/transaction 1.0.44 → 1.0.45
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 +6 -2
- package/browser/transaction/builders/TransactionBuilder.d.ts +1 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/tests/Regtest.js +1 -1
- package/build/tests/btc/send.d.ts +1 -0
- package/build/tests/btc/send.js +36 -0
- package/build/tests/moto/airdropToken.js +3 -3
- package/build/tests/test.js +1 -1
- package/build/tests/wbtc/transferReg.js +2 -2
- package/build/tests/wbtc/unwrapReg.js +1 -1
- package/build/tests/wbtc/withdrawalRequestReg.js +1 -1
- package/build/tests/wbtc/wrapReg.js +2 -3
- package/build/transaction/TransactionFactory.d.ts +6 -2
- package/build/transaction/TransactionFactory.js +37 -32
- package/build/transaction/builders/FundingTransaction.js +1 -1
- package/build/transaction/builders/TransactionBuilder.d.ts +1 -0
- package/build/transaction/builders/TransactionBuilder.js +21 -5
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/build/transaction/shared/TweakedTransaction.js +0 -1
- package/package.json +2 -2
- package/src/_version.ts +1 -1
- package/src/transaction/TransactionFactory.ts +61 -51
- package/src/transaction/builders/FundingTransaction.ts +40 -40
- package/src/transaction/builders/InteractionTransaction.ts +1 -1
- package/src/transaction/builders/TransactionBuilder.ts +33 -5
- package/src/transaction/interfaces/ITransactionParameters.ts +1 -1
- package/src/transaction/shared/TweakedTransaction.ts +0 -1
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
|
-
import { IFundingTransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
3
|
-
import { Signer } from 'bitcoinjs-lib';
|
|
4
|
-
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
|
-
|
|
6
|
-
export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
|
|
7
|
-
public readonly type: TransactionType.FUNDING = TransactionType.FUNDING;
|
|
8
|
-
|
|
9
|
-
protected childTransactionRequiredFees: bigint;
|
|
10
|
-
|
|
11
|
-
constructor(parameters: IFundingTransactionParameters) {
|
|
12
|
-
super(parameters);
|
|
13
|
-
|
|
14
|
-
this.childTransactionRequiredFees = parameters.
|
|
15
|
-
|
|
16
|
-
this.internalInit();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
protected override async buildTransaction(): Promise<void> {
|
|
20
|
-
if (!this.to) {
|
|
21
|
-
throw new Error('Recipient address is required');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.addInputsFromUTXO();
|
|
25
|
-
|
|
26
|
-
const amountSpent: bigint =
|
|
27
|
-
this.getTransactionOPNetFee() + this.childTransactionRequiredFees;
|
|
28
|
-
|
|
29
|
-
this.addOutput({
|
|
30
|
-
value: Number(amountSpent),
|
|
31
|
-
address: this.to,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
await this.addRefundOutput(amountSpent);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
protected override getSignerKey(): Signer {
|
|
38
|
-
return this.signer;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
|
+
import { IFundingTransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
3
|
+
import { Signer } from 'bitcoinjs-lib';
|
|
4
|
+
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
|
+
|
|
6
|
+
export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
|
|
7
|
+
public readonly type: TransactionType.FUNDING = TransactionType.FUNDING;
|
|
8
|
+
|
|
9
|
+
protected childTransactionRequiredFees: bigint;
|
|
10
|
+
|
|
11
|
+
constructor(parameters: IFundingTransactionParameters) {
|
|
12
|
+
super(parameters);
|
|
13
|
+
|
|
14
|
+
this.childTransactionRequiredFees = parameters.amount;
|
|
15
|
+
|
|
16
|
+
this.internalInit();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
protected override async buildTransaction(): Promise<void> {
|
|
20
|
+
if (!this.to) {
|
|
21
|
+
throw new Error('Recipient address is required');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.addInputsFromUTXO();
|
|
25
|
+
|
|
26
|
+
const amountSpent: bigint =
|
|
27
|
+
this.getTransactionOPNetFee() + this.childTransactionRequiredFees;
|
|
28
|
+
|
|
29
|
+
this.addOutput({
|
|
30
|
+
value: Number(amountSpent),
|
|
31
|
+
address: this.to,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
await this.addRefundOutput(amountSpent);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected override getSignerKey(): Signer {
|
|
38
|
+
return this.signer;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -182,8 +182,8 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
public async getFundingTransactionParameters(): Promise<IFundingTransactionParameters> {
|
|
185
|
-
if (!this.
|
|
186
|
-
this.
|
|
185
|
+
if (!this.estimatedFees) {
|
|
186
|
+
this.estimatedFees = await this.estimateTransactionFees();
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
return {
|
|
@@ -194,7 +194,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
194
194
|
feeRate: this.feeRate,
|
|
195
195
|
priorityFee: this.priorityFee,
|
|
196
196
|
from: this.from,
|
|
197
|
-
|
|
197
|
+
amount: this.estimatedFees,
|
|
198
198
|
};
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -245,6 +245,34 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
245
245
|
throw new Error('Could not sign transaction');
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
/**
|
|
249
|
+
* @description Generates the transaction minimal signatures
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
public async generateTransactionMinimalSignatures(): Promise<void> {
|
|
253
|
+
if (this.to && !EcKeyPair.verifyContractAddress(this.to, this.network)) {
|
|
254
|
+
throw new Error(
|
|
255
|
+
'Invalid contract address. The contract address must be a taproot address.',
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
await this.buildTransaction();
|
|
260
|
+
|
|
261
|
+
if (this.transaction.data.inputs.length === 0) {
|
|
262
|
+
const inputs: PsbtInputExtended[] = this.getInputs();
|
|
263
|
+
const outputs: PsbtOutputExtended[] = this.getOutputs();
|
|
264
|
+
|
|
265
|
+
this.transaction.setMaximumFeeRate(this._maximumFeeRate);
|
|
266
|
+
this.transaction.addInputs(inputs);
|
|
267
|
+
|
|
268
|
+
for (let i = 0; i < this.updateInputs.length; i++) {
|
|
269
|
+
this.transaction.updateInput(i, this.updateInputs[i]);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
this.transaction.addOutputs(outputs);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
248
276
|
/**
|
|
249
277
|
* @description Signs the transaction
|
|
250
278
|
* @public
|
|
@@ -317,9 +345,9 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
317
345
|
|
|
318
346
|
const builtTx = await this.internalBuildTransaction(fakeTx);
|
|
319
347
|
if (builtTx) {
|
|
320
|
-
const tx = fakeTx.extractTransaction(false);
|
|
348
|
+
const tx = fakeTx.extractTransaction(false, true);
|
|
321
349
|
const size = tx.virtualSize();
|
|
322
|
-
const fee: number = this.feeRate * size
|
|
350
|
+
const fee: number = this.feeRate * size;
|
|
323
351
|
|
|
324
352
|
this.estimatedFees = BigInt(Math.ceil(fee) + 1);
|
|
325
353
|
|
|
@@ -17,7 +17,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
20
|
-
|
|
20
|
+
amount: bigint;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface SharedInteractionParameters extends ITransactionParameters {
|