@@ -347,14 +347,8 @@ ${chainID} chain does not yet know of address ${clientAddr}${adviseEgress(
347
347
// We want to subscribe.
348
348
method : 'subscribe' ,
349
349
params : {
350
- // Here is the Tendermint event for new blocks.
351
- // query: `tm.event = 'NewBlockHeader'`,
352
-
353
- // This is the Cosmos event for activityhash changes.
354
- // query: `storage.path = 'activityhash'`,
355
-
356
- // This is the Cosmos event for our mailbox changes.
357
- query : `storage.path = '${ mailboxPath } '` ,
350
+ // This is the minimal query for mailbox changes.
351
+ query : `tm.event = 'NewBlockHeader' AND storage.path = '${ mailboxPath } '` ,
358
352
} ,
359
353
} ;
360
354
// Send that message, and wait for the subscription.
@@ -363,7 +357,7 @@ ${chainID} chain does not yet know of address ${clientAddr}${adviseEgress(
363
357
// Poll to establish our initial mailbox.
364
358
const pollMailboxWhileFirstUpdate = async ( ) => {
365
359
if ( ! firstUpdate ) {
366
- // Already got the subscription .
360
+ // We're too late .
367
361
return ;
368
362
}
369
363
const mb = await getMailbox ( ) . then (
@@ -373,12 +367,12 @@ ${chainID} chain does not yet know of address ${clientAddr}${adviseEgress(
373
367
} ,
374
368
) ;
375
369
if ( ! firstUpdate ) {
376
- // Already got the subscription .
370
+ // We're too late .
377
371
return ;
378
372
}
379
- console . error ( 'got first mb' , mb ) ;
373
+ // console.error('got first mb', mb);
380
374
if ( mb !== undefined ) {
381
- // Found the first mailbox.
375
+ // Found the initial mailbox.
382
376
// console.error('Updating in pollMailboxWhileFirstUpdate');
383
377
updater . updateState ( mb ) ;
384
378
firstUpdate = false ;
@@ -412,6 +406,12 @@ ${chainID} chain does not yet know of address ${clientAddr}${adviseEgress(
412
406
return ;
413
407
}
414
408
409
+ if ( obj . error ) {
410
+ console . error ( `Error subscribing to events` , obj . error ) ;
411
+ ws . close ( ) ;
412
+ return ;
413
+ }
414
+
415
415
// It matches our subscription, so maybe notify.
416
416
const events = obj . result . events ;
417
417
if ( ! events ) {
@@ -420,18 +420,19 @@ ${chainID} chain does not yet know of address ${clientAddr}${adviseEgress(
420
420
const paths = events [ 'storage.path' ] ;
421
421
const values = events [ 'storage.value' ] ;
422
422
423
- // Find only the latest value.
424
- let latestValue ;
423
+ // Find only the latest value in the events .
424
+ let latestMailboxValue ;
425
425
paths . forEach ( ( key , i ) => {
426
426
if ( key === mailboxPath ) {
427
- latestValue = values [ i ] ;
427
+ latestMailboxValue = values [ i ] ;
428
428
}
429
429
} ) ;
430
- if ( latestValue === undefined ) {
430
+ if ( latestMailboxValue === undefined ) {
431
+ // No matching events found.
431
432
return ;
432
433
}
433
434
434
- const mb = JSON . parse ( latestValue ) ;
435
+ const mb = JSON . parse ( latestMailboxValue ) ;
435
436
436
437
// Update our notifier.
437
438
// console.error('Updating in ws.message');
0 commit comments