@@ -4,7 +4,6 @@ use std::mem::{
44} ;
55
66use crate :: c_oracle_header:: {
7- CPubkey ,
87 MappingAccount ,
98 PriceAccount ,
109 PriceComponent ,
@@ -40,19 +39,12 @@ use crate::utils::{
4039 check_valid_signable_account,
4140 check_valid_writable_account,
4241 is_component_update,
43- pubkey_assign,
44- pubkey_clear,
45- pubkey_equal,
46- pubkey_is_zero,
4742 pyth_assert,
4843 read_pc_str_t,
4944 try_convert,
5045} ;
5146use crate :: OracleError ;
52- use bytemuck:: {
53- bytes_of,
54- bytes_of_mut,
55- } ;
47+ use bytemuck:: bytes_of_mut;
5648use solana_program:: account_info:: AccountInfo ;
5749use solana_program:: clock:: Clock ;
5850use solana_program:: entrypoint:: ProgramResult ;
@@ -197,15 +189,12 @@ pub fn add_mapping(
197189 let mut cur_mapping = load_checked :: < MappingAccount > ( cur_mapping, hdr. version ) ?;
198190 pyth_assert (
199191 cur_mapping. number_of_products == PC_MAP_TABLE_SIZE
200- && pubkey_is_zero ( & cur_mapping. next_mapping_account ) ,
192+ && cur_mapping. next_mapping_account == Pubkey :: default ( ) ,
201193 ProgramError :: InvalidArgument ,
202194 ) ?;
203195
204196 initialize_pyth_account_checked :: < MappingAccount > ( next_mapping, hdr. version ) ?;
205- pubkey_assign (
206- & mut cur_mapping. next_mapping_account ,
207- & next_mapping. key . to_bytes ( ) ,
208- ) ;
197+ cur_mapping. next_mapping_account = * next_mapping. key ;
209198
210199 Ok ( ( ) )
211200}
@@ -240,10 +229,7 @@ pub fn upd_price(
240229
241230 // Verify that publisher is authorized
242231 while publisher_index < price_data. num_ as usize {
243- if pubkey_equal (
244- & price_data. comp_ [ publisher_index] . pub_ ,
245- & funding_account. key . to_bytes ( ) ,
246- ) {
232+ if price_data. comp_ [ publisher_index] . pub_ == * funding_account. key {
247233 break ;
248234 }
249235 publisher_index += 1 ;
@@ -357,18 +343,9 @@ pub fn add_price(
357343 initialize_pyth_account_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
358344 price_data. exponent = cmd_args. exponent ;
359345 price_data. price_type = cmd_args. price_type ;
360- pubkey_assign (
361- & mut price_data. product_account ,
362- & product_account. key . to_bytes ( ) ,
363- ) ;
364- pubkey_assign (
365- & mut price_data. next_price_account ,
366- bytes_of ( & product_data. first_price_account ) ,
367- ) ;
368- pubkey_assign (
369- & mut product_data. first_price_account ,
370- & price_account. key . to_bytes ( ) ,
371- ) ;
346+ price_data. product_account = * product_account. key ;
347+ price_data. next_price_account = product_data. first_price_account ;
348+ product_data. first_price_account = * price_account. key ;
372349
373350 Ok ( ( ) )
374351}
@@ -399,22 +376,16 @@ pub fn del_price(
399376 let mut product_data = load_checked :: < ProductAccount > ( product_account, cmd_args. version ) ?;
400377 let price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. version ) ?;
401378 pyth_assert (
402- pubkey_equal (
403- & product_data. first_price_account ,
404- & price_account. key . to_bytes ( ) ,
405- ) ,
379+ product_data. first_price_account == * price_account. key ,
406380 ProgramError :: InvalidArgument ,
407381 ) ?;
408382
409383 pyth_assert (
410- pubkey_equal ( & price_data. product_account , & product_account. key . to_bytes ( ) ) ,
384+ price_data. product_account == * product_account. key ,
411385 ProgramError :: InvalidArgument ,
412386 ) ?;
413387
414- pubkey_assign (
415- & mut product_data. first_price_account ,
416- bytes_of ( & price_data. next_price_account ) ,
417- ) ;
388+ product_data. first_price_account = price_data. next_price_account ;
418389 }
419390
420391 // Zero out the balance of the price account to delete it.
@@ -502,7 +473,7 @@ pub fn add_publisher(
502473
503474 pyth_assert (
504475 instruction_data. len ( ) == size_of :: < AddPublisherArgs > ( )
505- && ! pubkey_is_zero ( & cmd_args. publisher ) ,
476+ && cmd_args. publisher != Pubkey :: default ( ) ,
506477 ProgramError :: InvalidArgument ,
507478 ) ?;
508479
@@ -521,7 +492,7 @@ pub fn add_publisher(
521492 }
522493
523494 for i in 0 ..( price_data. num_ as usize ) {
524- if pubkey_equal ( & cmd_args. publisher , bytes_of ( & price_data. comp_ [ i] . pub_ ) ) {
495+ if cmd_args. publisher == price_data. comp_ [ i] . pub_ {
525496 return Err ( ProgramError :: InvalidArgument ) ;
526497 }
527498 }
@@ -532,10 +503,7 @@ pub fn add_publisher(
532503 0 ,
533504 size_of :: < PriceComponent > ( ) ,
534505 ) ;
535- pubkey_assign (
536- & mut price_data. comp_ [ current_index] . pub_ ,
537- bytes_of ( & cmd_args. publisher ) ,
538- ) ;
506+ price_data. comp_ [ current_index] . pub_ = cmd_args. publisher ;
539507 price_data. num_ += 1 ;
540508 price_data. header . size =
541509 try_convert :: < _ , u32 > ( size_of :: < PriceAccount > ( ) - size_of_val ( & price_data. comp_ ) ) ?
@@ -555,7 +523,7 @@ pub fn del_publisher(
555523
556524 pyth_assert (
557525 instruction_data. len ( ) == size_of :: < DelPublisherArgs > ( )
558- && ! pubkey_is_zero ( & cmd_args. publisher ) ,
526+ && cmd_args. publisher != Pubkey :: default ( ) ,
559527 ProgramError :: InvalidArgument ,
560528 ) ?;
561529
@@ -570,7 +538,7 @@ pub fn del_publisher(
570538 let mut price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
571539
572540 for i in 0 ..( price_data. num_ as usize ) {
573- if pubkey_equal ( & cmd_args. publisher , bytes_of ( & price_data. comp_ [ i] . pub_ ) ) {
541+ if cmd_args. publisher == price_data. comp_ [ i] . pub_ {
574542 for j in i + 1 ..( price_data. num_ as usize ) {
575543 price_data. comp_ [ j - 1 ] = price_data. comp_ [ j] ;
576544 }
@@ -615,15 +583,12 @@ pub fn add_product(
615583 initialize_pyth_account_checked :: < ProductAccount > ( new_product_account, hdr. version ) ?;
616584
617585 let current_index: usize = try_convert ( mapping_data. number_of_products ) ?;
618- pubkey_assign (
619- & mut mapping_data. products_list [ current_index] ,
620- bytes_of ( & new_product_account. key . to_bytes ( ) ) ,
621- ) ;
586+ mapping_data. products_list [ current_index] = * new_product_account. key ;
622587 mapping_data. number_of_products += 1 ;
623588 mapping_data. header . size = try_convert :: < _ , u32 > (
624589 size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
625590 ) ? + mapping_data. number_of_products
626- * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
591+ * try_convert :: < _ , u32 > ( size_of :: < Pubkey > ( ) ) ?;
627592
628593 Ok ( ( ) )
629594}
@@ -746,15 +711,15 @@ pub fn del_product(
746711 ProgramError :: InvalidArgument ,
747712 ) ?;
748713 pyth_assert (
749- pubkey_is_zero ( & product_data. first_price_account ) ,
714+ product_data. first_price_account == Pubkey :: default ( ) ,
750715 ProgramError :: InvalidArgument ,
751716 ) ?;
752717
753- let product_key = product_account. key . to_bytes ( ) ;
718+ let product_key = product_account. key ;
754719 let product_index = mapping_data
755720 . products_list
756721 . iter ( )
757- . position ( |x| pubkey_equal ( x , & product_key) )
722+ . position ( |x| * x == * product_key)
758723 . ok_or ( ProgramError :: InvalidArgument ) ?;
759724
760725 let num_after_removal: usize = try_convert (
@@ -765,16 +730,13 @@ pub fn del_product(
765730 ) ?;
766731
767732 let last_key_bytes = mapping_data. products_list [ num_after_removal] ;
768- pubkey_assign (
769- & mut mapping_data. products_list [ product_index] ,
770- bytes_of ( & last_key_bytes) ,
771- ) ;
772- pubkey_clear ( & mut mapping_data. products_list [ num_after_removal] ) ;
733+ mapping_data. products_list [ product_index] = last_key_bytes;
734+ mapping_data. products_list [ num_after_removal] = Pubkey :: default ( ) ;
773735 mapping_data. number_of_products = try_convert :: < _ , u32 > ( num_after_removal) ?;
774736 mapping_data. header . size = try_convert :: < _ , u32 > (
775737 size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
776738 ) ? + mapping_data. number_of_products
777- * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
739+ * try_convert :: < _ , u32 > ( size_of :: < Pubkey > ( ) ) ?;
778740 }
779741
780742 // Zero out the balance of the price account to delete it.
0 commit comments