@@ -342,75 +342,78 @@ async def sync_mapping_instructions(
342
342
mapping_keypair_0 = load_keypair (
343
343
"mapping_0" , key_dir = self .key_dir , generate = generate_keys
344
344
)
345
- logger .debug (f"mapping_0 public key: { mapping_keypair_0 .public_key } " )
346
345
347
346
instructions : List [TransactionInstruction ] = []
348
347
349
- if not await account_exists (self .rpc_endpoint , mapping_keypair_0 .public_key ):
350
- logger .debug ("Building system.program.create_account instruction" )
351
- instructions .append (
352
- system_program .create_account (
353
- system_program .CreateAccountParams (
354
- from_pubkey = funding_keypair .public_key ,
355
- new_account_pubkey = mapping_keypair_0 .public_key ,
356
- # FIXME: Change to minimum rent-exempt amount
357
- lamports = await self .fetch_minimum_balance (MAPPING_ACCOUNT_SIZE ),
358
- space = MAPPING_ACCOUNT_SIZE ,
359
- program_id = self .program_key ,
360
- )
361
- )
362
- )
363
-
364
- logger .debug ("Building pyth_program.init_mapping instruction" )
365
- instructions .append (
366
- pyth_program .init_mapping (
367
- self .program_key ,
368
- funding_keypair .public_key ,
369
- mapping_keypair_0 .public_key ,
370
- )
371
- )
372
-
373
- mapping_keypairs : List [Keypair ] = []
374
- if num_mapping_accounts > 1 :
375
- mapping_keypairs : List [Keypair ] = [
376
- load_keypair (
377
- f"mapping_{ n } " , key_dir = self .key_dir , generate = generate_keys
378
- )
379
- for n in range (1 , num_mapping_accounts )
380
- ]
381
-
382
- tail_mapping_keypair = mapping_keypair_0
383
- for mapping_keypair in mapping_keypairs :
384
- if not (
385
- await account_exists (self .rpc_endpoint , mapping_keypair .public_key )
386
- ):
348
+ # Create initial mapping account
349
+ if len (self ._mapping_accounts ) < 1 :
350
+ if not await account_exists (self .rpc_endpoint , mapping_keypair_0 .public_key ):
387
351
logger .debug ("Building system.program.create_account instruction" )
388
352
instructions .append (
389
353
system_program .create_account (
390
354
system_program .CreateAccountParams (
391
355
from_pubkey = funding_keypair .public_key ,
392
- new_account_pubkey = mapping_keypair .public_key ,
356
+ new_account_pubkey = mapping_keypair_0 .public_key ,
393
357
# FIXME: Change to minimum rent-exempt amount
394
- lamports = await self .fetch_minimum_balance (
395
- MAPPING_ACCOUNT_SIZE
396
- ),
358
+ lamports = await self .fetch_minimum_balance (MAPPING_ACCOUNT_SIZE ),
397
359
space = MAPPING_ACCOUNT_SIZE ,
398
360
program_id = self .program_key ,
399
361
)
400
362
)
401
363
)
402
364
403
- logger .debug ("Building pyth_program.add_mapping instruction" )
365
+ logger .debug ("Building pyth_program.init_mapping instruction" )
404
366
instructions .append (
405
- pyth_program .add_mapping (
367
+ pyth_program .init_mapping (
406
368
self .program_key ,
407
369
funding_keypair .public_key ,
408
- tail_mapping_keypair .public_key ,
409
- mapping_keypair .public_key ,
370
+ mapping_keypair_0 .public_key ,
410
371
)
411
372
)
412
373
413
- tail_mapping_keypair = mapping_keypair
374
+ # Add extra mapping accounts
375
+ if len (self ._mapping_accounts ) < num_mapping_accounts :
376
+ mapping_keypairs : List [Keypair ] = []
377
+ if num_mapping_accounts > 1 :
378
+ mapping_keypairs : List [Keypair ] = [
379
+ load_keypair (
380
+ f"mapping_{ n } " , key_dir = self .key_dir , generate = generate_keys
381
+ )
382
+ for n in range (1 , num_mapping_accounts )
383
+ ]
384
+
385
+ tail_mapping_keypair = mapping_keypair_0
386
+ for mapping_keypair in mapping_keypairs :
387
+ if not (
388
+ await account_exists (self .rpc_endpoint , mapping_keypair .public_key )
389
+ ):
390
+ logger .debug ("Building system.program.create_account instruction" )
391
+ instructions .append (
392
+ system_program .create_account (
393
+ system_program .CreateAccountParams (
394
+ from_pubkey = funding_keypair .public_key ,
395
+ new_account_pubkey = mapping_keypair .public_key ,
396
+ # FIXME: Change to minimum rent-exempt amount
397
+ lamports = await self .fetch_minimum_balance (
398
+ MAPPING_ACCOUNT_SIZE
399
+ ),
400
+ space = MAPPING_ACCOUNT_SIZE ,
401
+ program_id = self .program_key ,
402
+ )
403
+ )
404
+ )
405
+
406
+ logger .debug ("Building pyth_program.add_mapping instruction" )
407
+ instructions .append (
408
+ pyth_program .add_mapping (
409
+ self .program_key ,
410
+ funding_keypair .public_key ,
411
+ tail_mapping_keypair .public_key ,
412
+ mapping_keypair .public_key ,
413
+ )
414
+ )
415
+
416
+ tail_mapping_keypair = mapping_keypair
414
417
415
418
return (instructions , [funding_keypair , mapping_keypair_0 ] + mapping_keypairs )
416
419
0 commit comments