Skip to content

Commit f514be5

Browse files
guibescosmajabbour
andauthored
Rust logging 2 (#205)
* changed c return value of update price to indicate aggregation (#190) * changed c return value of update price to indicate aggregation * forgot to add bindings * removed the need for casting * fixed update_no_fail * removed unnecessary docker packages * timeless coments * added comment clarifying that 0 is success * a convinient way to derive traits * silenced unused bindings warnings * removed dead code * added a comment explaining the structure * changed importing style * called fmt on bindings output * added register_traits method * removed unnecessary match * fixed formatting * made it easier to add borsch to more types by not using vectors * changed c return value of update price to indicate aggregation (#190) * changed c return value of update price to indicate aggregation * forgot to add bindings * removed the need for casting * fixed update_no_fail * removed unnecessary docker packages * Switch from vector to slice to allow adding traits to multiple structs * Logging 2 * Prelog and postlog instructions * Fix CI * Remove accidental commits * Remove line * Clippy * Format and reorder * Add comment about accessing account 1 * Remove old offset file * Remove duplicate comment * More info * Don't commit bindings Co-authored-by: majabbour <[email protected]> Co-authored-by: Mark Jabbour <[email protected]> Co-authored-by: Guillermo Bescos <guibescos>
1 parent e4edbd9 commit f514be5

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

program/rust/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub extern "C" fn c_entrypoint(input: *mut u8) -> u64 {
4040
pub extern "C" fn entrypoint(input: *mut u8) -> u64 {
4141
let (_program_id, accounts, instruction_data) = unsafe { deserialize(input) };
4242

43-
match pre_log(instruction_data) {
43+
match pre_log(&accounts,instruction_data) {
4444
Err(error) => return error.into(),
4545
_ => {}
4646
}

program/rust/src/log.rs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use solana_program::entrypoint::ProgramResult;
66
use solana_program::msg;
77
use std::mem::size_of;
88

9-
pub fn pre_log(instruction_data: &[u8]) -> ProgramResult {
9+
pub fn pre_log(accounts : &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
1010
msg!("Pyth oracle contract");
1111

1212
let instruction_header: cmd_hdr = cmd_hdr::try_from_slice(&instruction_data[..8])?;
@@ -15,64 +15,64 @@ pub fn pre_log(instruction_data: &[u8]) -> ProgramResult {
1515
.try_into()
1616
.map_err(|_| OracleError::Generic)?;
1717
match instruction_id {
18-
command_t_e_cmd_upd_price => {
18+
command_t_e_cmd_upd_price | command_t_e_cmd_agg_price=> {
1919
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
2020
msg!(
21-
"Update price: price={:}, conf={:}, status={:}",
21+
"UpdatePrice: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
22+
accounts.get(0)
23+
.ok_or(OracleError::Generic)?.key,
24+
accounts.get(1)
25+
.ok_or(OracleError::Generic)?.key,
2226
instruction.price_,
2327
instruction.conf_,
24-
instruction.status_
28+
instruction.status_,
29+
instruction.pub_slot_
2530
);
2631
}
27-
command_t_e_cmd_agg_price => {
32+
command_t_e_cmd_upd_price_no_fail_on_error=> {
2833
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
2934
msg!(
30-
"Update price: price={:}, conf={:}, status={:}",
35+
"UpdatePriceNoFailOnError: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
36+
accounts.get(0)
37+
.ok_or(OracleError::Generic)?.key,
38+
accounts.get(1)
39+
.ok_or(OracleError::Generic)?.key,
3140
instruction.price_,
3241
instruction.conf_,
33-
instruction.status_
42+
instruction.status_,
43+
instruction.pub_slot_
3444
);
3545
}
36-
command_t_e_cmd_upd_price_no_fail_on_error => {
37-
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
38-
msg!(
39-
"Update price no fail on error: price={:}, conf={:}, status={:}",
40-
instruction.price_,
41-
instruction.conf_,
42-
instruction.status_
43-
);
44-
}
45-
4646
command_t_e_cmd_add_mapping => {
47-
msg!("Add mapping");
47+
msg!("AddMapping");
4848
}
4949
command_t_e_cmd_add_price => {
50-
msg!("Add price");
50+
msg!("AddPrice");
5151
}
5252
command_t_e_cmd_add_product => {
53-
msg!("Add product")
53+
msg!("AddProduct")
5454
}
5555
command_t_e_cmd_add_publisher => {
56-
msg!("Add publisher")
56+
msg!("AddPublisher")
5757
}
5858
command_t_e_cmd_del_publisher => {
59-
msg!("Delete publisher")
59+
msg!("DeletePublisher")
6060
}
6161
command_t_e_cmd_init_price => {
62-
msg!("Initialize price")
62+
msg!("InitializePrice")
6363
}
6464
command_t_e_cmd_init_mapping => {
65-
msg!("Initialize mapping account");
65+
msg!("InitializeMapping");
6666
}
6767

6868
command_t_e_cmd_set_min_pub => {
69-
msg!("Set minimum number of publishers");
69+
msg!("SetMinimumPublishers");
7070
}
7171
command_t_e_cmd_upd_product => {
72-
msg!("Update product");
72+
msg!("UpdateProduct");
7373
}
7474
_ => {
75-
msg!("Unrecognized instruction");
75+
msg!("UnrecognizedInstruction");
7676
return Err(OracleError::Generic.into());
7777
}
7878
}
@@ -92,10 +92,13 @@ pub fn post_log(c_ret_val: u64, accounts: &[AccountInfo]) -> ProgramResult {
9292
.try_borrow_data()?[start..(start + size_of::<pc_price_info>())],
9393
)?;
9494
msg!(
95-
"Aggregate updated : price={:}, conf={:}, status={:}",
95+
"UpdateAggregate : price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
96+
accounts.get(1)
97+
.ok_or(OracleError::Generic)?.key,
9698
aggregate_price_info.price_,
9799
aggregate_price_info.conf_,
98-
aggregate_price_info.status_
100+
aggregate_price_info.status_,
101+
aggregate_price_info.pub_slot_
99102
);
100103
}
101104
Ok(())

0 commit comments

Comments
 (0)