br_client/
lib.rs

1use borsh::{ BorshDeserialize };
2use solana_program::{
3    account_info::{ AccountInfo },
4    program_error::ProgramError,
5    pubkey::Pubkey,
6    borsh::try_from_slice_unchecked,
7};
8use std::str::FromStr;
9
10#[derive(BorshDeserialize)]
11pub struct Report {
12    pub magic: u64,
13    pub bump: u8,
14    pub active: bool,
15    pub process: Pubkey,
16    pub info: ReportInfo,
17}
18
19#[derive(BorshDeserialize)]
20pub struct ReportInfo {
21    pub source_chain: u32,
22    pub price: u64,
23    pub risk: u64,
24    pub time: u64,
25    pub decimal: u64,
26    pub program_addr: Pubkey,
27    pub token_addr: Pubkey,
28    pub local_addr: Pubkey, // It is solana local mint address of the nft which is transfer from other chain
29    pub name: String,
30    pub price_type: String,
31}
32
33fn check_owner(owner: &Pubkey) -> bool {
34    let oracle_program_id = Pubkey::from_str("BorcZEiGQJAL62M9QotWAvZYGkymuVnf42mj5HYnLZQj").unwrap();
35    owner.eq(&oracle_program_id)
36}
37
38pub fn get_report_info(account_info: &AccountInfo) -> Result<ReportInfo, ProgramError> {
39    if !check_owner(account_info.owner) {
40        return Err(ProgramError::IllegalOwner);
41    }
42
43    let report: Report = try_from_slice_unchecked(&account_info.data.borrow())?;
44
45    if !report.active {
46        // the account is deprecated
47        return Err(ProgramError::InvalidAccountData);
48    }
49
50
51    Ok(report.info)
52}