@@ -4,7 +4,6 @@ use std::mem::{
44} ;
55
66use crate :: c_oracle_header:: {
7- CPubkey ,
87 MappingAccount ,
98 PriceAccount ,
109 PriceComponent ,
@@ -42,18 +41,14 @@ use crate::utils::{
4241 check_valid_signable_account,
4342 check_valid_writable_account,
4443 is_component_update,
45- pubkey_assign,
46- pubkey_clear,
47- pubkey_equal,
48- pubkey_is_zero,
4944 pyth_assert,
5045 read_pc_str_t,
5146 try_convert,
5247} ;
5348use crate :: OracleError ;
5449use bytemuck:: {
55- bytes_of,
5650 bytes_of_mut,
51+ Zeroable ,
5752} ;
5853use solana_program:: account_info:: AccountInfo ;
5954use solana_program:: clock:: Clock ;
@@ -209,15 +204,12 @@ pub fn add_mapping(
209204 let mut cur_mapping = load_checked :: < MappingAccount > ( cur_mapping, hdr. version ) ?;
210205 pyth_assert (
211206 cur_mapping. number_of_products == PC_MAP_TABLE_SIZE
212- && pubkey_is_zero ( & cur_mapping. next_mapping_account ) ,
207+ && cur_mapping. next_mapping_account == Pubkey :: zeroed ( ) ,
213208 ProgramError :: InvalidArgument ,
214209 ) ?;
215210
216211 initialize_pyth_account_checked :: < MappingAccount > ( next_mapping, hdr. version ) ?;
217- pubkey_assign (
218- & mut cur_mapping. next_mapping_account ,
219- & next_mapping. key . to_bytes ( ) ,
220- ) ;
212+ cur_mapping. next_mapping_account = * next_mapping. key ;
221213
222214 Ok ( ( ) )
223215}
@@ -252,10 +244,7 @@ pub fn upd_price(
252244
253245 // Verify that publisher is authorized
254246 while publisher_index < price_data. num_ as usize {
255- if pubkey_equal (
256- & price_data. comp_ [ publisher_index] . pub_ ,
257- & funding_account. key . to_bytes ( ) ,
258- ) {
247+ if price_data. comp_ [ publisher_index] . pub_ == * funding_account. key {
259248 break ;
260249 }
261250 publisher_index += 1 ;
@@ -369,18 +358,9 @@ pub fn add_price(
369358 initialize_pyth_account_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
370359 price_data. exponent = cmd_args. exponent ;
371360 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- ) ;
361+ price_data. product_account = * product_account. key ;
362+ price_data. next_price_account = product_data. first_price_account ;
363+ product_data. first_price_account = * price_account. key ;
384364
385365 Ok ( ( ) )
386366}
@@ -411,22 +391,16 @@ pub fn del_price(
411391 let mut product_data = load_checked :: < ProductAccount > ( product_account, cmd_args. version ) ?;
412392 let price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. version ) ?;
413393 pyth_assert (
414- pubkey_equal (
415- & product_data. first_price_account ,
416- & price_account. key . to_bytes ( ) ,
417- ) ,
394+ product_data. first_price_account == * price_account. key ,
418395 ProgramError :: InvalidArgument ,
419396 ) ?;
420397
421398 pyth_assert (
422- pubkey_equal ( & price_data. product_account , & product_account. key . to_bytes ( ) ) ,
399+ price_data. product_account == * product_account. key ,
423400 ProgramError :: InvalidArgument ,
424401 ) ?;
425402
426- pubkey_assign (
427- & mut product_data. first_price_account ,
428- bytes_of ( & price_data. next_price_account ) ,
429- ) ;
403+ product_data. first_price_account = price_data. next_price_account ;
430404 }
431405
432406 // Zero out the balance of the price account to delete it.
@@ -514,7 +488,7 @@ pub fn add_publisher(
514488
515489 pyth_assert (
516490 instruction_data. len ( ) == size_of :: < AddPublisherArgs > ( )
517- && ! pubkey_is_zero ( & cmd_args. publisher ) ,
491+ && cmd_args. publisher != Pubkey :: zeroed ( ) ,
518492 ProgramError :: InvalidArgument ,
519493 ) ?;
520494
@@ -533,7 +507,7 @@ pub fn add_publisher(
533507 }
534508
535509 for i in 0 ..( price_data. num_ as usize ) {
536- if pubkey_equal ( & cmd_args. publisher , bytes_of ( & price_data. comp_ [ i] . pub_ ) ) {
510+ if cmd_args. publisher == price_data. comp_ [ i] . pub_ {
537511 return Err ( ProgramError :: InvalidArgument ) ;
538512 }
539513 }
@@ -544,10 +518,7 @@ pub fn add_publisher(
544518 0 ,
545519 size_of :: < PriceComponent > ( ) ,
546520 ) ;
547- pubkey_assign (
548- & mut price_data. comp_ [ current_index] . pub_ ,
549- bytes_of ( & cmd_args. publisher ) ,
550- ) ;
521+ price_data. comp_ [ current_index] . pub_ = cmd_args. publisher ;
551522 price_data. num_ += 1 ;
552523 price_data. header . size =
553524 try_convert :: < _ , u32 > ( size_of :: < PriceAccount > ( ) - size_of_val ( & price_data. comp_ ) ) ?
@@ -567,7 +538,7 @@ pub fn del_publisher(
567538
568539 pyth_assert (
569540 instruction_data. len ( ) == size_of :: < DelPublisherArgs > ( )
570- && ! pubkey_is_zero ( & cmd_args. publisher ) ,
541+ && cmd_args. publisher != Pubkey :: zeroed ( ) ,
571542 ProgramError :: InvalidArgument ,
572543 ) ?;
573544
@@ -582,7 +553,7 @@ pub fn del_publisher(
582553 let mut price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
583554
584555 for i in 0 ..( price_data. num_ as usize ) {
585- if pubkey_equal ( & cmd_args. publisher , bytes_of ( & price_data. comp_ [ i] . pub_ ) ) {
556+ if cmd_args. publisher == price_data. comp_ [ i] . pub_ {
586557 for j in i + 1 ..( price_data. num_ as usize ) {
587558 price_data. comp_ [ j - 1 ] = price_data. comp_ [ j] ;
588559 }
@@ -632,15 +603,12 @@ pub fn add_product(
632603 initialize_pyth_account_checked :: < ProductAccount > ( new_product_account, hdr. version ) ?;
633604
634605 let current_index: usize = try_convert ( mapping_data. number_of_products ) ?;
635- pubkey_assign (
636- & mut mapping_data. products_list [ current_index] ,
637- bytes_of ( & new_product_account. key . to_bytes ( ) ) ,
638- ) ;
606+ mapping_data. products_list [ current_index] = * new_product_account. key ;
639607 mapping_data. number_of_products += 1 ;
640608 mapping_data. header . size = try_convert :: < _ , u32 > (
641609 size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
642610 ) ? + mapping_data. number_of_products
643- * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
611+ * try_convert :: < _ , u32 > ( size_of :: < Pubkey > ( ) ) ?;
644612
645613 Ok ( ( ) )
646614}
@@ -763,15 +731,15 @@ pub fn del_product(
763731 ProgramError :: InvalidArgument ,
764732 ) ?;
765733 pyth_assert (
766- pubkey_is_zero ( & product_data. first_price_account ) ,
734+ product_data. first_price_account == Pubkey :: zeroed ( ) ,
767735 ProgramError :: InvalidArgument ,
768736 ) ?;
769737
770- let product_key = product_account. key . to_bytes ( ) ;
738+ let product_key = product_account. key ;
771739 let product_index = mapping_data
772740 . products_list
773741 . iter ( )
774- . position ( |x| pubkey_equal ( x , & product_key) )
742+ . position ( |x| * x == * product_key)
775743 . ok_or ( ProgramError :: InvalidArgument ) ?;
776744
777745 let num_after_removal: usize = try_convert (
@@ -782,16 +750,13 @@ pub fn del_product(
782750 ) ?;
783751
784752 let last_key_bytes = mapping_data. products_list [ num_after_removal] ;
785- pubkey_assign (
786- & mut mapping_data. products_list [ product_index] ,
787- bytes_of ( & last_key_bytes) ,
788- ) ;
789- pubkey_clear ( & mut mapping_data. products_list [ num_after_removal] ) ;
753+ mapping_data. products_list [ product_index] = last_key_bytes;
754+ mapping_data. products_list [ num_after_removal] = Pubkey :: zeroed ( ) ;
790755 mapping_data. number_of_products = try_convert :: < _ , u32 > ( num_after_removal) ?;
791756 mapping_data. header . size = try_convert :: < _ , u32 > (
792757 size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
793758 ) ? + mapping_data. number_of_products
794- * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
759+ * try_convert :: < _ , u32 > ( size_of :: < Pubkey > ( ) ) ?;
795760 }
796761
797762 // Zero out the balance of the price account to delete it.
0 commit comments