Skip to content

Commit 21922b5

Browse files
committed
Rename load_checked to load_pyth_account_checked
1 parent 8ff86c7 commit 21922b5

15 files changed

+178
-95
lines changed

program/rust/src/deserialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn check_owned_and_rent_exempt_account<T: PythAccount>(
8888
Ok(())
8989
}
9090

91-
pub fn load_checked<'a, T: PythAccount>(
91+
pub fn load_pyth_account_checked<'a, T: PythAccount>(
9292
account: &'a AccountInfo,
9393
version: u32,
9494
program_id: &Pubkey,

program/rust/src/rust_oracle.rs

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::deserialize::{
2323
initialize_pyth_account_checked,
2424
load,
2525
load_account_as_mut,
26-
load_checked,
26+
load_pyth_account_checked,
2727
};
2828
use crate::instruction::{
2929
AddPriceArgs,
@@ -122,7 +122,7 @@ pub fn resize_price_account(
122122
)?;
123123
// Check that it is a valid initialized price account
124124
{
125-
load_checked::<PriceAccount>(price_account_info, PC_VERSION, program_id)?;
125+
load_pyth_account_checked::<PriceAccount>(price_account_info, PC_VERSION, program_id)?;
126126
}
127127
let account_len = price_account_info.try_data_len()?;
128128
match account_len {
@@ -150,8 +150,11 @@ pub fn resize_price_account(
150150
price_account_info,
151151
size_of::<PriceAccountWrapper>(),
152152
)?;
153-
let mut price_account =
154-
load_checked::<PriceAccountWrapper>(price_account_info, PC_VERSION, program_id)?;
153+
let mut price_account = load_pyth_account_checked::<PriceAccountWrapper>(
154+
price_account_info,
155+
PC_VERSION,
156+
program_id,
157+
)?;
155158
// Initialize Time Machine
156159
price_account.initialize_time_machine()?;
157160
Ok(())
@@ -206,7 +209,8 @@ pub fn add_mapping(
206209
check_valid_fresh_account(next_mapping)?;
207210

208211
let hdr = load::<CommandHeader>(instruction_data)?;
209-
let mut cur_mapping = load_checked::<MappingAccount>(cur_mapping, hdr.version, program_id)?;
212+
let mut cur_mapping =
213+
load_pyth_account_checked::<MappingAccount>(cur_mapping, hdr.version, program_id)?;
210214
pyth_assert(
211215
cur_mapping.num_ == PC_MAP_TABLE_SIZE && pubkey_is_zero(&cur_mapping.next_),
212216
ProgramError::InvalidArgument,
@@ -244,8 +248,11 @@ pub fn upd_price(
244248
let latest_aggregate_price: PriceInfo;
245249
{
246250
// Verify that symbol account is initialized
247-
let price_data =
248-
load_checked::<PriceAccount>(price_account, cmd_args.header.version, program_id)?;
251+
let price_data = load_pyth_account_checked::<PriceAccount>(
252+
price_account,
253+
cmd_args.header.version,
254+
program_id,
255+
)?;
249256

250257
// Verify that publisher is authorized
251258
while publisher_index < price_data.num_ as usize {
@@ -306,8 +313,11 @@ pub fn upd_price(
306313
}
307314

308315
{
309-
let mut price_data =
310-
load_checked::<PriceAccount>(price_account, cmd_args.header.version, program_id)?;
316+
let mut price_data = load_pyth_account_checked::<PriceAccount>(
317+
price_account,
318+
cmd_args.header.version,
319+
program_id,
320+
)?;
311321
let publisher_price = &mut price_data.comp_[publisher_index].latest_;
312322
publisher_price.price_ = cmd_args.price;
313323
publisher_price.conf_ = cmd_args.confidence;
@@ -359,8 +369,11 @@ pub fn add_price(
359369
check_valid_signable_account(program_id, price_account, size_of::<PriceAccount>())?;
360370
check_valid_fresh_account(price_account)?;
361371

362-
let mut product_data =
363-
load_checked::<ProductAccount>(product_account, cmd_args.header.version, program_id)?;
372+
let mut product_data = load_pyth_account_checked::<ProductAccount>(
373+
product_account,
374+
cmd_args.header.version,
375+
program_id,
376+
)?;
364377

365378
let mut price_data =
366379
initialize_pyth_account_checked::<PriceAccount>(price_account, cmd_args.header.version)?;
@@ -396,9 +409,13 @@ pub fn del_price(
396409

397410
{
398411
let cmd_args = load::<CommandHeader>(instruction_data)?;
399-
let mut product_data =
400-
load_checked::<ProductAccount>(product_account, cmd_args.version, program_id)?;
401-
let price_data = load_checked::<PriceAccount>(price_account, cmd_args.version, program_id)?;
412+
let mut product_data = load_pyth_account_checked::<ProductAccount>(
413+
product_account,
414+
cmd_args.version,
415+
program_id,
416+
)?;
417+
let price_data =
418+
load_pyth_account_checked::<PriceAccount>(price_account, cmd_args.version, program_id)?;
402419
pyth_assert(
403420
pubkey_equal(&product_data.px_acc_, &price_account.key.to_bytes()),
404421
ProgramError::InvalidArgument,
@@ -439,8 +456,11 @@ pub fn init_price(
439456
check_valid_funding_account(funding_account)?;
440457
check_valid_signable_account(program_id, price_account, size_of::<PriceAccount>())?;
441458

442-
let mut price_data =
443-
load_checked::<PriceAccount>(price_account, cmd_args.header.version, program_id)?;
459+
let mut price_data = load_pyth_account_checked::<PriceAccount>(
460+
price_account,
461+
cmd_args.header.version,
462+
program_id,
463+
)?;
444464
pyth_assert(
445465
price_data.ptype_ == cmd_args.price_type,
446466
ProgramError::InvalidArgument,
@@ -510,8 +530,11 @@ pub fn add_publisher(
510530
check_valid_funding_account(funding_account)?;
511531
check_valid_signable_account(program_id, price_account, size_of::<PriceAccount>())?;
512532

513-
let mut price_data =
514-
load_checked::<PriceAccount>(price_account, cmd_args.header.version, program_id)?;
533+
let mut price_data = load_pyth_account_checked::<PriceAccount>(
534+
price_account,
535+
cmd_args.header.version,
536+
program_id,
537+
)?;
515538

516539
if price_data.num_ >= PC_COMP_SIZE {
517540
return Err(ProgramError::InvalidArgument);
@@ -564,8 +587,11 @@ pub fn del_publisher(
564587
check_valid_funding_account(funding_account)?;
565588
check_valid_signable_account(program_id, price_account, size_of::<PriceAccount>())?;
566589

567-
let mut price_data =
568-
load_checked::<PriceAccount>(price_account, cmd_args.header.version, program_id)?;
590+
let mut price_data = load_pyth_account_checked::<PriceAccount>(
591+
price_account,
592+
cmd_args.header.version,
593+
program_id,
594+
)?;
569595

570596
for i in 0..(price_data.num_ as usize) {
571597
if pubkey_equal(&cmd_args.publisher, bytes_of(&price_data.comp_[i].pub_)) {
@@ -609,7 +635,7 @@ pub fn add_product(
609635

610636
let hdr = load::<CommandHeader>(instruction_data)?;
611637
let mut mapping_data =
612-
load_checked::<MappingAccount>(tail_mapping_account, hdr.version, program_id)?;
638+
load_pyth_account_checked::<MappingAccount>(tail_mapping_account, hdr.version, program_id)?;
613639
// The mapping account must have free space to add the product account
614640
pyth_assert(
615641
mapping_data.num_ < PC_MAP_TABLE_SIZE,
@@ -650,7 +676,7 @@ pub fn upd_product(
650676
{
651677
// Validate that product_account contains the appropriate account header
652678
let mut _product_data =
653-
load_checked::<ProductAccount>(product_account, hdr.version, program_id)?;
679+
load_pyth_account_checked::<ProductAccount>(product_account, hdr.version, program_id)?;
654680
}
655681

656682
pyth_assert(
@@ -687,7 +713,7 @@ pub fn upd_product(
687713
}
688714

689715
let mut product_data =
690-
load_checked::<ProductAccount>(product_account, hdr.version, program_id)?;
716+
load_pyth_account_checked::<ProductAccount>(product_account, hdr.version, program_id)?;
691717
product_data.size_ = try_convert(size_of::<ProductAccount>() + new_data.len())?;
692718

693719
Ok(())
@@ -714,7 +740,7 @@ pub fn set_min_pub(
714740
check_valid_signable_account(program_id, price_account, size_of::<PriceAccount>())?;
715741

716742
let mut price_account_data =
717-
load_checked::<PriceAccount>(price_account, cmd.header.version, program_id)?;
743+
load_pyth_account_checked::<PriceAccount>(price_account, cmd.header.version, program_id)?;
718744
price_account_data.min_pub_ = cmd.minimum_publishers;
719745

720746
Ok(())
@@ -743,10 +769,16 @@ pub fn del_product(
743769

744770
{
745771
let cmd_args = load::<CommandHeader>(instruction_data)?;
746-
let mut mapping_data =
747-
load_checked::<MappingAccount>(mapping_account, cmd_args.version, program_id)?;
748-
let product_data =
749-
load_checked::<ProductAccount>(product_account, cmd_args.version, program_id)?;
772+
let mut mapping_data = load_pyth_account_checked::<MappingAccount>(
773+
mapping_account,
774+
cmd_args.version,
775+
program_id,
776+
)?;
777+
let product_data = load_pyth_account_checked::<ProductAccount>(
778+
product_account,
779+
cmd_args.version,
780+
program_id,
781+
)?;
750782

751783
// This assertion is just to make the subtractions below simpler
752784
pyth_assert(mapping_data.num_ >= 1, ProgramError::InvalidArgument)?;

program/rust/src/tests/test_add_mapping.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::c_oracle_header::{
66
};
77
use crate::deserialize::{
88
initialize_pyth_account_checked,
9-
load_checked,
9+
load_pyth_account_checked,
1010
};
1111
use crate::instruction::{
1212
CommandHeader,
@@ -43,7 +43,8 @@ fn test_add_mapping() {
4343

4444
{
4545
let mut cur_mapping_data =
46-
load_checked::<MappingAccount>(&cur_mapping, PC_VERSION, &program_id).unwrap();
46+
load_pyth_account_checked::<MappingAccount>(&cur_mapping, PC_VERSION, &program_id)
47+
.unwrap();
4748
cur_mapping_data.num_ = PC_MAP_TABLE_SIZE;
4849
}
4950

@@ -60,9 +61,11 @@ fn test_add_mapping() {
6061

6162
{
6263
let next_mapping_data =
63-
load_checked::<MappingAccount>(&next_mapping, PC_VERSION, &program_id).unwrap();
64+
load_pyth_account_checked::<MappingAccount>(&next_mapping, PC_VERSION, &program_id)
65+
.unwrap();
6466
let mut cur_mapping_data =
65-
load_checked::<MappingAccount>(&cur_mapping, PC_VERSION, &program_id).unwrap();
67+
load_pyth_account_checked::<MappingAccount>(&cur_mapping, PC_VERSION, &program_id)
68+
.unwrap();
6669

6770
assert!(pubkey_equal(
6871
&cur_mapping_data.next_,
@@ -90,7 +93,8 @@ fn test_add_mapping() {
9093

9194
{
9295
let mut cur_mapping_data =
93-
load_checked::<MappingAccount>(&cur_mapping, PC_VERSION, &program_id).unwrap();
96+
load_pyth_account_checked::<MappingAccount>(&cur_mapping, PC_VERSION, &program_id)
97+
.unwrap();
9498
assert!(pubkey_is_zero(&cur_mapping_data.next_));
9599
cur_mapping_data.num_ = PC_MAP_TABLE_SIZE;
96100
cur_mapping_data.magic_ = 0;
@@ -111,7 +115,8 @@ fn test_add_mapping() {
111115

112116
{
113117
let mut cur_mapping_data =
114-
load_checked::<MappingAccount>(&cur_mapping, PC_VERSION, &program_id).unwrap();
118+
load_pyth_account_checked::<MappingAccount>(&cur_mapping, PC_VERSION, &program_id)
119+
.unwrap();
115120
cur_mapping_data.magic_ = PC_MAGIC;
116121
}
117122

program/rust/src/tests/test_add_price.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::c_oracle_header::{
66
};
77
use crate::deserialize::{
88
initialize_pyth_account_checked,
9-
load_checked,
9+
load_pyth_account_checked,
1010
};
1111
use crate::error::OracleError;
1212
use crate::instruction::{
@@ -79,9 +79,11 @@ fn test_add_price() {
7979

8080
{
8181
let price_data =
82-
load_checked::<PriceAccount>(&price_account, PC_VERSION, &program_id).unwrap();
82+
load_pyth_account_checked::<PriceAccount>(&price_account, PC_VERSION, &program_id)
83+
.unwrap();
8384
let product_data =
84-
load_checked::<ProductAccount>(&product_account, PC_VERSION, &program_id).unwrap();
85+
load_pyth_account_checked::<ProductAccount>(&product_account, PC_VERSION, &program_id)
86+
.unwrap();
8587
assert_eq!(price_data.expo_, 1);
8688
assert_eq!(price_data.ptype_, 1);
8789
assert!(pubkey_equal(
@@ -108,9 +110,11 @@ fn test_add_price() {
108110

109111
{
110112
let price_data_2 =
111-
load_checked::<PriceAccount>(&price_account_2, PC_VERSION, &program_id).unwrap();
113+
load_pyth_account_checked::<PriceAccount>(&price_account_2, PC_VERSION, &program_id)
114+
.unwrap();
112115
let product_data =
113-
load_checked::<ProductAccount>(&product_account, PC_VERSION, &program_id).unwrap();
116+
load_pyth_account_checked::<ProductAccount>(&product_account, PC_VERSION, &program_id)
117+
.unwrap();
114118
assert_eq!(price_data_2.expo_, 1);
115119
assert_eq!(price_data_2.ptype_, 1);
116120
assert!(pubkey_equal(

program/rust/src/tests/test_add_product.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::c_oracle_header::{
1212
};
1313
use crate::deserialize::{
1414
initialize_pyth_account_checked,
15-
load_checked,
15+
load_pyth_account_checked,
1616
};
1717
use crate::error::OracleError;
1818
use crate::instruction::{
@@ -66,9 +66,11 @@ fn test_add_product() {
6666

6767
{
6868
let product_data =
69-
load_checked::<ProductAccount>(&product_account, PC_VERSION, &program_id).unwrap();
69+
load_pyth_account_checked::<ProductAccount>(&product_account, PC_VERSION, &program_id)
70+
.unwrap();
7071
let mapping_data =
71-
load_checked::<MappingAccount>(&mapping_account, PC_VERSION, &program_id).unwrap();
72+
load_pyth_account_checked::<MappingAccount>(&mapping_account, PC_VERSION, &program_id)
73+
.unwrap();
7274

7375
assert_eq!(product_data.magic_, PC_MAGIC);
7476
assert_eq!(product_data.ver_, PC_VERSION);
@@ -94,7 +96,8 @@ fn test_add_product() {
9496
.is_ok());
9597
{
9698
let mapping_data =
97-
load_checked::<MappingAccount>(&mapping_account, PC_VERSION, &program_id).unwrap();
99+
load_pyth_account_checked::<MappingAccount>(&mapping_account, PC_VERSION, &program_id)
100+
.unwrap();
98101
assert_eq!(mapping_data.num_, 2);
99102
assert_eq!(mapping_data.size_, (MappingAccount::INITIAL_SIZE + 2 * 32));
100103
assert!(pubkey_equal(
@@ -148,7 +151,8 @@ fn test_add_product() {
148151
)
149152
.is_ok());
150153
let mapping_data =
151-
load_checked::<MappingAccount>(&mapping_account, PC_VERSION, &program_id).unwrap();
154+
load_pyth_account_checked::<MappingAccount>(&mapping_account, PC_VERSION, &program_id)
155+
.unwrap();
152156
assert_eq!(
153157
mapping_data.size_,
154158
MappingAccount::INITIAL_SIZE + (i + 1) * 32
@@ -172,6 +176,7 @@ fn test_add_product() {
172176
);
173177

174178
let mapping_data =
175-
load_checked::<MappingAccount>(&mapping_account, PC_VERSION, &program_id).unwrap();
179+
load_pyth_account_checked::<MappingAccount>(&mapping_account, PC_VERSION, &program_id)
180+
.unwrap();
176181
assert_eq!(mapping_data.num_, PC_MAP_TABLE_SIZE);
177182
}

program/rust/src/tests/test_add_publisher.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::c_oracle_header::{
88
};
99
use crate::deserialize::{
1010
initialize_pyth_account_checked,
11-
load_checked,
11+
load_pyth_account_checked,
1212
};
1313
use crate::instruction::{
1414
AddPublisherArgs,
@@ -72,7 +72,8 @@ fn test_add_publisher() {
7272

7373
{
7474
let price_data =
75-
load_checked::<PriceAccount>(&price_account, PC_VERSION, &program_id).unwrap();
75+
load_pyth_account_checked::<PriceAccount>(&price_account, PC_VERSION, &program_id)
76+
.unwrap();
7677
assert_eq!(price_data.num_, 1);
7778
assert_eq!(
7879
price_data.size_,
@@ -122,7 +123,8 @@ fn test_add_publisher() {
122123

123124
{
124125
let price_data =
125-
load_checked::<PriceAccount>(&price_account, PC_VERSION, &program_id).unwrap();
126+
load_pyth_account_checked::<PriceAccount>(&price_account, PC_VERSION, &program_id)
127+
.unwrap();
126128
assert_eq!(price_data.num_, i + 1);
127129
assert!(pubkey_equal(
128130
&price_data.comp_[i as usize].pub_,

0 commit comments

Comments
 (0)