@@ -208,12 +208,16 @@ pub fn add_mapping(
208208 let hdr = load :: < CommandHeader > ( instruction_data) ?;
209209 let mut cur_mapping = load_checked :: < MappingAccount > ( cur_mapping, hdr. version ) ?;
210210 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 ) ,
212213 ProgramError :: InvalidArgument ,
213214 ) ?;
214215
215216 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+ ) ;
217221
218222 Ok ( ( ) )
219223}
@@ -363,11 +367,17 @@ pub fn add_price(
363367
364368 let mut price_data =
365369 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 ;
370+ price_data. exponent = cmd_args. exponent ;
371+ price_data. price_type = cmd_args. price_type ;
368372 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 ( ) ) ;
373+ pubkey_assign (
374+ & mut price_data. next_ ,
375+ bytes_of ( & product_data. first_price_account ) ,
376+ ) ;
377+ pubkey_assign (
378+ & mut product_data. first_price_account ,
379+ & price_account. key . to_bytes ( ) ,
380+ ) ;
371381
372382 Ok ( ( ) )
373383}
@@ -398,7 +408,10 @@ pub fn del_price(
398408 let mut product_data = load_checked :: < ProductAccount > ( product_account, cmd_args. version ) ?;
399409 let price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. version ) ?;
400410 pyth_assert (
401- pubkey_equal ( & product_data. px_acc_ , & price_account. key . to_bytes ( ) ) ,
411+ pubkey_equal (
412+ & product_data. first_price_account ,
413+ & price_account. key . to_bytes ( ) ,
414+ ) ,
402415 ProgramError :: InvalidArgument ,
403416 ) ?;
404417
@@ -407,7 +420,10 @@ pub fn del_price(
407420 ProgramError :: InvalidArgument ,
408421 ) ?;
409422
410- pubkey_assign ( & mut product_data. px_acc_ , bytes_of ( & price_data. next_ ) ) ;
423+ pubkey_assign (
424+ & mut product_data. first_price_account ,
425+ bytes_of ( & price_data. next_ ) ,
426+ ) ;
411427 }
412428
413429 // Zero out the balance of the price account to delete it.
@@ -439,11 +455,11 @@ pub fn init_price(
439455
440456 let mut price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
441457 pyth_assert (
442- price_data. ptype_ == cmd_args. price_type ,
458+ price_data. price_type == cmd_args. price_type ,
443459 ProgramError :: InvalidArgument ,
444460 ) ?;
445461
446- price_data. expo_ = cmd_args. exponent ;
462+ price_data. exponent = cmd_args. exponent ;
447463
448464 price_data. last_slot_ = 0 ;
449465 price_data. valid_slot_ = 0 ;
@@ -530,7 +546,7 @@ pub fn add_publisher(
530546 bytes_of ( & cmd_args. publisher ) ,
531547 ) ;
532548 price_data. num_ += 1 ;
533- price_data. size_ =
549+ price_data. header . size =
534550 try_convert :: < _ , u32 > ( size_of :: < PriceAccount > ( ) - size_of_val ( & price_data. comp_ ) ) ?
535551 + price_data. num_ * try_convert :: < _ , u32 > ( size_of :: < PriceComponent > ( ) ) ?;
536552 Ok ( ( ) )
@@ -574,7 +590,7 @@ pub fn del_publisher(
574590 0 ,
575591 size_of :: < PriceComponent > ( ) ,
576592 ) ;
577- price_data. size_ =
593+ price_data. header . size =
578594 try_convert :: < _ , u32 > ( size_of :: < PriceAccount > ( ) - size_of_val ( & price_data. comp_ ) ) ?
579595 + price_data. num_ * try_convert :: < _ , u32 > ( size_of :: < PriceComponent > ( ) ) ?;
580596 return Ok ( ( ) ) ;
@@ -606,21 +622,22 @@ pub fn add_product(
606622 let mut mapping_data = load_checked :: < MappingAccount > ( tail_mapping_account, hdr. version ) ?;
607623 // The mapping account must have free space to add the product account
608624 pyth_assert (
609- mapping_data. num_ < PC_MAP_TABLE_SIZE ,
625+ mapping_data. number_of_products < PC_MAP_TABLE_SIZE ,
610626 ProgramError :: InvalidArgument ,
611627 ) ?;
612628
613629 initialize_pyth_account_checked :: < ProductAccount > ( new_product_account, hdr. version ) ?;
614630
615- let current_index: usize = try_convert ( mapping_data. num_ ) ?;
631+ let current_index: usize = try_convert ( mapping_data. number_of_products ) ?;
616632 pubkey_assign (
617- & mut mapping_data. prod_ [ current_index] ,
633+ & mut mapping_data. products_list [ current_index] ,
618634 bytes_of ( & new_product_account. key . to_bytes ( ) ) ,
619635 ) ;
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 > ( ) ) ?;
636+ mapping_data. number_of_products += 1 ;
637+ mapping_data. header . size = try_convert :: < _ , u32 > (
638+ size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
639+ ) ? + mapping_data. number_of_products
640+ * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
624641
625642 Ok ( ( ) )
626643}
@@ -680,7 +697,7 @@ pub fn upd_product(
680697 }
681698
682699 let mut product_data = load_checked :: < ProductAccount > ( product_account, hdr. version ) ?;
683- product_data. size_ = try_convert ( size_of :: < ProductAccount > ( ) + new_data. len ( ) ) ?;
700+ product_data. header . size = try_convert ( size_of :: < ProductAccount > ( ) + new_data. len ( ) ) ?;
684701
685702 Ok ( ( ) )
686703}
@@ -738,36 +755,40 @@ pub fn del_product(
738755 let product_data = load_checked :: < ProductAccount > ( product_account, cmd_args. version ) ?;
739756
740757 // This assertion is just to make the subtractions below simpler
741- pyth_assert ( mapping_data. num_ >= 1 , ProgramError :: InvalidArgument ) ?;
742758 pyth_assert (
743- pubkey_is_zero ( & product_data. px_acc_ ) ,
759+ mapping_data. number_of_products >= 1 ,
760+ ProgramError :: InvalidArgument ,
761+ ) ?;
762+ pyth_assert (
763+ pubkey_is_zero ( & product_data. first_price_account ) ,
744764 ProgramError :: InvalidArgument ,
745765 ) ?;
746766
747767 let product_key = product_account. key . to_bytes ( ) ;
748768 let product_index = mapping_data
749- . prod_
769+ . products_list
750770 . iter ( )
751771 . position ( |x| pubkey_equal ( x, & product_key) )
752772 . ok_or ( ProgramError :: InvalidArgument ) ?;
753773
754774 let num_after_removal: usize = try_convert (
755775 mapping_data
756- . num_
776+ . number_of_products
757777 . checked_sub ( 1 )
758778 . ok_or ( ProgramError :: InvalidArgument ) ?,
759779 ) ?;
760780
761- let last_key_bytes = mapping_data. prod_ [ num_after_removal] ;
781+ let last_key_bytes = mapping_data. products_list [ num_after_removal] ;
762782 pubkey_assign (
763- & mut mapping_data. prod_ [ product_index] ,
783+ & mut mapping_data. products_list [ product_index] ,
764784 bytes_of ( & last_key_bytes) ,
765785 ) ;
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 > ( ) ) ?;
786+ pubkey_clear ( & mut mapping_data. products_list [ num_after_removal] ) ;
787+ mapping_data. number_of_products = try_convert :: < _ , u32 > ( num_after_removal) ?;
788+ mapping_data. header . size = try_convert :: < _ , u32 > (
789+ size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
790+ ) ? + mapping_data. number_of_products
791+ * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
771792 }
772793
773794 // Zero out the balance of the price account to delete it.
0 commit comments