opnet 1.8.3 → 1.8.5
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/CHANGELOG.md +20 -0
- package/browser/_version.d.ts +1 -1
- package/browser/contracts/CallResult.d.ts +3 -0
- package/browser/index.js +9939 -10210
- package/browser/noble-curves.js +3049 -2135
- package/browser/noble-hashes.js +1812 -2504
- package/browser/protobuf.js +2695 -2103
- package/browser/rolldown-runtime.js +35 -0
- package/browser/vendors.js +36998 -45617
- package/browser/worker_threads-browser.js +7 -9
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/contracts/CallResult.d.ts +3 -0
- package/build/contracts/CallResult.js +18 -11
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +17 -11
- package/src/_version.ts +1 -1
- package/src/contracts/CallResult.ts +59 -13
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
1
|
+
//#region src/shims/worker_threads-browser.js
|
|
2
|
+
var Worker = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
throw new Error("worker_threads is not available in browser. Use Web Workers instead.");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
10
8
|
export { Worker };
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.8.
|
|
1
|
+
export declare const version = "1.8.5";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.8.
|
|
1
|
+
export const version = '1.8.5';
|
|
@@ -107,6 +107,9 @@ export declare class CallResult<T extends ContractDecodedObjectResult = {}, U ex
|
|
|
107
107
|
setEvents(events: U): void;
|
|
108
108
|
setCalldata(calldata: Uint8Array): void;
|
|
109
109
|
toOfflineBuffer(refundAddress: string, amount: bigint): Promise<Uint8Array>;
|
|
110
|
+
private max;
|
|
111
|
+
private ensureUTXOsAvailable;
|
|
112
|
+
private computeRequiredAmount;
|
|
110
113
|
private acquire;
|
|
111
114
|
private bigintMax;
|
|
112
115
|
private getValuesFromAccessList;
|
|
@@ -427,6 +427,19 @@ export class CallResult {
|
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
|
+
max(a, b) {
|
|
431
|
+
return a > b ? a : b;
|
|
432
|
+
}
|
|
433
|
+
ensureUTXOsAvailable(utxos) {
|
|
434
|
+
if (!utxos || utxos.length === 0) {
|
|
435
|
+
throw new Error('Wallet optimization required. No UTXOs available. You may need to split your wallet UTXOs so at ' +
|
|
436
|
+
'least one non-extra-input UTXO is available for the funding transaction.');
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
computeRequiredAmount(gasFee, priority, amountAddition, totalOuts, extraInputValue, miningCost = 0n, maximumAllowedSatToSpend = 0n) {
|
|
440
|
+
const gross = this.max(gasFee + priority + amountAddition + totalOuts + miningCost, maximumAllowedSatToSpend);
|
|
441
|
+
return gross > extraInputValue ? gross - extraInputValue : 1n;
|
|
442
|
+
}
|
|
430
443
|
async acquire(interactionParams, amountAddition = 0n) {
|
|
431
444
|
if (!this.calldata) {
|
|
432
445
|
throw new Error('Calldata not set');
|
|
@@ -439,21 +452,14 @@ export class CallResult {
|
|
|
439
452
|
const addedOuts = interactionParams.extraOutputs ?? [];
|
|
440
453
|
const totalOuts = addedOuts.reduce((s, o) => s + BigInt(o.value), 0n);
|
|
441
454
|
const gasFee = this.bigintMax(this.estimatedSatGas, interactionParams.minGas ?? 0n);
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
amountAddition +
|
|
445
|
-
totalOuts +
|
|
446
|
-
interactionParams.maximumAllowedSatToSpend;
|
|
455
|
+
const extraInputValue = (interactionParams.extraInputs ?? []).reduce((s, u) => s + u.value, 0n);
|
|
456
|
+
const preWant = this.computeRequiredAmount(gasFee, priority, amountAddition, totalOuts, extraInputValue, 0n, interactionParams.maximumAllowedSatToSpend);
|
|
447
457
|
let utxos = interactionParams.utxos ?? (await this.#fetchUTXOs(preWant, interactionParams));
|
|
458
|
+
this.ensureUTXOsAvailable(utxos);
|
|
448
459
|
let refetched = false;
|
|
449
460
|
while (true) {
|
|
450
461
|
const miningCost = TransactionHelper.estimateMiningCost(utxos, addedOuts, this.calldata.length + 200, interactionParams.network, feeRate);
|
|
451
|
-
const want = gasFee
|
|
452
|
-
priority +
|
|
453
|
-
amountAddition +
|
|
454
|
-
totalOuts +
|
|
455
|
-
miningCost +
|
|
456
|
-
interactionParams.maximumAllowedSatToSpend;
|
|
462
|
+
const want = this.computeRequiredAmount(gasFee, priority, amountAddition, totalOuts, extraInputValue, miningCost, interactionParams.maximumAllowedSatToSpend);
|
|
457
463
|
const have = utxos.reduce((s, u) => s + u.value, 0n);
|
|
458
464
|
if (have >= want)
|
|
459
465
|
break;
|
|
@@ -462,6 +468,7 @@ export class CallResult {
|
|
|
462
468
|
}
|
|
463
469
|
utxos = await this.#fetchUTXOs(want, interactionParams);
|
|
464
470
|
refetched = true;
|
|
471
|
+
this.ensureUTXOsAvailable(utxos);
|
|
465
472
|
const haveAfter = utxos.reduce((s, u) => s + u.value, 0n);
|
|
466
473
|
if (haveAfter === have) {
|
|
467
474
|
throw new Error('Not enough sat to complete transaction');
|