solana_central/types/
link.rs1use solana_sdk::pubkey::Pubkey;
2
3#[derive(Clone)]
12pub struct Link {
13 pub link: [u8; 64],
14 pub block_time: u64,
15 pub slot: u64,
16 pub index: u64,
17 pub atomic_instruction_index: u8,
18}
19
20impl Link {
21 pub fn check_link(
24 account1: &Pubkey,
25 account2: &Pubkey,
26 block_time: u64,
27 slot: u64,
28 index: u64,
29 atomic_instruction_index: u8,
30 ) -> Option<Self> {
31 if !(account1.is_on_curve() && account2.is_on_curve()) {
32 return None;
33 }
34
35 let mut link = [0u8; 64];
36 if account1 < account2 {
37 link[0..32].copy_from_slice(account1.as_ref());
38 link[32..64].copy_from_slice(account2.as_ref());
39 } else if account1 > account2 {
40 link[0..32].copy_from_slice(account2.as_ref());
41 link[32..64].copy_from_slice(account1.as_ref());
42 }
43 else {
45 return None;
46 }
47 Some(Self {
48 link,
49 block_time,
50 slot,
51 index,
52 atomic_instruction_index,
53 })
54 }
55
56 pub fn to_string(&self) -> String {
58 let wallet_1 = Pubkey::new_from_array(self.link[0..32].try_into().expect("slice with incorrect length"));
59 let wallet_2 = Pubkey::new_from_array(self.link[32..64].try_into().expect("slice with incorrect length"));
60 format!(
61 "Wallet 1: {}, Wallet 2: {}, Block Time: {}, Slot: {}, Index: {}, Atomic Instruction Index: {}",
62 wallet_1, wallet_2, self.block_time, self.slot, self.index, self.atomic_instruction_index
63 )
64 }
65}