opnet 1.3.1 → 1.3.2

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.
@@ -1 +1 @@
1
- export declare const version = "1.3.1";
1
+ export declare const version = "1.3.2";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.3.1';
1
+ export const version = '1.3.2';
@@ -37,7 +37,7 @@ export declare class CallResult<T extends ContractDecodedObjectResult = {}, U ex
37
37
  constructor(callResult: ICallResultData, provider: AbstractRpcProvider);
38
38
  get rawEvents(): EventList;
39
39
  setTo(to: string): void;
40
- sendTransaction(interactionParams: TransactionParameters): Promise<InteractionTransactionReceipt>;
40
+ sendTransaction(interactionParams: TransactionParameters, amountAddition?: bigint): Promise<InteractionTransactionReceipt>;
41
41
  setGasEstimation(estimatedGas: bigint): void;
42
42
  setDecoded(decoded: DecodedOutput): void;
43
43
  setEvents(events: U): void;
@@ -31,7 +31,7 @@ export class CallResult {
31
31
  setTo(to) {
32
32
  this.to = to;
33
33
  }
34
- async sendTransaction(interactionParams) {
34
+ async sendTransaction(interactionParams, amountAddition = 0n) {
35
35
  if (!this.calldata) {
36
36
  throw new Error('Calldata not set');
37
37
  }
@@ -47,7 +47,10 @@ export class CallResult {
47
47
  const totalFee = this.estimatedSatGas + priorityFee;
48
48
  try {
49
49
  const UTXOs = interactionParams.utxos ||
50
- (await this.#fetchUTXOs(totalFee + interactionParams.maximumAllowedSatToSpend + totalAmount, interactionParams));
50
+ (await this.#fetchUTXOs(totalFee +
51
+ interactionParams.maximumAllowedSatToSpend +
52
+ totalAmount +
53
+ amountAddition, interactionParams));
51
54
  if (!UTXOs || UTXOs.length === 0) {
52
55
  throw new Error('No UTXOs found');
53
56
  }
@@ -87,6 +90,10 @@ export class CallResult {
87
90
  };
88
91
  }
89
92
  catch (e) {
93
+ const msgStr = e.message;
94
+ if (msgStr.includes('Insufficient funds to pay the fees') && amountAddition === 0n) {
95
+ return await this.sendTransaction(interactionParams, 200000n);
96
+ }
90
97
  this.#provider.utxoManager.clean();
91
98
  throw e;
92
99
  }
@@ -109,7 +116,7 @@ export class CallResult {
109
116
  }
110
117
  const utxoSetting = {
111
118
  address: interactionParams.refundTo,
112
- amount: 10000n + amount,
119
+ amount: 50000n + amount,
113
120
  throwErrors: true,
114
121
  };
115
122
  const utxos = await this.#provider.utxoManager.getUTXOsForAmount(utxoSetting);
@@ -15,6 +15,8 @@ export class JSONRpcProvider extends AbstractRpcProvider {
15
15
  method: 'POST',
16
16
  headers: {
17
17
  'Content-Type': 'application/json',
18
+ Connection: 'close',
19
+ 'User-Agent': 'OPNET/1.0',
18
20
  },
19
21
  body: JSON.stringify(payload),
20
22
  timeout: this.timeout,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opnet",
3
3
  "type": "module",
4
- "version": "1.3.1",
4
+ "version": "1.3.2",
5
5
  "author": "OP_NET",
6
6
  "description": "The perfect library for building Bitcoin-based applications.",
7
7
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.3.1';
1
+ export const version = '1.3.2';
@@ -93,10 +93,12 @@ export class CallResult<
93
93
  /**
94
94
  * Easily create a bitcoin interaction transaction from a simulated contract call.
95
95
  * @param {TransactionParameters} interactionParams - The parameters for the transaction.
96
+ * @param amountAddition
96
97
  * @returns {Promise<InteractionTransactionReceipt>} The transaction hash, the transaction hex and the UTXOs used.
97
98
  */
98
99
  public async sendTransaction(
99
100
  interactionParams: TransactionParameters,
101
+ amountAddition: bigint = 0n,
100
102
  ): Promise<InteractionTransactionReceipt> {
101
103
  if (!this.calldata) {
102
104
  throw new Error('Calldata not set');
@@ -119,7 +121,10 @@ export class CallResult<
119
121
  const UTXOs: UTXO[] =
120
122
  interactionParams.utxos ||
121
123
  (await this.#fetchUTXOs(
122
- totalFee + interactionParams.maximumAllowedSatToSpend + totalAmount,
124
+ totalFee +
125
+ interactionParams.maximumAllowedSatToSpend +
126
+ totalAmount +
127
+ amountAddition,
123
128
  interactionParams,
124
129
  ));
125
130
 
@@ -174,6 +179,12 @@ export class CallResult<
174
179
  preimage: transaction.preimage,
175
180
  };
176
181
  } catch (e) {
182
+ const msgStr = (e as Error).message;
183
+
184
+ if (msgStr.includes('Insufficient funds to pay the fees') && amountAddition === 0n) {
185
+ return await this.sendTransaction(interactionParams, 200_000n);
186
+ }
187
+
177
188
  // We need to clean up the UTXOs if the transaction fails
178
189
  this.#provider.utxoManager.clean();
179
190
 
@@ -204,7 +215,7 @@ export class CallResult<
204
215
 
205
216
  const utxoSetting: RequestUTXOsParamsWithAmount = {
206
217
  address: interactionParams.refundTo,
207
- amount: 10000n + amount,
218
+ amount: 50_000n + amount,
208
219
  throwErrors: true,
209
220
  };
210
221
 
@@ -38,6 +38,8 @@ export class JSONRpcProvider extends AbstractRpcProvider {
38
38
  method: 'POST',
39
39
  headers: {
40
40
  'Content-Type': 'application/json',
41
+ Connection: 'close',
42
+ 'User-Agent': 'OPNET/1.0',
41
43
  },
42
44
  body: JSON.stringify(payload),
43
45
  timeout: this.timeout,