gn-provider 1.2.5 → 1.2.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.
Files changed (2) hide show
  1. package/dist/gn-provider.js +42 -11
  2. package/package.json +1 -1
@@ -230,55 +230,86 @@ class GNProvider extends abstract_provider_1.Provider {
230
230
  yield this._ready();
231
231
  const headers = this._getHeaders();
232
232
  const size = Math.max(1, rawTxHex.length / 2 / 1024);
233
+ const timeout = Math.max(10000, 1000 * size);
234
+ try {
235
+ const res = yield superagent.post(`${this.apiPrefix()}/tx/raw`)
236
+ .timeout({
237
+ response: timeout,
238
+ deadline: 60000
239
+ })
240
+ .set(headers)
241
+ .send({ txhex: rawTxHex });
242
+ return res.body;
243
+ }
244
+ catch (error) {
245
+ if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.text) {
246
+ if (this.needIgnoreError(error.response.text)) {
247
+ return new scryptlib.bsv.Transaction(rawTxHex).id;
248
+ }
249
+ throw new Error(`GNProvider ERROR: ${this.friendlyBIP22RejectionMsg(error.response.text)}`);
250
+ }
251
+ throw new Error(`GNProvider ERROR: ${error.message}`);
252
+ }
253
+ });
254
+ /*sendRawTransaction = async (rawTxHex: string): Promise<TxHash> => {
255
+ await this._ready();
256
+ const headers = this._getHeaders();
257
+ const size = Math.max(1, rawTxHex.length / 2 / 1024);
233
258
  const timeout = Math.max(15000, 1000 * size);
259
+
234
260
  const wocRequest = superagent.post(`${this.apiPrefix()}/tx/raw`)
235
261
  .timeout({ response: timeout, deadline: 60000 })
236
262
  .set(headers)
237
263
  .send({ txhex: rawTxHex });
264
+
238
265
  const gpRequest = superagent.post(this._mapiURL + 'tx')
239
266
  .timeout({ response: timeout, deadline: 60000 })
240
267
  .set('Content-Type', 'application/octet-stream')
241
268
  .send(Buffer.from(rawTxHex, 'hex'));
269
+
242
270
  if (this._gorillaPoolApiKey) {
243
271
  gpRequest.set('Authorization', `Bearer ${this._gorillaPoolApiKey}`);
244
272
  }
273
+
245
274
  try {
246
- const responses = yield Promise.allSettled([
275
+ const responses = await Promise.allSettled([
247
276
  wocRequest.then(res => ({ source: 'WhatsOnChain', result: res.body })),
248
277
  gpRequest.then(res => {
249
- var _a;
250
278
  try {
251
- if (!((_a = res.body) === null || _a === void 0 ? void 0 : _a.payload)) {
279
+ if (!res.body?.payload) {
252
280
  throw new Error('Respuesta inválida de GorillaPool: falta payload');
253
281
  }
282
+
254
283
  const payload = JSON.parse(res.body.payload);
284
+
255
285
  if (payload.returnResult === 'success') {
256
286
  return { source: 'GorillaPool', result: payload.txid };
257
- }
258
- else {
287
+ } else {
259
288
  throw new Error(`GorillaPool [${payload.returnResult || 'unknown'}]: ${payload.resultDescription || 'Sin descripción'}`);
260
289
  }
261
- }
262
- catch (parseError) {
290
+ } catch (parseError) {
263
291
  const message = parseError instanceof Error ? parseError.message : String(parseError);
264
292
  throw new Error(`GorillaPool: Error parsing response - ${message}`);
265
293
  }
266
294
  })
267
295
  ]);
296
+
268
297
  for (const response of responses) {
269
298
  if (response.status === 'fulfilled') {
270
299
  console.log(`✅ Transacción aceptada por: ${response.value.source}`);
271
300
  return response.value.result;
272
301
  }
273
302
  }
303
+
274
304
  const firstRejection = responses.find(r => r.status === 'rejected');
275
305
  if (firstRejection) {
276
306
  throw new Error(firstRejection.reason.message || firstRejection.reason);
277
307
  }
308
+
278
309
  throw new Error('Todos los intentos de envío fallaron');
279
- }
280
- catch (error) {
281
- if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.text) {
310
+
311
+ } catch (error: any) {
312
+ if (error.response?.text) {
282
313
  if (this.needIgnoreError(error.response.text)) {
283
314
  return new scryptlib.bsv.Transaction(rawTxHex).id;
284
315
  }
@@ -286,7 +317,7 @@ class GNProvider extends abstract_provider_1.Provider {
286
317
  }
287
318
  throw new Error(`GNProvider ERROR: ${error.message}`);
288
319
  }
289
- });
320
+ }*/
290
321
  this.sendTransaction = (signedTx) => __awaiter(this, void 0, void 0, function* () {
291
322
  try {
292
323
  const txHex = signedTx.serialize({ disableIsFullySigned: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gn-provider",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "files": [
5
5
  "dist",
6
6
  "scripts",