@@ -208,12 +208,16 @@ pub fn add_mapping(
208
208
let hdr = load :: < CommandHeader > ( instruction_data) ?;
209
209
let mut cur_mapping = load_checked :: < MappingAccount > ( cur_mapping, hdr. version ) ?;
210
210
pyth_assert (
211
- cur_mapping. num_ == PC_MAP_TABLE_SIZE && pubkey_is_zero ( & cur_mapping. next_ ) ,
211
+ cur_mapping. number_of_products == PC_MAP_TABLE_SIZE
212
+ && pubkey_is_zero ( & cur_mapping. next_mapping_account ) ,
212
213
ProgramError :: InvalidArgument ,
213
214
) ?;
214
215
215
216
initialize_pyth_account_checked :: < MappingAccount > ( next_mapping, hdr. version ) ?;
216
- pubkey_assign ( & mut cur_mapping. next_ , & next_mapping. key . to_bytes ( ) ) ;
217
+ pubkey_assign (
218
+ & mut cur_mapping. next_mapping_account ,
219
+ & next_mapping. key . to_bytes ( ) ,
220
+ ) ;
217
221
218
222
Ok ( ( ) )
219
223
}
@@ -363,11 +367,20 @@ pub fn add_price(
363
367
364
368
let mut price_data =
365
369
initialize_pyth_account_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
366
- price_data. expo_ = cmd_args. exponent ;
367
- price_data. ptype_ = cmd_args. price_type ;
368
- pubkey_assign ( & mut price_data. prod_ , & product_account. key . to_bytes ( ) ) ;
369
- pubkey_assign ( & mut price_data. next_ , bytes_of ( & product_data. px_acc_ ) ) ;
370
- pubkey_assign ( & mut product_data. px_acc_ , & price_account. key . to_bytes ( ) ) ;
370
+ price_data. exponent = cmd_args. exponent ;
371
+ price_data. price_type = cmd_args. price_type ;
372
+ pubkey_assign (
373
+ & mut price_data. product_account ,
374
+ & product_account. key . to_bytes ( ) ,
375
+ ) ;
376
+ pubkey_assign (
377
+ & mut price_data. next_price_account ,
378
+ bytes_of ( & product_data. first_price_account ) ,
379
+ ) ;
380
+ pubkey_assign (
381
+ & mut product_data. first_price_account ,
382
+ & price_account. key . to_bytes ( ) ,
383
+ ) ;
371
384
372
385
Ok ( ( ) )
373
386
}
@@ -398,16 +411,22 @@ pub fn del_price(
398
411
let mut product_data = load_checked :: < ProductAccount > ( product_account, cmd_args. version ) ?;
399
412
let price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. version ) ?;
400
413
pyth_assert (
401
- pubkey_equal ( & product_data. px_acc_ , & price_account. key . to_bytes ( ) ) ,
414
+ pubkey_equal (
415
+ & product_data. first_price_account ,
416
+ & price_account. key . to_bytes ( ) ,
417
+ ) ,
402
418
ProgramError :: InvalidArgument ,
403
419
) ?;
404
420
405
421
pyth_assert (
406
- pubkey_equal ( & price_data. prod_ , & product_account. key . to_bytes ( ) ) ,
422
+ pubkey_equal ( & price_data. product_account , & product_account. key . to_bytes ( ) ) ,
407
423
ProgramError :: InvalidArgument ,
408
424
) ?;
409
425
410
- pubkey_assign ( & mut product_data. px_acc_ , bytes_of ( & price_data. next_ ) ) ;
426
+ pubkey_assign (
427
+ & mut product_data. first_price_account ,
428
+ bytes_of ( & price_data. next_price_account ) ,
429
+ ) ;
411
430
}
412
431
413
432
// Zero out the balance of the price account to delete it.
@@ -439,11 +458,11 @@ pub fn init_price(
439
458
440
459
let mut price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
441
460
pyth_assert (
442
- price_data. ptype_ == cmd_args. price_type ,
461
+ price_data. price_type == cmd_args. price_type ,
443
462
ProgramError :: InvalidArgument ,
444
463
) ?;
445
464
446
- price_data. expo_ = cmd_args. exponent ;
465
+ price_data. exponent = cmd_args. exponent ;
447
466
448
467
price_data. last_slot_ = 0 ;
449
468
price_data. valid_slot_ = 0 ;
@@ -530,7 +549,7 @@ pub fn add_publisher(
530
549
bytes_of ( & cmd_args. publisher ) ,
531
550
) ;
532
551
price_data. num_ += 1 ;
533
- price_data. size_ =
552
+ price_data. header . size =
534
553
try_convert :: < _ , u32 > ( size_of :: < PriceAccount > ( ) - size_of_val ( & price_data. comp_ ) ) ?
535
554
+ price_data. num_ * try_convert :: < _ , u32 > ( size_of :: < PriceComponent > ( ) ) ?;
536
555
Ok ( ( ) )
@@ -574,7 +593,7 @@ pub fn del_publisher(
574
593
0 ,
575
594
size_of :: < PriceComponent > ( ) ,
576
595
) ;
577
- price_data. size_ =
596
+ price_data. header . size =
578
597
try_convert :: < _ , u32 > ( size_of :: < PriceAccount > ( ) - size_of_val ( & price_data. comp_ ) ) ?
579
598
+ price_data. num_ * try_convert :: < _ , u32 > ( size_of :: < PriceComponent > ( ) ) ?;
580
599
return Ok ( ( ) ) ;
@@ -606,21 +625,22 @@ pub fn add_product(
606
625
let mut mapping_data = load_checked :: < MappingAccount > ( tail_mapping_account, hdr. version ) ?;
607
626
// The mapping account must have free space to add the product account
608
627
pyth_assert (
609
- mapping_data. num_ < PC_MAP_TABLE_SIZE ,
628
+ mapping_data. number_of_products < PC_MAP_TABLE_SIZE ,
610
629
ProgramError :: InvalidArgument ,
611
630
) ?;
612
631
613
632
initialize_pyth_account_checked :: < ProductAccount > ( new_product_account, hdr. version ) ?;
614
633
615
- let current_index: usize = try_convert ( mapping_data. num_ ) ?;
634
+ let current_index: usize = try_convert ( mapping_data. number_of_products ) ?;
616
635
pubkey_assign (
617
- & mut mapping_data. prod_ [ current_index] ,
636
+ & mut mapping_data. products_list [ current_index] ,
618
637
bytes_of ( & new_product_account. key . to_bytes ( ) ) ,
619
638
) ;
620
- mapping_data. num_ += 1 ;
621
- mapping_data. size_ =
622
- try_convert :: < _ , u32 > ( size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. prod_ ) ) ?
623
- + mapping_data. num_ * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
639
+ mapping_data. number_of_products += 1 ;
640
+ mapping_data. header . size = try_convert :: < _ , u32 > (
641
+ size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
642
+ ) ? + mapping_data. number_of_products
643
+ * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
624
644
625
645
Ok ( ( ) )
626
646
}
@@ -680,7 +700,7 @@ pub fn upd_product(
680
700
}
681
701
682
702
let mut product_data = load_checked :: < ProductAccount > ( product_account, hdr. version ) ?;
683
- product_data. size_ = try_convert ( size_of :: < ProductAccount > ( ) + new_data. len ( ) ) ?;
703
+ product_data. header . size = try_convert ( size_of :: < ProductAccount > ( ) + new_data. len ( ) ) ?;
684
704
685
705
Ok ( ( ) )
686
706
}
@@ -738,36 +758,40 @@ pub fn del_product(
738
758
let product_data = load_checked :: < ProductAccount > ( product_account, cmd_args. version ) ?;
739
759
740
760
// This assertion is just to make the subtractions below simpler
741
- pyth_assert ( mapping_data. num_ >= 1 , ProgramError :: InvalidArgument ) ?;
742
761
pyth_assert (
743
- pubkey_is_zero ( & product_data. px_acc_ ) ,
762
+ mapping_data. number_of_products >= 1 ,
763
+ ProgramError :: InvalidArgument ,
764
+ ) ?;
765
+ pyth_assert (
766
+ pubkey_is_zero ( & product_data. first_price_account ) ,
744
767
ProgramError :: InvalidArgument ,
745
768
) ?;
746
769
747
770
let product_key = product_account. key . to_bytes ( ) ;
748
771
let product_index = mapping_data
749
- . prod_
772
+ . products_list
750
773
. iter ( )
751
774
. position ( |x| pubkey_equal ( x, & product_key) )
752
775
. ok_or ( ProgramError :: InvalidArgument ) ?;
753
776
754
777
let num_after_removal: usize = try_convert (
755
778
mapping_data
756
- . num_
779
+ . number_of_products
757
780
. checked_sub ( 1 )
758
781
. ok_or ( ProgramError :: InvalidArgument ) ?,
759
782
) ?;
760
783
761
- let last_key_bytes = mapping_data. prod_ [ num_after_removal] ;
784
+ let last_key_bytes = mapping_data. products_list [ num_after_removal] ;
762
785
pubkey_assign (
763
- & mut mapping_data. prod_ [ product_index] ,
786
+ & mut mapping_data. products_list [ product_index] ,
764
787
bytes_of ( & last_key_bytes) ,
765
788
) ;
766
- pubkey_clear ( & mut mapping_data. prod_ [ num_after_removal] ) ;
767
- mapping_data. num_ = try_convert :: < _ , u32 > ( num_after_removal) ?;
768
- mapping_data. size_ =
769
- try_convert :: < _ , u32 > ( size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. prod_ ) ) ?
770
- + mapping_data. num_ * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
789
+ pubkey_clear ( & mut mapping_data. products_list [ num_after_removal] ) ;
790
+ mapping_data. number_of_products = try_convert :: < _ , u32 > ( num_after_removal) ?;
791
+ mapping_data. header . size = try_convert :: < _ , u32 > (
792
+ size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
793
+ ) ? + mapping_data. number_of_products
794
+ * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
771
795
}
772
796
773
797
// Zero out the balance of the price account to delete it.
0 commit comments