Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0f238d0
changed c return value of update price to indicate aggregation (#190)
majabbour Jul 19, 2022
3a2140b
timeless coments
majabbour Jul 20, 2022
13377c8
added comment clarifying that 0 is success
majabbour Jul 20, 2022
a0556d7
a convinient way to derive traits
majabbour Jul 20, 2022
2abb63b
silenced unused bindings warnings
majabbour Jul 21, 2022
cb1a3b8
removed dead code
majabbour Jul 21, 2022
80ac6a0
added a comment explaining the structure
majabbour Jul 21, 2022
abd8e2e
changed importing style
majabbour Jul 21, 2022
fba7985
called fmt on bindings output
majabbour Jul 21, 2022
c6fa336
added register_traits method
majabbour Jul 21, 2022
371d453
removed unnecessary match
majabbour Jul 21, 2022
5871ab8
fixed formatting
majabbour Jul 21, 2022
ec94b78
made it easier to add borsch to more types by not using vectors
majabbour Jul 22, 2022
93717a9
changed c return value of update price to indicate aggregation (#190)
majabbour Jul 19, 2022
3911d15
Switch from vector to slice to allow adding traits to multiple structs
Jul 21, 2022
637990c
Logging 2
Jul 21, 2022
5f04d3b
Prelog and postlog instructions
Jul 22, 2022
940af79
Fix CI
Jul 22, 2022
a004412
Merge branch 'main' into rust-logging-2
Jul 22, 2022
0cbafb8
Remove accidental commits
Jul 22, 2022
65f276b
Merge branch 'main' into rust-logging-2
Jul 22, 2022
3f5dfb9
Remove line
Jul 22, 2022
f579d78
Clippy
Jul 22, 2022
b426d38
Format and reorder
Jul 22, 2022
5bf547f
Add comment about accessing account 1
Jul 22, 2022
93121b0
Remove old offset file
Jul 22, 2022
928360c
Remove duplicate comment
Jul 22, 2022
9574cfd
More info
Jul 25, 2022
d911032
Merge branch 'main' into rust-logging-2
Jul 25, 2022
87ceaa8
Don't commit bindings
Jul 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion program/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub extern "C" fn c_entrypoint(input: *mut u8) -> u64 {
pub extern "C" fn entrypoint(input: *mut u8) -> u64 {
let (_program_id, accounts, instruction_data) = unsafe { deserialize(input) };

match pre_log(instruction_data) {
match pre_log(&accounts,instruction_data) {
Err(error) => return error.into(),
_ => {}
}
Expand Down
61 changes: 32 additions & 29 deletions program/rust/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use solana_program::entrypoint::ProgramResult;
use solana_program::msg;
use std::mem::size_of;

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

let instruction_header: cmd_hdr = cmd_hdr::try_from_slice(&instruction_data[..8])?;
Expand All @@ -15,64 +15,64 @@ pub fn pre_log(instruction_data: &[u8]) -> ProgramResult {
.try_into()
.map_err(|_| OracleError::Generic)?;
match instruction_id {
command_t_e_cmd_upd_price => {
command_t_e_cmd_upd_price | command_t_e_cmd_agg_price=> {
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
msg!(
"Update price: price={:}, conf={:}, status={:}",
"UpdatePrice: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
accounts.get(0)
.ok_or(OracleError::Generic)?.key,
accounts.get(1)
.ok_or(OracleError::Generic)?.key,
instruction.price_,
instruction.conf_,
instruction.status_
instruction.status_,
instruction.pub_slot_
);
}
command_t_e_cmd_agg_price => {
command_t_e_cmd_upd_price_no_fail_on_error=> {
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
msg!(
"Update price: price={:}, conf={:}, status={:}",
"UpdatePriceNoFailOnError: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
accounts.get(0)
.ok_or(OracleError::Generic)?.key,
accounts.get(1)
.ok_or(OracleError::Generic)?.key,
instruction.price_,
instruction.conf_,
instruction.status_
instruction.status_,
instruction.pub_slot_
);
}
command_t_e_cmd_upd_price_no_fail_on_error => {
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
msg!(
"Update price no fail on error: price={:}, conf={:}, status={:}",
instruction.price_,
instruction.conf_,
instruction.status_
);
}

command_t_e_cmd_add_mapping => {
msg!("Add mapping");
msg!("AddMapping");
}
command_t_e_cmd_add_price => {
msg!("Add price");
msg!("AddPrice");
}
command_t_e_cmd_add_product => {
msg!("Add product")
msg!("AddProduct")
}
command_t_e_cmd_add_publisher => {
msg!("Add publisher")
msg!("AddPublisher")
}
command_t_e_cmd_del_publisher => {
msg!("Delete publisher")
msg!("DeletePublisher")
}
command_t_e_cmd_init_price => {
msg!("Initialize price")
msg!("InitializePrice")
}
command_t_e_cmd_init_mapping => {
msg!("Initialize mapping account");
msg!("InitializeMapping");
}

command_t_e_cmd_set_min_pub => {
msg!("Set minimum number of publishers");
msg!("SetMinimumPublishers");
}
command_t_e_cmd_upd_product => {
msg!("Update product");
msg!("UpdateProduct");
}
_ => {
msg!("Unrecognized instruction");
msg!("UnrecognizedInstruction");
return Err(OracleError::Generic.into());
}
}
Expand All @@ -92,10 +92,13 @@ pub fn post_log(c_ret_val: u64, accounts: &[AccountInfo]) -> ProgramResult {
.try_borrow_data()?[start..(start + size_of::<pc_price_info>())],
)?;
msg!(
"Aggregate updated : price={:}, conf={:}, status={:}",
"UpdateAggregate : price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
accounts.get(1)
.ok_or(OracleError::Generic)?.key,
aggregate_price_info.price_,
aggregate_price_info.conf_,
aggregate_price_info.status_
aggregate_price_info.status_,
aggregate_price_info.pub_slot_
);
}
Ok(())
Expand Down