@@ -52,14 +52,10 @@ type InternalField struct {
52
52
Location string
53
53
}
54
54
55
- type ValueLookup struct {
56
- Location string
57
- }
58
-
59
55
// LookupTables represents a list of lookup tables that are used to derive addresses for a program.
60
56
type LookupTables struct {
61
57
DerivedLookupTables []DerivedLookupTable
62
- StaticLookupTables []string
58
+ StaticLookupTables []solana. PublicKey
63
59
}
64
60
65
61
// DerivedLookupTable represents a lookup table that is used to derive addresses for a program.
@@ -212,19 +208,18 @@ func decodeBorshIntoType(data []byte, typ reflect.Type) (interface{}, error) {
212
208
// It handles both AddressSeeds (which are public keys) and ValueSeeds (which are byte arrays from input args).
213
209
func getSeedBytes (ctx context.Context , lookup PDALookups , args any , derivedTableMap map [string ]map [string ][]* solana.AccountMeta , reader client.Reader ) ([][]byte , error ) {
214
210
var seedBytes [][]byte
215
- maxSeedLength := 32
216
211
217
212
for _ , seed := range lookup .Seeds {
218
213
if lookupSeed , ok := seed .(AccountLookup ); ok {
219
- // Get value from a location (This doens 't have to be an address, it can be any value)
214
+ // Get value from a location (This doesn 't have to be an address, it can be any value)
220
215
bytes , err := GetValuesAtLocation (args , lookupSeed .Location )
221
216
if err != nil {
222
217
return nil , fmt .Errorf ("error getting address seed: %w" , err )
223
218
}
224
219
// validate seed length
225
220
for _ , b := range bytes {
226
- if len (b ) > maxSeedLength {
227
- return nil , fmt .Errorf ("seed byte array exceeds maximum length of %d: got %d bytes" , maxSeedLength , len (b ))
221
+ if len (b ) > solana . MaxSeedLength {
222
+ return nil , fmt .Errorf ("seed byte array exceeds maximum length of %d: got %d bytes" , solana . MaxSeedLength , len (b ))
228
223
}
229
224
seedBytes = append (seedBytes , b )
230
225
}
@@ -247,7 +242,7 @@ func getSeedBytes(ctx context.Context, lookup PDALookups, args any, derivedTable
247
242
248
243
// generatePDAs generates program-derived addresses (PDAs) from public keys and seeds.
249
244
func generatePDAs (publicKeys []* solana.AccountMeta , seeds [][]byte , lookup PDALookups ) ([]* solana.AccountMeta , error ) {
250
- if len (seeds ) > 16 {
245
+ if len (seeds ) > solana . MaxSeeds {
251
246
return nil , fmt .Errorf ("seed maximum exceeded: %d" , len (seeds ))
252
247
}
253
248
var addresses []* solana.AccountMeta
@@ -271,6 +266,8 @@ func (s *SolanaChainWriterService) ResolveLookupTables(ctx context.Context, args
271
266
272
267
// Read derived lookup tables
273
268
for _ , derivedLookup := range lookupTables .DerivedLookupTables {
269
+ // Load the lookup table - note: This could be multiple tables if the lookup is a PDALookups that resovles to more
270
+ // than one address
274
271
lookupTableMap , _ , err := s .LoadTable (ctx , args , derivedLookup , s .reader , derivedTableMap )
275
272
if err != nil {
276
273
return nil , nil , fmt .Errorf ("error loading derived lookup table: %w" , err )
@@ -289,17 +286,11 @@ func (s *SolanaChainWriterService) ResolveLookupTables(ctx context.Context, args
289
286
290
287
// Read static lookup tables
291
288
for _ , staticTable := range lookupTables .StaticLookupTables {
292
- // Parse the static table address
293
- tableAddress , err := solana .PublicKeyFromBase58 (staticTable )
294
- if err != nil {
295
- return nil , nil , fmt .Errorf ("invalid static lookup table address: %s, error: %w" , staticTable , err )
296
- }
297
-
298
- addressses , err := getLookupTableAddresses (ctx , s .reader , tableAddress )
289
+ addressses , err := getLookupTableAddresses (ctx , s .reader , staticTable )
299
290
if err != nil {
300
291
return nil , nil , fmt .Errorf ("error fetching static lookup table address: %w" , err )
301
292
}
302
- staticTableMap [tableAddress ] = addressses
293
+ staticTableMap [staticTable ] = addressses
303
294
}
304
295
305
296
return derivedTableMap , staticTableMap , nil
@@ -312,15 +303,16 @@ func (s *SolanaChainWriterService) LoadTable(ctx context.Context, args any, rlt
312
303
return nil , nil , fmt .Errorf ("error resolving addresses for lookup table: %w" , err )
313
304
}
314
305
306
+ // Nested map in case the lookup table resolves to multiple addresses
315
307
resultMap := make (map [string ]map [string ][]* solana.AccountMeta )
316
308
var lookupTableMetas []* solana.AccountMeta
317
309
318
310
// Iterate over each address of the lookup table
319
311
for _ , addressMeta := range lookupTableAddresses {
320
- // Fetch account info
312
+ // Read the full list of addresses from the lookup table
321
313
addresses , err := getLookupTableAddresses (ctx , reader , addressMeta .PublicKey )
322
314
if err != nil {
323
- return nil , nil , fmt .Errorf ("error fetching lookup table address: %w" , err )
315
+ return nil , nil , fmt .Errorf ("error fetching lookup table address: %s, error: %w" , addressMeta . PublicKey , err )
324
316
}
325
317
326
318
// Create the inner map for this lookup table
0 commit comments