From 1ea7f139a4e880f159ee8ec54e46ffa08e94fd6a Mon Sep 17 00:00:00 2001 From: Ben Guidarelli Date: Thu, 26 Oct 2023 16:03:16 -0400 Subject: [PATCH] prepend vaa since we're receiving them in reverse order --- watcher/src/watchers/SolanaWatcher.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/watcher/src/watchers/SolanaWatcher.ts b/watcher/src/watchers/SolanaWatcher.ts index 186be0b7..0dacc8d0 100644 --- a/watcher/src/watchers/SolanaWatcher.ts +++ b/watcher/src/watchers/SolanaWatcher.ts @@ -206,6 +206,12 @@ export class SolanaWatcher extends Watcher { .concat(instructions) .filter((i) => i.programIdIndex === programIdIndex); + const blockKey = makeBlockKey( + res.slot.toString(), + new Date(res.blockTime * 1000).toISOString() + ); + + const vaaKeys: string[] = []; for (const instruction of whInstructions) { // skip if not postMessage instruction const instructionId = instruction.data; @@ -216,20 +222,17 @@ export class SolanaWatcher extends Watcher { message: { emitterAddress, sequence }, } = await getPostedMessage(this.getConnection(), accountId.toBase58(), COMMITMENT); - const blockKey = makeBlockKey( - res.slot.toString(), - new Date(res.blockTime * 1000).toISOString() - ); - - const vaaKey = makeVaaKey( - res.transaction.signatures[0], - this.chain, - emitterAddress.toString('hex'), - sequence.toString() + vaaKeys.push( + makeVaaKey( + res.transaction.signatures[0], + this.chain, + emitterAddress.toString('hex'), + sequence.toString() + ) ); - - vaasByBlock[blockKey] = [...(vaasByBlock[blockKey] || []), vaaKey]; } + if (vaaKeys.length > 0) + vaasByBlock[blockKey] = [...vaaKeys, ...(vaasByBlock[blockKey] || [])]; } numSignatures = signatures.length;