@meshconnect/uwc-injected-connector 0.26.0 → 0.26.1-snapshot.0c4e867
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/services/ethereum/ethereum-transaction-service.d.ts.map +1 -1
- package/dist/services/ethereum/ethereum-transaction-service.js +28 -7
- package/dist/services/ethereum/ethereum-transaction-service.js.map +1 -1
- package/package.json +7 -7
- package/src/services/ethereum/ethereum-transaction-service.test.ts +222 -5
- package/src/services/ethereum/ethereum-transaction-service.ts +41 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum-transaction-service.d.ts","sourceRoot":"","sources":["../../../src/services/ethereum/ethereum-transaction-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAKV,0BAA0B,EAE3B,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"ethereum-transaction-service.d.ts","sourceRoot":"","sources":["../../../src/services/ethereum/ethereum-transaction-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,KAAK,EAKV,0BAA0B,EAE3B,MAAM,wBAAwB,CAAA;AAY/B;;GAEG;AACH,qBAAa,0BAA0B;IACrC,OAAO,CAAC,OAAO,CAA4B;IAE3C,cAEC;IAED;;OAEG;IACG,eAAe,CACnB,OAAO,EAAE,0BAA0B,EACnC,QAAQ,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,CAAC,CAiCjB;IAED;;OAEG;YACW,qBAAqB;IAiCnC;;OAEG;YACW,gBAAgB;IAkC9B;;OAEG;YACW,gBAAgB;IAkC9B;;OAEG;YACW,SAAS;CAgJxB"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { createWalletClient, custom } from 'viem';
|
|
2
|
+
import { BatchConfirmedWithoutReceiptError } from '@meshconnect/uwc-types';
|
|
2
3
|
import { parseError } from '../../utils/error-utils';
|
|
3
4
|
import { EthereumTransactionBuilder } from './ethereum-transaction-builder';
|
|
5
|
+
/**
|
|
6
|
+
* How long a confirmed (200) batch without receipts is re-read before giving up.
|
|
7
|
+
* EIP-5792 makes receipts optional; a wallet may still add them on a later read.
|
|
8
|
+
*/
|
|
9
|
+
const RECEIPT_POLL_INTERVAL_MS = 1000;
|
|
10
|
+
const RECEIPT_POLL_ATTEMPTS = 10;
|
|
4
11
|
/**
|
|
5
12
|
* Service for handling Ethereum/EVM transaction operations
|
|
6
13
|
*/
|
|
@@ -188,13 +195,14 @@ export class EthereumTransactionService {
|
|
|
188
195
|
});
|
|
189
196
|
// Poll for completion with retry logic for specific errors
|
|
190
197
|
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
198
|
+
const getCallsStatus = () => client.request({
|
|
199
|
+
method: 'wallet_getCallsStatus',
|
|
200
|
+
params: [response.id]
|
|
201
|
+
});
|
|
191
202
|
let result;
|
|
192
203
|
while (true) {
|
|
193
204
|
try {
|
|
194
|
-
result = await
|
|
195
|
-
method: 'wallet_getCallsStatus',
|
|
196
|
-
params: [response.id]
|
|
197
|
-
});
|
|
205
|
+
result = await getCallsStatus();
|
|
198
206
|
// Wait 1 second if still pending
|
|
199
207
|
if (result?.status === 100) {
|
|
200
208
|
await sleep(1000);
|
|
@@ -218,10 +226,23 @@ export class EthereumTransactionService {
|
|
|
218
226
|
if (result.status !== 200) {
|
|
219
227
|
throw new Error('Batch transaction failed');
|
|
220
228
|
}
|
|
221
|
-
// Return first transaction hash
|
|
222
|
-
|
|
229
|
+
// Return first transaction hash. A confirmed batch may come without
|
|
230
|
+
// receipts (optional in EIP-5792): re-read for a while in case the wallet
|
|
231
|
+
// adds them, and only then report it as confirmed-without-receipt.
|
|
232
|
+
let firstReceipt = result.receipts?.find(r => r);
|
|
233
|
+
for (let attempt = 0; !firstReceipt && attempt < RECEIPT_POLL_ATTEMPTS; attempt++) {
|
|
234
|
+
await sleep(RECEIPT_POLL_INTERVAL_MS);
|
|
235
|
+
try {
|
|
236
|
+
firstReceipt = (await getCallsStatus())?.receipts?.find(r => r);
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// The batch is already confirmed; a failed re-read must not turn it
|
|
240
|
+
// into a failure. Stop and report it without a receipt.
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
223
244
|
if (!firstReceipt) {
|
|
224
|
-
throw new
|
|
245
|
+
throw new BatchConfirmedWithoutReceiptError(response.id, request.chainId);
|
|
225
246
|
}
|
|
226
247
|
return firstReceipt.transactionHash;
|
|
227
248
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethereum-transaction-service.js","sourceRoot":"","sources":["../../../src/services/ethereum/ethereum-transaction-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAUjD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAA;AAE3E;;GAEG;AACH,MAAM,OAAO,0BAA0B;IAC7B,OAAO,CAA4B;IAE3C;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,0BAA0B,EAAE,CAAA;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CACnB,OAAmC,EACnC,QAA0B;QAE1B,IAAI,CAAC;YACH,6CAA6C;YAC7C,IAAI,iBAAiB,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;gBACrD,gBAAgB;gBAChB,OAAO,MAAM,IAAI,CAAC,gBAAgB,CAChC,QAAQ,EACR,OAAiC,CAClC,CAAA;YACH,CAAC;iBAAM,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;gBAC9B,oBAAoB;gBACpB,OAAO,MAAM,IAAI,CAAC,SAAS,CACzB,QAAQ,EACR,OAA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C,CAAC,QAAQ,CAAC,EAAE,CAAC;qBAChD,CAAA;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;gBACrD,CAAC;YACH,CAAC,CAAC,CACH,CAAA;YAED,4BAA4B;YAC5B,MAAM,MAAM,GAAG,kBAAkB,CAAC;gBAChC,OAAO,EAAE,OAAO,CAAC,IAAqB;gBACtC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC;aAC5B,CAAC,CAAA;YAEF,wCAAwC;YACxC,MAAM,QAAQ,GAAmB,MAC/B,MAAM,CAAC,OAIR,CAAC;gBACA,MAAM,EAAE,kBAAkB;gBAC1B,MAAM,EAAE;oBACN;wBACE,OAAO,EAAE,OAAO,CAAC,OAAO;wBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;wBAClB,OAAO,EAAE,OAAO,CAAC,OAAO;wBACxB,cAAc,EAAE,OAAO,CAAC,cAAc;wBACtC,KAAK,EAAE,KAAK;qBACb;iBACF;aACF,CAAC,CAAA;YAEF,2DAA2D;YAC3D,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAC3B,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;YACjD,
|
|
1
|
+
{"version":3,"file":"ethereum-transaction-service.js","sourceRoot":"","sources":["../../../src/services/ethereum/ethereum-transaction-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAUjD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wBAAwB,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAA;AAE3E;;;GAGG;AACH,MAAM,wBAAwB,GAAG,IAAI,CAAA;AACrC,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAE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C,YAAY,IAAI,OAAO,GAAG,qBAAqB,EAChD,OAAO,EAAE,EACT,CAAC;gBACD,MAAM,KAAK,CAAC,wBAAwB,CAAC,CAAA;gBACrC,IAAI,CAAC;oBACH,YAAY,GAAG,CAAC,MAAM,cAAc,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;gBACjE,CAAC;gBAAC,MAAM,CAAC;oBACP,oEAAoE;oBACpE,wDAAwD;oBACxD,MAAK;gBACP,CAAC;YACH,CAAC;YACD,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,MAAM,IAAI,iCAAiC,CACzC,QAAQ,CAAC,EAAE,EACX,OAAO,CAAC,OAAO,CAChB,CAAA;YACH,CAAC;YAED,OAAO,YAAY,CAAC,eAAe,CAAA;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,UAAU,CAAC,KAAK,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-injected-connector",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.1-snapshot.0c4e867",
|
|
4
4
|
"description": "Injected connector for Universal Wallet Connector",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"buffer": "^6.0.3",
|
|
28
28
|
"uuid": "^14.0.2",
|
|
29
29
|
"viem": "^2.56.5",
|
|
30
|
-
"@meshconnect/uwc-bridge-child": "0.6.0",
|
|
31
|
-
"@meshconnect/uwc-constants": "0.
|
|
32
|
-
"@meshconnect/uwc-ton-connector": "0.9.
|
|
33
|
-
"@meshconnect/uwc-bitcoin": "0.5.
|
|
34
|
-
"@meshconnect/uwc-tron-connector": "0.7.
|
|
35
|
-
"@meshconnect/uwc-types": "0.
|
|
30
|
+
"@meshconnect/uwc-bridge-child": "0.6.0-snapshot.0c4e867",
|
|
31
|
+
"@meshconnect/uwc-constants": "0.8.0-snapshot.0c4e867",
|
|
32
|
+
"@meshconnect/uwc-ton-connector": "0.9.8-snapshot.0c4e867",
|
|
33
|
+
"@meshconnect/uwc-bitcoin": "0.5.2-snapshot.0c4e867",
|
|
34
|
+
"@meshconnect/uwc-tron-connector": "0.7.12-snapshot.0c4e867",
|
|
35
|
+
"@meshconnect/uwc-types": "0.30.0-snapshot.0c4e867"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typescript": "^7.0.2"
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
|
2
2
|
import { EthereumTransactionService } from './ethereum-transaction-service'
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import {
|
|
4
|
+
BatchConfirmedWithoutReceiptError,
|
|
5
|
+
WalletConnectorError,
|
|
6
|
+
type EVMNativeTransferRequest,
|
|
7
|
+
type EVMContractCallRequest,
|
|
8
|
+
type EVMDataTransferRequest,
|
|
9
|
+
type EVMBatchTransactionRequest
|
|
7
10
|
} from '@meshconnect/uwc-types'
|
|
8
11
|
import type { EthereumProvider } from '../../eip6963-discovery'
|
|
9
12
|
|
|
@@ -271,4 +274,218 @@ describe('EthereumTransactionService', () => {
|
|
|
271
274
|
).rejects.toThrow()
|
|
272
275
|
})
|
|
273
276
|
})
|
|
277
|
+
|
|
278
|
+
describe('sendBatch (EIP-5792)', () => {
|
|
279
|
+
const BATCH_ID = '0x8becd65ed2d2425485a9a90d04b63ec0'
|
|
280
|
+
const TX_HASH =
|
|
281
|
+
'0x1986bfb2c0ffee00000000000000000000000000000000000000000000aad1'
|
|
282
|
+
|
|
283
|
+
// Recorded from MetaMask Mobile (iOS in-app browser) paying the network fee
|
|
284
|
+
// in ARB on Arbitrum: confirmed, atomic, and no `receipts` field at all.
|
|
285
|
+
const confirmedWithoutReceipts = {
|
|
286
|
+
version: '2.0.0',
|
|
287
|
+
id: BATCH_ID,
|
|
288
|
+
chainId: '0xa4b1',
|
|
289
|
+
atomic: true,
|
|
290
|
+
status: 200
|
|
291
|
+
}
|
|
292
|
+
const confirmedWithReceipts = {
|
|
293
|
+
...confirmedWithoutReceipts,
|
|
294
|
+
receipts: [{ transactionHash: TX_HASH }]
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const batchRequest: EVMBatchTransactionRequest = {
|
|
298
|
+
version: '2.0.0',
|
|
299
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
300
|
+
chainId: '0xa4b1',
|
|
301
|
+
atomicRequired: true,
|
|
302
|
+
calls: [
|
|
303
|
+
{
|
|
304
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
305
|
+
to: '0x0987654321098765432109876543210987654321',
|
|
306
|
+
data: '0x095ea7b3',
|
|
307
|
+
chainId: '42161'
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
from: '0x1234567890123456789012345678901234567890',
|
|
311
|
+
to: '0x0987654321098765432109876543210987654321',
|
|
312
|
+
data: '0xa9059cbb',
|
|
313
|
+
chainId: '42161'
|
|
314
|
+
}
|
|
315
|
+
]
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Provider that accepts `wallet_sendCalls` and answers each
|
|
320
|
+
* `wallet_getCallsStatus` with the next scripted reply (the last one
|
|
321
|
+
* repeats). A reply that is an Error is thrown instead.
|
|
322
|
+
*/
|
|
323
|
+
const batchProvider = (statusReplies: unknown[]) => {
|
|
324
|
+
let call = 0
|
|
325
|
+
const request = vi.fn(async ({ method }: { method: string }) => {
|
|
326
|
+
if (method === 'wallet_sendCalls') return { id: BATCH_ID }
|
|
327
|
+
if (method === 'wallet_getCallsStatus') {
|
|
328
|
+
const reply =
|
|
329
|
+
statusReplies[Math.min(call++, statusReplies.length - 1)]
|
|
330
|
+
if (reply instanceof Error) throw reply
|
|
331
|
+
return reply
|
|
332
|
+
}
|
|
333
|
+
throw new Error(`unexpected method ${method}`)
|
|
334
|
+
})
|
|
335
|
+
return { request } as unknown as EthereumProvider & {
|
|
336
|
+
request: typeof request
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const statusCalls = (provider: { request: ReturnType<typeof vi.fn> }) =>
|
|
341
|
+
provider.request.mock.calls.filter(
|
|
342
|
+
([args]) =>
|
|
343
|
+
(args as { method: string }).method === 'wallet_getCallsStatus'
|
|
344
|
+
).length
|
|
345
|
+
|
|
346
|
+
/** Run a send to completion under fake timers; resolves to its outcome. */
|
|
347
|
+
const settle = async (provider: EthereumProvider) => {
|
|
348
|
+
const outcome = service.sendTransaction(batchRequest, provider).then(
|
|
349
|
+
hash => ({ hash }),
|
|
350
|
+
(error: unknown) => ({ error })
|
|
351
|
+
)
|
|
352
|
+
await vi.runAllTimersAsync()
|
|
353
|
+
return outcome
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
beforeEach(() => {
|
|
357
|
+
vi.useFakeTimers()
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
afterEach(() => {
|
|
361
|
+
vi.useRealTimers()
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it('returns the first receipt hash when the confirmation carries receipts', async () => {
|
|
365
|
+
const provider = batchProvider([confirmedWithReceipts])
|
|
366
|
+
|
|
367
|
+
expect(await settle(provider)).toEqual({ hash: TX_HASH })
|
|
368
|
+
expect(statusCalls(provider)).toBe(1)
|
|
369
|
+
const sendCalls = provider.request.mock.calls.find(
|
|
370
|
+
([args]) => (args as { method: string }).method === 'wallet_sendCalls'
|
|
371
|
+
)
|
|
372
|
+
expect(sendCalls?.[0]).toMatchObject({
|
|
373
|
+
params: [{ version: '2.0.0', chainId: '0xa4b1', atomicRequired: true }]
|
|
374
|
+
})
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
it('keeps polling a receipt-less confirmation and returns the hash once receipts appear', async () => {
|
|
378
|
+
const provider = batchProvider([
|
|
379
|
+
confirmedWithoutReceipts,
|
|
380
|
+
confirmedWithoutReceipts,
|
|
381
|
+
confirmedWithReceipts
|
|
382
|
+
])
|
|
383
|
+
|
|
384
|
+
expect(await settle(provider)).toEqual({ hash: TX_HASH })
|
|
385
|
+
expect(statusCalls(provider)).toBe(3)
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
it('throws BatchConfirmedWithoutReceiptError when receipts never appear', async () => {
|
|
389
|
+
const provider = batchProvider([confirmedWithoutReceipts])
|
|
390
|
+
|
|
391
|
+
const outcome = await settle(provider)
|
|
392
|
+
|
|
393
|
+
expect(outcome).not.toHaveProperty('hash')
|
|
394
|
+
const { error } = outcome as { error: unknown }
|
|
395
|
+
expect(error).toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
396
|
+
// Subclass of the connector error, so `parseError` passes it through.
|
|
397
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
398
|
+
expect(error).toMatchObject({
|
|
399
|
+
name: 'BatchConfirmedWithoutReceiptError',
|
|
400
|
+
batchId: BATCH_ID,
|
|
401
|
+
chainId: '0xa4b1'
|
|
402
|
+
})
|
|
403
|
+
// The initial read plus 10 one-second re-reads, then it gives up.
|
|
404
|
+
expect(statusCalls(provider)).toBe(11)
|
|
405
|
+
})
|
|
406
|
+
|
|
407
|
+
it('gives up on receipts after about 10 seconds', async () => {
|
|
408
|
+
const provider = batchProvider([confirmedWithoutReceipts])
|
|
409
|
+
const outcome = service.sendTransaction(batchRequest, provider).then(
|
|
410
|
+
() => 'resolved',
|
|
411
|
+
() => 'rejected'
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
await vi.advanceTimersByTimeAsync(9_999)
|
|
415
|
+
expect(statusCalls(provider)).toBe(10)
|
|
416
|
+
await vi.advanceTimersByTimeAsync(1)
|
|
417
|
+
|
|
418
|
+
expect(await outcome).toBe('rejected')
|
|
419
|
+
expect(statusCalls(provider)).toBe(11)
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
it('treats an empty receipts array like a missing one', async () => {
|
|
423
|
+
const provider = batchProvider([
|
|
424
|
+
{ ...confirmedWithoutReceipts, receipts: [] }
|
|
425
|
+
])
|
|
426
|
+
|
|
427
|
+
const { error } = (await settle(provider)) as { error: unknown }
|
|
428
|
+
|
|
429
|
+
expect(error).toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
430
|
+
expect(error).toMatchObject({ batchId: BATCH_ID, chainId: '0xa4b1' })
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
it('reports a confirmed batch without receipt when a re-read fails', async () => {
|
|
434
|
+
const provider = batchProvider([
|
|
435
|
+
confirmedWithoutReceipts,
|
|
436
|
+
new Error('Internal JSON-RPC error')
|
|
437
|
+
])
|
|
438
|
+
|
|
439
|
+
const { error } = (await settle(provider)) as { error: unknown }
|
|
440
|
+
|
|
441
|
+
expect(error).toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
442
|
+
})
|
|
443
|
+
|
|
444
|
+
it.each([400, 500])(
|
|
445
|
+
'throws "Batch transaction failed" for status %i without re-reading',
|
|
446
|
+
async status => {
|
|
447
|
+
const provider = batchProvider([
|
|
448
|
+
{ ...confirmedWithoutReceipts, status }
|
|
449
|
+
])
|
|
450
|
+
|
|
451
|
+
const { error } = (await settle(provider)) as { error: unknown }
|
|
452
|
+
|
|
453
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
454
|
+
expect(error).not.toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
455
|
+
expect((error as Error).message).toBe('Batch transaction failed')
|
|
456
|
+
expect(statusCalls(provider)).toBe(1)
|
|
457
|
+
}
|
|
458
|
+
)
|
|
459
|
+
|
|
460
|
+
it('keeps polling while the batch is pending (status 100)', async () => {
|
|
461
|
+
const provider = batchProvider([
|
|
462
|
+
{ ...confirmedWithoutReceipts, status: 100 },
|
|
463
|
+
confirmedWithReceipts
|
|
464
|
+
])
|
|
465
|
+
|
|
466
|
+
expect(await settle(provider)).toEqual({ hash: TX_HASH })
|
|
467
|
+
expect(statusCalls(provider)).toBe(2)
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
it('retries "No matching bundle found" until the batch is known', async () => {
|
|
471
|
+
const provider = batchProvider([
|
|
472
|
+
new Error('No matching bundle found'),
|
|
473
|
+
new Error('No matching bundle found'),
|
|
474
|
+
confirmedWithReceipts
|
|
475
|
+
])
|
|
476
|
+
|
|
477
|
+
expect(await settle(provider)).toEqual({ hash: TX_HASH })
|
|
478
|
+
expect(statusCalls(provider)).toBe(3)
|
|
479
|
+
})
|
|
480
|
+
|
|
481
|
+
it('fails immediately on any other status-read error', async () => {
|
|
482
|
+
const provider = batchProvider([new Error('Unsupported method')])
|
|
483
|
+
|
|
484
|
+
const { error } = (await settle(provider)) as { error: unknown }
|
|
485
|
+
|
|
486
|
+
expect(error).toBeInstanceOf(WalletConnectorError)
|
|
487
|
+
expect(error).not.toBeInstanceOf(BatchConfirmedWithoutReceiptError)
|
|
488
|
+
expect((error as Error).message).toContain('Unsupported method')
|
|
489
|
+
})
|
|
490
|
+
})
|
|
274
491
|
})
|
|
@@ -8,9 +8,17 @@ import type {
|
|
|
8
8
|
EthereumTransactionRequest,
|
|
9
9
|
EVMDataTransferRequest
|
|
10
10
|
} from '@meshconnect/uwc-types'
|
|
11
|
+
import { BatchConfirmedWithoutReceiptError } from '@meshconnect/uwc-types'
|
|
11
12
|
import { parseError } from '../../utils/error-utils'
|
|
12
13
|
import { EthereumTransactionBuilder } from './ethereum-transaction-builder'
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* How long a confirmed (200) batch without receipts is re-read before giving up.
|
|
17
|
+
* EIP-5792 makes receipts optional; a wallet may still add them on a later read.
|
|
18
|
+
*/
|
|
19
|
+
const RECEIPT_POLL_INTERVAL_MS = 1000
|
|
20
|
+
const RECEIPT_POLL_ATTEMPTS = 10
|
|
21
|
+
|
|
14
22
|
/**
|
|
15
23
|
* Service for handling Ethereum/EVM transaction operations
|
|
16
24
|
*/
|
|
@@ -246,19 +254,21 @@ export class EthereumTransactionService {
|
|
|
246
254
|
// Poll for completion with retry logic for specific errors
|
|
247
255
|
const sleep = (ms: number) =>
|
|
248
256
|
new Promise(resolve => setTimeout(resolve, ms))
|
|
257
|
+
const getCallsStatus = () =>
|
|
258
|
+
(
|
|
259
|
+
client.request as (args: {
|
|
260
|
+
method: string
|
|
261
|
+
params: unknown[]
|
|
262
|
+
}) => Promise<BatchTransactionResult>
|
|
263
|
+
)({
|
|
264
|
+
method: 'wallet_getCallsStatus',
|
|
265
|
+
params: [response.id]
|
|
266
|
+
})
|
|
249
267
|
let result: BatchTransactionResult | undefined
|
|
250
268
|
|
|
251
269
|
while (true) {
|
|
252
270
|
try {
|
|
253
|
-
result = await (
|
|
254
|
-
client.request as (args: {
|
|
255
|
-
method: string
|
|
256
|
-
params: unknown[]
|
|
257
|
-
}) => Promise<BatchTransactionResult>
|
|
258
|
-
)({
|
|
259
|
-
method: 'wallet_getCallsStatus',
|
|
260
|
-
params: [response.id]
|
|
261
|
-
})
|
|
271
|
+
result = await getCallsStatus()
|
|
262
272
|
|
|
263
273
|
// Wait 1 second if still pending
|
|
264
274
|
if (result?.status === 100) {
|
|
@@ -287,10 +297,29 @@ export class EthereumTransactionService {
|
|
|
287
297
|
throw new Error('Batch transaction failed')
|
|
288
298
|
}
|
|
289
299
|
|
|
290
|
-
// Return first transaction hash
|
|
291
|
-
|
|
300
|
+
// Return first transaction hash. A confirmed batch may come without
|
|
301
|
+
// receipts (optional in EIP-5792): re-read for a while in case the wallet
|
|
302
|
+
// adds them, and only then report it as confirmed-without-receipt.
|
|
303
|
+
let firstReceipt = result.receipts?.find(r => r)
|
|
304
|
+
for (
|
|
305
|
+
let attempt = 0;
|
|
306
|
+
!firstReceipt && attempt < RECEIPT_POLL_ATTEMPTS;
|
|
307
|
+
attempt++
|
|
308
|
+
) {
|
|
309
|
+
await sleep(RECEIPT_POLL_INTERVAL_MS)
|
|
310
|
+
try {
|
|
311
|
+
firstReceipt = (await getCallsStatus())?.receipts?.find(r => r)
|
|
312
|
+
} catch {
|
|
313
|
+
// The batch is already confirmed; a failed re-read must not turn it
|
|
314
|
+
// into a failure. Stop and report it without a receipt.
|
|
315
|
+
break
|
|
316
|
+
}
|
|
317
|
+
}
|
|
292
318
|
if (!firstReceipt) {
|
|
293
|
-
throw new
|
|
319
|
+
throw new BatchConfirmedWithoutReceiptError(
|
|
320
|
+
response.id,
|
|
321
|
+
request.chainId
|
|
322
|
+
)
|
|
294
323
|
}
|
|
295
324
|
|
|
296
325
|
return firstReceipt.transactionHash
|