@rsksmart/powpeg-sdk 1.2.0-beta.3 → 1.2.0-beta.4
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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -2
- package/dist/index.mjs +12 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -480,7 +480,7 @@ declare class APIError extends Error {
|
|
|
480
480
|
declare class FederationAddressError extends Error {
|
|
481
481
|
constructor(message?: string);
|
|
482
482
|
}
|
|
483
|
-
/** Thrown when one or more Bitcoin
|
|
483
|
+
/** Thrown when one or more addresses are invalid: a Bitcoin address that doesn't belong to the SDK's configured network, or a malformed Rootstock recipient address. */
|
|
484
484
|
declare class InvalidAddressError extends Error {
|
|
485
485
|
readonly invalidAddresses: string[];
|
|
486
486
|
constructor(invalidAddresses: string[], message?: string);
|
package/dist/index.d.ts
CHANGED
|
@@ -480,7 +480,7 @@ declare class APIError extends Error {
|
|
|
480
480
|
declare class FederationAddressError extends Error {
|
|
481
481
|
constructor(message?: string);
|
|
482
482
|
}
|
|
483
|
-
/** Thrown when one or more Bitcoin
|
|
483
|
+
/** Thrown when one or more addresses are invalid: a Bitcoin address that doesn't belong to the SDK's configured network, or a malformed Rootstock recipient address. */
|
|
484
484
|
declare class InvalidAddressError extends Error {
|
|
485
485
|
readonly invalidAddresses: string[];
|
|
486
486
|
constructor(invalidAddresses: string[], message?: string);
|
package/dist/index.js
CHANGED
|
@@ -579,7 +579,11 @@ var PowPegSDK = class {
|
|
|
579
579
|
const amount = value ?? BigInt(psbt.txOutputs[1].value);
|
|
580
580
|
const feeRate = await this.bitcoinDataSource.getFeeRate(feeLevel);
|
|
581
581
|
const { inputs, change, totalFee } = await this.calculateFeeAndSelectedInputs(amount, funding.utxos, feeRate);
|
|
582
|
-
|
|
582
|
+
const hexTransactions = await Promise.all(inputs.map((input) => this.bitcoinDataSource.getTxHex(input.txid)));
|
|
583
|
+
const initialInputCount = psbt.txInputs.length;
|
|
584
|
+
const initialOutputCount = psbt.txOutputs.length;
|
|
585
|
+
const addChange = change > Math.min(this.burnDustValue, this.burnDustMaxValue);
|
|
586
|
+
if (addChange) {
|
|
583
587
|
psbt.addOutput({
|
|
584
588
|
// Fall back to the first funding input's address when every derived
|
|
585
589
|
// change address has already been used.
|
|
@@ -587,7 +591,6 @@ var PowPegSDK = class {
|
|
|
587
591
|
value: change
|
|
588
592
|
});
|
|
589
593
|
}
|
|
590
|
-
const hexTransactions = await Promise.all(inputs.map((input) => this.bitcoinDataSource.getTxHex(input.txid)));
|
|
591
594
|
inputs.forEach((input, index) => {
|
|
592
595
|
const transaction = import_bitcoinjs_lib4.Transaction.fromHex(hexTransactions[index]);
|
|
593
596
|
psbt.addInput({
|
|
@@ -599,6 +602,13 @@ var PowPegSDK = class {
|
|
|
599
602
|
}
|
|
600
603
|
});
|
|
601
604
|
});
|
|
605
|
+
const expectedInputCount = initialInputCount + inputs.length;
|
|
606
|
+
const expectedOutputCount = initialOutputCount + (addChange ? 1 : 0);
|
|
607
|
+
(0, import_bridges_core_sdk4.assertTruthy)(
|
|
608
|
+
psbt.txInputs.length === expectedInputCount && psbt.txOutputs.length === expectedOutputCount,
|
|
609
|
+
`Funded PSBT structure mismatch: expected ${expectedInputCount} inputs and ${expectedOutputCount} outputs, got ${psbt.txInputs.length} and ${psbt.txOutputs.length}.`
|
|
610
|
+
);
|
|
611
|
+
this.funding.delete(psbt);
|
|
602
612
|
return { psbt, inputs, transactions: hexTransactions, fee: totalFee };
|
|
603
613
|
}
|
|
604
614
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -532,7 +532,11 @@ var PowPegSDK = class {
|
|
|
532
532
|
const amount = value ?? BigInt(psbt.txOutputs[1].value);
|
|
533
533
|
const feeRate = await this.bitcoinDataSource.getFeeRate(feeLevel);
|
|
534
534
|
const { inputs, change, totalFee } = await this.calculateFeeAndSelectedInputs(amount, funding.utxos, feeRate);
|
|
535
|
-
|
|
535
|
+
const hexTransactions = await Promise.all(inputs.map((input) => this.bitcoinDataSource.getTxHex(input.txid)));
|
|
536
|
+
const initialInputCount = psbt.txInputs.length;
|
|
537
|
+
const initialOutputCount = psbt.txOutputs.length;
|
|
538
|
+
const addChange = change > Math.min(this.burnDustValue, this.burnDustMaxValue);
|
|
539
|
+
if (addChange) {
|
|
536
540
|
psbt.addOutput({
|
|
537
541
|
// Fall back to the first funding input's address when every derived
|
|
538
542
|
// change address has already been used.
|
|
@@ -540,7 +544,6 @@ var PowPegSDK = class {
|
|
|
540
544
|
value: change
|
|
541
545
|
});
|
|
542
546
|
}
|
|
543
|
-
const hexTransactions = await Promise.all(inputs.map((input) => this.bitcoinDataSource.getTxHex(input.txid)));
|
|
544
547
|
inputs.forEach((input, index) => {
|
|
545
548
|
const transaction = Transaction.fromHex(hexTransactions[index]);
|
|
546
549
|
psbt.addInput({
|
|
@@ -552,6 +555,13 @@ var PowPegSDK = class {
|
|
|
552
555
|
}
|
|
553
556
|
});
|
|
554
557
|
});
|
|
558
|
+
const expectedInputCount = initialInputCount + inputs.length;
|
|
559
|
+
const expectedOutputCount = initialOutputCount + (addChange ? 1 : 0);
|
|
560
|
+
assertTruthy(
|
|
561
|
+
psbt.txInputs.length === expectedInputCount && psbt.txOutputs.length === expectedOutputCount,
|
|
562
|
+
`Funded PSBT structure mismatch: expected ${expectedInputCount} inputs and ${expectedOutputCount} outputs, got ${psbt.txInputs.length} and ${psbt.txOutputs.length}.`
|
|
563
|
+
);
|
|
564
|
+
this.funding.delete(psbt);
|
|
555
565
|
return { psbt, inputs, transactions: hexTransactions, fee: totalFee };
|
|
556
566
|
}
|
|
557
567
|
/**
|
package/package.json
CHANGED