5
5
PublicKey ,
6
6
SolanaJSONRPCError ,
7
7
VersionedBlockResponse ,
8
+ VersionedMessage ,
8
9
} from '@solana/web3.js' ;
9
10
import { decode } from 'bs58' ;
10
11
import { z } from 'zod' ;
@@ -13,13 +14,13 @@ import { VaasByBlock } from '../databases/types';
13
14
import { makeBlockKey , makeVaaKey } from '../databases/utils' ;
14
15
import {
15
16
Mode ,
16
- isLegacyMessage ,
17
17
normalizeCompileInstruction ,
18
18
universalAddress_stripped ,
19
19
} from '@wormhole-foundation/wormhole-monitor-common' ;
20
20
import { Watcher } from './Watcher' ;
21
21
import { Network , contracts } from '@wormhole-foundation/sdk-base' ;
22
22
import { deserializePostMessage } from '@wormhole-foundation/sdk-solana-core' ;
23
+ import { getAllKeys } from '../utils/solana' ;
23
24
24
25
const COMMITMENT : Commitment = 'finalized' ;
25
26
const GET_SIGNATURES_LIMIT = 1000 ;
@@ -159,50 +160,9 @@ export class SolanaWatcher extends Watcher {
159
160
) ;
160
161
}
161
162
162
- const message = res . transaction . message ;
163
- let accountKeys = isLegacyMessage ( message )
164
- ? message . accountKeys
165
- : message . staticAccountKeys ;
166
-
167
- // If the message contains an address table lookup, we need to resolve the addresses
168
- // before looking for the programIdIndex
169
- if ( message . addressTableLookups . length > 0 ) {
170
- const lookupPromises = message . addressTableLookups . map ( async ( atl ) => {
171
- const lookupTableAccount = await this . getConnection ( )
172
- . getAddressLookupTable ( atl . accountKey )
173
- . then ( ( res ) => res . value ) ;
174
-
175
- if ( ! lookupTableAccount )
176
- throw new Error ( 'lookupTableAccount is null, cant resolve addresses' ) ;
177
-
178
- // Important to return the addresses in the order they're specified in the
179
- // address table lookup object. Note writable comes first, then readable.
180
- return [
181
- atl . accountKey ,
182
- atl . writableIndexes . map ( ( i ) => lookupTableAccount . state . addresses [ i ] ) ,
183
- atl . readonlyIndexes . map ( ( i ) => lookupTableAccount . state . addresses [ i ] ) ,
184
- ] as [ PublicKey , PublicKey [ ] , PublicKey [ ] ] ;
185
- } ) ;
186
-
187
- // Lookup all addresses in parallel
188
- const lookups = await Promise . all ( lookupPromises ) ;
189
-
190
- // Ensure the order is maintained for lookups
191
- // Static, Writable, Readable
192
- // ref: https://github.com/gagliardetto/solana-go/blob/main/message.go#L414-L464
193
- const writable : PublicKey [ ] = [ ] ;
194
- const readable : PublicKey [ ] = [ ] ;
195
- for ( const atl of message . addressTableLookups ) {
196
- const table = lookups . find ( ( l ) => l [ 0 ] . equals ( atl . accountKey ) ) ;
197
- if ( ! table ) throw new Error ( 'Could not find address table lookup' ) ;
198
- writable . push ( ...table [ 1 ] ) ;
199
- readable . push ( ...table [ 2 ] ) ;
200
- }
201
-
202
- accountKeys . push ( ...writable . concat ( readable ) ) ;
203
- }
204
-
163
+ const accountKeys = await getAllKeys ( this . getConnection ( ) , res ) ;
205
164
const programIdIndex = accountKeys . findIndex ( ( i ) => i . toBase58 ( ) === this . programId ) ;
165
+ const message : VersionedMessage = res . transaction . message ;
206
166
const instructions = message . compiledInstructions ;
207
167
const innerInstructions =
208
168
res . meta ?. innerInstructions ?. flatMap ( ( i ) =>
0 commit comments