@@ -4,7 +4,6 @@ use std::mem::{
4
4
} ;
5
5
6
6
use crate :: c_oracle_header:: {
7
- CPubkey ,
8
7
MappingAccount ,
9
8
PriceAccount ,
10
9
PriceComponent ,
@@ -40,19 +39,12 @@ use crate::utils::{
40
39
check_valid_signable_account,
41
40
check_valid_writable_account,
42
41
is_component_update,
43
- pubkey_assign,
44
- pubkey_clear,
45
- pubkey_equal,
46
- pubkey_is_zero,
47
42
pyth_assert,
48
43
read_pc_str_t,
49
44
try_convert,
50
45
} ;
51
46
use crate :: OracleError ;
52
- use bytemuck:: {
53
- bytes_of,
54
- bytes_of_mut,
55
- } ;
47
+ use bytemuck:: bytes_of_mut;
56
48
use solana_program:: account_info:: AccountInfo ;
57
49
use solana_program:: clock:: Clock ;
58
50
use solana_program:: entrypoint:: ProgramResult ;
@@ -197,15 +189,12 @@ pub fn add_mapping(
197
189
let mut cur_mapping = load_checked :: < MappingAccount > ( cur_mapping, hdr. version ) ?;
198
190
pyth_assert (
199
191
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 ( ) ,
201
193
ProgramError :: InvalidArgument ,
202
194
) ?;
203
195
204
196
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 ;
209
198
210
199
Ok ( ( ) )
211
200
}
@@ -240,10 +229,7 @@ pub fn upd_price(
240
229
241
230
// Verify that publisher is authorized
242
231
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 {
247
233
break ;
248
234
}
249
235
publisher_index += 1 ;
@@ -357,18 +343,9 @@ pub fn add_price(
357
343
initialize_pyth_account_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
358
344
price_data. exponent = cmd_args. exponent ;
359
345
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 ;
372
349
373
350
Ok ( ( ) )
374
351
}
@@ -399,22 +376,16 @@ pub fn del_price(
399
376
let mut product_data = load_checked :: < ProductAccount > ( product_account, cmd_args. version ) ?;
400
377
let price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. version ) ?;
401
378
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 ,
406
380
ProgramError :: InvalidArgument ,
407
381
) ?;
408
382
409
383
pyth_assert (
410
- pubkey_equal ( & price_data. product_account , & product_account. key . to_bytes ( ) ) ,
384
+ price_data. product_account == * product_account. key ,
411
385
ProgramError :: InvalidArgument ,
412
386
) ?;
413
387
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 ;
418
389
}
419
390
420
391
// Zero out the balance of the price account to delete it.
@@ -502,7 +473,7 @@ pub fn add_publisher(
502
473
503
474
pyth_assert (
504
475
instruction_data. len ( ) == size_of :: < AddPublisherArgs > ( )
505
- && ! pubkey_is_zero ( & cmd_args. publisher ) ,
476
+ && cmd_args. publisher != Pubkey :: default ( ) ,
506
477
ProgramError :: InvalidArgument ,
507
478
) ?;
508
479
@@ -521,7 +492,7 @@ pub fn add_publisher(
521
492
}
522
493
523
494
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_ {
525
496
return Err ( ProgramError :: InvalidArgument ) ;
526
497
}
527
498
}
@@ -532,10 +503,7 @@ pub fn add_publisher(
532
503
0 ,
533
504
size_of :: < PriceComponent > ( ) ,
534
505
) ;
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 ;
539
507
price_data. num_ += 1 ;
540
508
price_data. header . size =
541
509
try_convert :: < _ , u32 > ( size_of :: < PriceAccount > ( ) - size_of_val ( & price_data. comp_ ) ) ?
@@ -555,7 +523,7 @@ pub fn del_publisher(
555
523
556
524
pyth_assert (
557
525
instruction_data. len ( ) == size_of :: < DelPublisherArgs > ( )
558
- && ! pubkey_is_zero ( & cmd_args. publisher ) ,
526
+ && cmd_args. publisher != Pubkey :: default ( ) ,
559
527
ProgramError :: InvalidArgument ,
560
528
) ?;
561
529
@@ -570,7 +538,7 @@ pub fn del_publisher(
570
538
let mut price_data = load_checked :: < PriceAccount > ( price_account, cmd_args. header . version ) ?;
571
539
572
540
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_ {
574
542
for j in i + 1 ..( price_data. num_ as usize ) {
575
543
price_data. comp_ [ j - 1 ] = price_data. comp_ [ j] ;
576
544
}
@@ -615,15 +583,12 @@ pub fn add_product(
615
583
initialize_pyth_account_checked :: < ProductAccount > ( new_product_account, hdr. version ) ?;
616
584
617
585
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 ;
622
587
mapping_data. number_of_products += 1 ;
623
588
mapping_data. header . size = try_convert :: < _ , u32 > (
624
589
size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
625
590
) ? + mapping_data. number_of_products
626
- * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
591
+ * try_convert :: < _ , u32 > ( size_of :: < Pubkey > ( ) ) ?;
627
592
628
593
Ok ( ( ) )
629
594
}
@@ -746,15 +711,15 @@ pub fn del_product(
746
711
ProgramError :: InvalidArgument ,
747
712
) ?;
748
713
pyth_assert (
749
- pubkey_is_zero ( & product_data. first_price_account ) ,
714
+ product_data. first_price_account == Pubkey :: default ( ) ,
750
715
ProgramError :: InvalidArgument ,
751
716
) ?;
752
717
753
- let product_key = product_account. key . to_bytes ( ) ;
718
+ let product_key = product_account. key ;
754
719
let product_index = mapping_data
755
720
. products_list
756
721
. iter ( )
757
- . position ( |x| pubkey_equal ( x , & product_key) )
722
+ . position ( |x| * x == * product_key)
758
723
. ok_or ( ProgramError :: InvalidArgument ) ?;
759
724
760
725
let num_after_removal: usize = try_convert (
@@ -765,16 +730,13 @@ pub fn del_product(
765
730
) ?;
766
731
767
732
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 ( ) ;
773
735
mapping_data. number_of_products = try_convert :: < _ , u32 > ( num_after_removal) ?;
774
736
mapping_data. header . size = try_convert :: < _ , u32 > (
775
737
size_of :: < MappingAccount > ( ) - size_of_val ( & mapping_data. products_list ) ,
776
738
) ? + mapping_data. number_of_products
777
- * try_convert :: < _ , u32 > ( size_of :: < CPubkey > ( ) ) ?;
739
+ * try_convert :: < _ , u32 > ( size_of :: < Pubkey > ( ) ) ?;
778
740
}
779
741
780
742
// Zero out the balance of the price account to delete it.
0 commit comments