opnet 1.8.4 → 1.8.6

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [v1.8.5] - 2026-03-13
4
+
5
+ ### Features
6
+
7
+ - Fix/bug with building tx ([#146](https://github.com/btc-vision/opnet/pull/146)) by @BlobMaster41
8
+
9
+ ### Bug Fixes
10
+
11
+ - Fix/bug with building tx ([#146](https://github.com/btc-vision/opnet/pull/146)) by @BlobMaster41
12
+
13
+
14
+
15
+
3
16
  ## [v1.8.3] - 2026-03-09
4
17
 
5
18
  ### Features
@@ -1 +1 @@
1
- export declare const version = "1.8.4";
1
+ export declare const version = "1.8.5";
@@ -1,7 +1,6 @@
1
1
  import { Address } from '../../node_modules/@btc-vision/transaction/build/index.js';
2
2
  import { BlockWitnesses, IBlockWitness, IBlockWitnessAPI, RawBlockWitnessAPI } from './interfaces/IBlockWitness.js';
3
3
  export declare class BlockWitnessAPI implements IBlockWitnessAPI {
4
- readonly trusted: boolean;
5
4
  readonly signature: Uint8Array;
6
5
  readonly timestamp: number;
7
6
  readonly proofs: readonly Uint8Array[];
@@ -1,6 +1,5 @@
1
1
  import { Address } from '../../../node_modules/@btc-vision/transaction/build/index.js';
2
2
  export interface IBlockWitnessAPI {
3
- readonly trusted: boolean;
4
3
  readonly signature: Uint8Array;
5
4
  readonly timestamp: number;
6
5
  readonly proofs: readonly Uint8Array[];
@@ -8,7 +7,6 @@ export interface IBlockWitnessAPI {
8
7
  readonly publicKey?: Address;
9
8
  }
10
9
  export interface RawBlockWitnessAPI {
11
- readonly trusted: boolean;
12
10
  readonly signature: string;
13
11
  readonly timestamp: number;
14
12
  readonly proofs: readonly string[];
@@ -108,6 +108,8 @@ export declare class CallResult<T extends ContractDecodedObjectResult = {}, U ex
108
108
  setCalldata(calldata: Uint8Array): void;
109
109
  toOfflineBuffer(refundAddress: string, amount: bigint): Promise<Uint8Array>;
110
110
  private max;
111
+ private ensureUTXOsAvailable;
112
+ private computeRequiredAmount;
111
113
  private acquire;
112
114
  private bigintMax;
113
115
  private getValuesFromAccessList;
package/browser/index.js CHANGED
@@ -2,7 +2,7 @@ import { a as __toESM, r as __exportAll } from "./rolldown-runtime.js";
2
2
  import { A as bitcoin, C as AddressVerificator, D as fromHex, E as toBase64, M as regtest, N as testnet, O as toHex, S as AddressTypes, T as fromBase64, _ as BinaryWriter, a as ABICoder, b as AddressMap, c as isAbiTuple, d as process$1, f as P2MR_MS, g as Logger, h as TransactionFactory, i as NetEvent, j as opnetTestnet, k as fromBech32, l as ABIDataTypes, m as ChallengeSolution, n as Long, o as abiTypeToSelectorString, p as P2TR_MS, r as pLimit, s as isAbiStruct, t as BigNumber, u as init_dist, v as BinaryReader, w as decompile, x as Address, y as BufferHelper } from "./vendors.js";
3
3
  import { t as require_protobuf_min } from "./protobuf.js";
4
4
  //#region src/_version.ts
5
- var version = "1.8.4";
5
+ var version = "1.8.5";
6
6
  //#endregion
7
7
  //#region src/interfaces/opnet/OPNetTransactionTypes.ts
8
8
  var OPNetTransactionTypes = /* @__PURE__ */ function(OPNetTransactionTypes) {
@@ -548,14 +548,12 @@ function stringBase64ToBuffer(str) {
548
548
  //#endregion
549
549
  //#region src/block/BlockWitness.ts
550
550
  var BlockWitnessAPI = class {
551
- trusted;
552
551
  signature;
553
552
  timestamp;
554
553
  proofs;
555
554
  identity;
556
555
  publicKey;
557
556
  constructor(data) {
558
- this.trusted = data.trusted;
559
557
  this.signature = stringBase64ToBuffer(data.signature);
560
558
  this.timestamp = data.timestamp;
561
559
  this.proofs = Object.freeze(data.proofs.map((proof) => stringBase64ToBuffer(proof)));
@@ -1355,6 +1353,13 @@ var CallResult = class CallResult {
1355
1353
  max(a, b) {
1356
1354
  return a > b ? a : b;
1357
1355
  }
1356
+ ensureUTXOsAvailable(utxos) {
1357
+ if (!utxos || utxos.length === 0) throw new Error("Wallet optimization required. No UTXOs available. You may need to split your wallet UTXOs so at least one non-extra-input UTXO is available for the funding transaction.");
1358
+ }
1359
+ computeRequiredAmount(gasFee, priority, amountAddition, totalOuts, extraInputValue, miningCost = 0n, maximumAllowedSatToSpend = 0n) {
1360
+ const gross = this.max(gasFee + priority + amountAddition + totalOuts + miningCost, maximumAllowedSatToSpend);
1361
+ return gross > extraInputValue ? gross - extraInputValue : 1n;
1362
+ }
1358
1363
  /**
1359
1364
  * Acquire UTXOs for the transaction.
1360
1365
  * @param {TransactionParameters} interactionParams - The transaction parameters.
@@ -1369,17 +1374,20 @@ var CallResult = class CallResult {
1369
1374
  const addedOuts = interactionParams.extraOutputs ?? [];
1370
1375
  const totalOuts = addedOuts.reduce((s, o) => s + BigInt(o.value), 0n);
1371
1376
  const gasFee = this.bigintMax(this.estimatedSatGas, interactionParams.minGas ?? 0n);
1372
- const preWant = this.max(gasFee + priority + amountAddition + totalOuts, interactionParams.maximumAllowedSatToSpend);
1377
+ const extraInputValue = (interactionParams.extraInputs ?? []).reduce((s, u) => s + u.value, 0n);
1378
+ const preWant = this.computeRequiredAmount(gasFee, priority, amountAddition, totalOuts, extraInputValue, 0n, interactionParams.maximumAllowedSatToSpend);
1373
1379
  let utxos = interactionParams.utxos ?? await this.#fetchUTXOs(preWant, interactionParams);
1380
+ this.ensureUTXOsAvailable(utxos);
1374
1381
  let refetched = false;
1375
1382
  while (true) {
1376
1383
  const miningCost = TransactionHelper.estimateMiningCost(utxos, addedOuts, this.calldata.length + 200, interactionParams.network, feeRate);
1377
- const want = this.max(gasFee + priority + amountAddition + totalOuts + miningCost, interactionParams.maximumAllowedSatToSpend);
1384
+ const want = this.computeRequiredAmount(gasFee, priority, amountAddition, totalOuts, extraInputValue, miningCost, interactionParams.maximumAllowedSatToSpend);
1378
1385
  const have = utxos.reduce((s, u) => s + u.value, 0n);
1379
1386
  if (have >= want) break;
1380
1387
  if (refetched) throw new Error("Not enough sat to complete transaction");
1381
1388
  utxos = await this.#fetchUTXOs(want, interactionParams);
1382
1389
  refetched = true;
1390
+ this.ensureUTXOsAvailable(utxos);
1383
1391
  if (utxos.reduce((s, u) => s + u.value, 0n) === have) throw new Error("Not enough sat to complete transaction");
1384
1392
  }
1385
1393
  return utxos;
@@ -2685,16 +2693,14 @@ var AbstractRpcProvider = class {
2685
2693
  * Get block witnesses.
2686
2694
  * @description This method is used to get the witnesses of a block. This proves that the actions executed inside a block are valid and confirmed by the network. If the minimum number of witnesses are not met, the block is considered as potentially invalid.
2687
2695
  * @param {BlockTag} height The block number or hash, use -1 for latest block
2688
- * @param {boolean} [trusted] Whether to trust the witnesses or not
2689
2696
  * @param {number} [limit] The maximum number of witnesses to return
2690
2697
  * @param {number} [page] The page number of the witnesses
2691
2698
  * @returns {Promise<BlockWitnesses>} The witnesses of the block
2692
2699
  * @example await getBlockWitness(123456n);
2693
2700
  * @throws {Error} If something went wrong while fetching the witnesses
2694
2701
  */
2695
- async getBlockWitness(height = -1, trusted, limit, page) {
2702
+ async getBlockWitness(height = -1, limit, page) {
2696
2703
  const params = [height.toString()];
2697
- if (trusted !== void 0 && trusted !== null) params.push(trusted);
2698
2704
  if (limit !== void 0 && limit !== null) params.push(limit);
2699
2705
  if (page !== void 0 && page !== null) params.push(page);
2700
2706
  const payload = this.buildJsonRpcPayload(JSONRpcMethods.BLOCK_WITNESS, params);
@@ -4462,8 +4468,7 @@ var WebSocketRpcProvider = class extends AbstractRpcProvider {
4462
4468
  case JSONRpcMethods.BLOCK_WITNESS: return {
4463
4469
  2: Long.fromString(String(params[0] ?? -1)),
4464
4470
  3: params[1],
4465
- 4: params[2],
4466
- 5: params[3]
4471
+ 4: params[2]
4467
4472
  };
4468
4473
  case JSONRpcMethods.GAS: return {};
4469
4474
  case JSONRpcMethods.GET_TRANSACTION_BY_HASH: return { 2: params[0] };
@@ -8853,7 +8858,7 @@ var OP721Events = [
8853
8858
  type: ABIDataTypes.ADDRESS
8854
8859
  },
8855
8860
  {
8856
- name: "amount",
8861
+ name: "tokenId",
8857
8862
  type: ABIDataTypes.UINT256
8858
8863
  }
8859
8864
  ],
@@ -8867,11 +8872,11 @@ var OP721Events = [
8867
8872
  type: ABIDataTypes.ADDRESS
8868
8873
  },
8869
8874
  {
8870
- name: "spender",
8875
+ name: "operator",
8871
8876
  type: ABIDataTypes.ADDRESS
8872
8877
  },
8873
8878
  {
8874
- name: "amount",
8879
+ name: "tokenId",
8875
8880
  type: ABIDataTypes.UINT256
8876
8881
  }
8877
8882
  ],
@@ -8895,6 +8900,28 @@ var OP721Events = [
8895
8900
  ],
8896
8901
  type: BitcoinAbiTypes.Event
8897
8902
  },
8903
+ {
8904
+ name: "Burned",
8905
+ values: [{
8906
+ name: "from",
8907
+ type: ABIDataTypes.ADDRESS
8908
+ }, {
8909
+ name: "tokenId",
8910
+ type: ABIDataTypes.UINT256
8911
+ }],
8912
+ type: BitcoinAbiTypes.Event
8913
+ },
8914
+ {
8915
+ name: "Minted",
8916
+ values: [{
8917
+ name: "to",
8918
+ type: ABIDataTypes.ADDRESS
8919
+ }, {
8920
+ name: "tokenId",
8921
+ type: ABIDataTypes.UINT256
8922
+ }],
8923
+ type: BitcoinAbiTypes.Event
8924
+ },
8898
8925
  {
8899
8926
  name: "URI",
8900
8927
  values: [{
@@ -8941,30 +8968,6 @@ var OP_721_ABI = [
8941
8968
  type: ABIDataTypes.UINT256
8942
8969
  }]
8943
8970
  },
8944
- {
8945
- name: "collectionInfo",
8946
- type: BitcoinAbiTypes.Function,
8947
- constant: true,
8948
- inputs: [],
8949
- outputs: [
8950
- {
8951
- name: "icon",
8952
- type: ABIDataTypes.STRING
8953
- },
8954
- {
8955
- name: "banner",
8956
- type: ABIDataTypes.STRING
8957
- },
8958
- {
8959
- name: "description",
8960
- type: ABIDataTypes.STRING
8961
- },
8962
- {
8963
- name: "website",
8964
- type: ABIDataTypes.STRING
8965
- }
8966
- ]
8967
- },
8968
8971
  {
8969
8972
  name: "tokenURI",
8970
8973
  type: BitcoinAbiTypes.Function,
@@ -9210,7 +9213,7 @@ var OP_721_ABI = [
9210
9213
  }]
9211
9214
  },
9212
9215
  {
9213
- name: "getApproveNonce",
9216
+ name: "nonceOf",
9214
9217
  type: BitcoinAbiTypes.Function,
9215
9218
  constant: true,
9216
9219
  inputs: [{
@@ -61,7 +61,7 @@ export declare abstract class AbstractRpcProvider {
61
61
  sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction>;
62
62
  sendRawTransactions(txs: string[]): Promise<BroadcastedTransaction[]>;
63
63
  sendRawTransactionPackage(txs: string[], isPackage?: boolean): Promise<BroadcastedTransactionPackage>;
64
- getBlockWitness(height?: BigNumberish, trusted?: boolean, limit?: number, page?: number): Promise<BlockWitnesses>;
64
+ getBlockWitness(height?: BigNumberish, limit?: number, page?: number): Promise<BlockWitnesses>;
65
65
  getReorg(fromBlock?: BigNumberish, toBlock?: BigNumberish): Promise<ReorgInformation[]>;
66
66
  abstract _send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
67
67
  callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult>;
@@ -1 +1 @@
1
- export declare const version = "1.8.4";
1
+ export declare const version = "1.8.5";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.8.4';
1
+ export const version = '1.8.5';
@@ -18,7 +18,7 @@ export const OP721Events = [
18
18
  type: ABIDataTypes.ADDRESS,
19
19
  },
20
20
  {
21
- name: 'amount',
21
+ name: 'tokenId',
22
22
  type: ABIDataTypes.UINT256,
23
23
  },
24
24
  ],
@@ -32,11 +32,11 @@ export const OP721Events = [
32
32
  type: ABIDataTypes.ADDRESS,
33
33
  },
34
34
  {
35
- name: 'spender',
35
+ name: 'operator',
36
36
  type: ABIDataTypes.ADDRESS,
37
37
  },
38
38
  {
39
- name: 'amount',
39
+ name: 'tokenId',
40
40
  type: ABIDataTypes.UINT256,
41
41
  },
42
42
  ],
@@ -60,6 +60,34 @@ export const OP721Events = [
60
60
  ],
61
61
  type: BitcoinAbiTypes.Event,
62
62
  },
63
+ {
64
+ name: 'Burned',
65
+ values: [
66
+ {
67
+ name: 'from',
68
+ type: ABIDataTypes.ADDRESS
69
+ },
70
+ {
71
+ name: 'tokenId',
72
+ type: ABIDataTypes.UINT256
73
+ },
74
+ ],
75
+ type: BitcoinAbiTypes.Event,
76
+ },
77
+ {
78
+ name: 'Minted',
79
+ values: [
80
+ {
81
+ name: 'to',
82
+ type: ABIDataTypes.ADDRESS,
83
+ },
84
+ {
85
+ name: 'tokenId',
86
+ type: ABIDataTypes.UINT256,
87
+ },
88
+ ],
89
+ type: BitcoinAbiTypes.Event,
90
+ },
63
91
  {
64
92
  name: 'URI',
65
93
  values: [
@@ -112,30 +140,6 @@ export const OP_721_ABI = [
112
140
  },
113
141
  ],
114
142
  },
115
- {
116
- name: 'collectionInfo',
117
- type: BitcoinAbiTypes.Function,
118
- constant: true,
119
- inputs: [],
120
- outputs: [
121
- {
122
- name: 'icon',
123
- type: ABIDataTypes.STRING,
124
- },
125
- {
126
- name: 'banner',
127
- type: ABIDataTypes.STRING,
128
- },
129
- {
130
- name: 'description',
131
- type: ABIDataTypes.STRING,
132
- },
133
- {
134
- name: 'website',
135
- type: ABIDataTypes.STRING,
136
- },
137
- ],
138
- },
139
143
  {
140
144
  name: 'tokenURI',
141
145
  type: BitcoinAbiTypes.Function,
@@ -417,7 +421,7 @@ export const OP_721_ABI = [
417
421
  ],
418
422
  },
419
423
  {
420
- name: 'getApproveNonce',
424
+ name: 'nonceOf',
421
425
  type: BitcoinAbiTypes.Function,
422
426
  constant: true,
423
427
  inputs: [
@@ -1,7 +1,6 @@
1
1
  import { Address } from '@btc-vision/transaction';
2
2
  import { BlockWitnesses, IBlockWitness, IBlockWitnessAPI, RawBlockWitnessAPI } from './interfaces/IBlockWitness.js';
3
3
  export declare class BlockWitnessAPI implements IBlockWitnessAPI {
4
- readonly trusted: boolean;
5
4
  readonly signature: Uint8Array;
6
5
  readonly timestamp: number;
7
6
  readonly proofs: readonly Uint8Array[];
@@ -1,14 +1,12 @@
1
1
  import { Address } from '@btc-vision/transaction';
2
2
  import { stringBase64ToBuffer } from '../utils/StringToBuffer.js';
3
3
  export class BlockWitnessAPI {
4
- trusted;
5
4
  signature;
6
5
  timestamp;
7
6
  proofs;
8
7
  identity;
9
8
  publicKey;
10
9
  constructor(data) {
11
- this.trusted = data.trusted;
12
10
  this.signature = stringBase64ToBuffer(data.signature);
13
11
  this.timestamp = data.timestamp;
14
12
  this.proofs = Object.freeze(data.proofs.map((proof) => stringBase64ToBuffer(proof)));
@@ -1,6 +1,5 @@
1
1
  import { Address } from '@btc-vision/transaction';
2
2
  export interface IBlockWitnessAPI {
3
- readonly trusted: boolean;
4
3
  readonly signature: Uint8Array;
5
4
  readonly timestamp: number;
6
5
  readonly proofs: readonly Uint8Array[];
@@ -8,7 +7,6 @@ export interface IBlockWitnessAPI {
8
7
  readonly publicKey?: Address;
9
8
  }
10
9
  export interface RawBlockWitnessAPI {
11
- readonly trusted: boolean;
12
10
  readonly signature: string;
13
11
  readonly timestamp: number;
14
12
  readonly proofs: readonly string[];
@@ -108,6 +108,8 @@ export declare class CallResult<T extends ContractDecodedObjectResult = {}, U ex
108
108
  setCalldata(calldata: Uint8Array): void;
109
109
  toOfflineBuffer(refundAddress: string, amount: bigint): Promise<Uint8Array>;
110
110
  private max;
111
+ private ensureUTXOsAvailable;
112
+ private computeRequiredAmount;
111
113
  private acquire;
112
114
  private bigintMax;
113
115
  private getValuesFromAccessList;
@@ -430,6 +430,16 @@ export class CallResult {
430
430
  max(a, b) {
431
431
  return a > b ? a : b;
432
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
+ }
433
443
  async acquire(interactionParams, amountAddition = 0n) {
434
444
  if (!this.calldata) {
435
445
  throw new Error('Calldata not set');
@@ -442,12 +452,14 @@ export class CallResult {
442
452
  const addedOuts = interactionParams.extraOutputs ?? [];
443
453
  const totalOuts = addedOuts.reduce((s, o) => s + BigInt(o.value), 0n);
444
454
  const gasFee = this.bigintMax(this.estimatedSatGas, interactionParams.minGas ?? 0n);
445
- const preWant = this.max(gasFee + priority + amountAddition + totalOuts, 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);
446
457
  let utxos = interactionParams.utxos ?? (await this.#fetchUTXOs(preWant, interactionParams));
458
+ this.ensureUTXOsAvailable(utxos);
447
459
  let refetched = false;
448
460
  while (true) {
449
461
  const miningCost = TransactionHelper.estimateMiningCost(utxos, addedOuts, this.calldata.length + 200, interactionParams.network, feeRate);
450
- const want = this.max(gasFee + priority + amountAddition + totalOuts + miningCost, interactionParams.maximumAllowedSatToSpend);
462
+ const want = this.computeRequiredAmount(gasFee, priority, amountAddition, totalOuts, extraInputValue, miningCost, interactionParams.maximumAllowedSatToSpend);
451
463
  const have = utxos.reduce((s, u) => s + u.value, 0n);
452
464
  if (have >= want)
453
465
  break;
@@ -456,6 +468,7 @@ export class CallResult {
456
468
  }
457
469
  utxos = await this.#fetchUTXOs(want, interactionParams);
458
470
  refetched = true;
471
+ this.ensureUTXOsAvailable(utxos);
459
472
  const haveAfter = utxos.reduce((s, u) => s + u.value, 0n);
460
473
  if (haveAfter === have) {
461
474
  throw new Error('Not enough sat to complete transaction');
@@ -62,7 +62,7 @@ export declare abstract class AbstractRpcProvider {
62
62
  sendRawTransaction(tx: string, psbt: boolean): Promise<BroadcastedTransaction>;
63
63
  sendRawTransactions(txs: string[]): Promise<BroadcastedTransaction[]>;
64
64
  sendRawTransactionPackage(txs: string[], isPackage?: boolean): Promise<BroadcastedTransactionPackage>;
65
- getBlockWitness(height?: BigNumberish, trusted?: boolean, limit?: number, page?: number): Promise<BlockWitnesses>;
65
+ getBlockWitness(height?: BigNumberish, limit?: number, page?: number): Promise<BlockWitnesses>;
66
66
  getReorg(fromBlock?: BigNumberish, toBlock?: BigNumberish): Promise<ReorgInformation[]>;
67
67
  abstract _send(payload: JsonRpcPayload | JsonRpcPayload[]): Promise<JsonRpcCallResult>;
68
68
  callPayloadSingle(payload: JsonRpcPayload): Promise<JsonRpcResult>;
@@ -339,10 +339,8 @@ export class AbstractRpcProvider {
339
339
  const result = await this.callPayloadSingle(payload);
340
340
  return result.result;
341
341
  }
342
- async getBlockWitness(height = -1, trusted, limit, page) {
342
+ async getBlockWitness(height = -1, limit, page) {
343
343
  const params = [height.toString()];
344
- if (trusted !== undefined && trusted !== null)
345
- params.push(trusted);
346
344
  if (limit !== undefined && limit !== null)
347
345
  params.push(limit);
348
346
  if (page !== undefined && page !== null)
@@ -226,7 +226,6 @@ export class WebSocketRpcProvider extends AbstractRpcProvider {
226
226
  2: Long.fromString(String(params[0] ?? -1)),
227
227
  3: params[1],
228
228
  4: params[2],
229
- 5: params[3],
230
229
  };
231
230
  case JSONRpcMethods.GAS:
232
231
  return {};