1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;
use solana_sdk_ids::system_program;
use switchboard_common::cfg_client;
use crate::anchor_traits::*;
use crate::find_lut_signer;
use crate::prelude::*;
pub struct QueueResetLut {}
#[derive(Clone, BorshSerialize, Debug)]
pub struct QueueResetLutParams {
pub recent_slot: u64,
}
impl InstructionData for QueueResetLutParams {}
const DISCRIMINATOR: &[u8] = &[126, 234, 176, 75, 38, 211, 204, 53];
impl Discriminator for QueueResetLut {
const DISCRIMINATOR: &[u8] = DISCRIMINATOR;
}
impl Discriminator for QueueResetLutParams {
const DISCRIMINATOR: &[u8] = DISCRIMINATOR;
}
#[derive(Clone, BorshSerialize, Debug)]
pub struct QueueResetLutArgs {
pub queue: Pubkey,
pub authority: Pubkey,
pub payer: Pubkey,
pub recent_slot: u64,
}
pub struct QueueResetLutAccounts {
pub queue: Pubkey,
pub authority: Pubkey,
pub payer: Pubkey,
pub recent_slot: u64,
}
impl ToAccountMetas for QueueResetLutAccounts {
fn to_account_metas(&self, _: Option<bool>) -> Vec<AccountMeta> {
let program_state = State::get_pda();
let system_program = system_program::id();
let address_lookup_table_program = solana_program::address_lookup_table::program::id();
let lut_signer = find_lut_signer(&self.queue);
fn derive_lookup_table_address(
authority_address: &Pubkey,
recent_block_slot: u64,
) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[authority_address.as_ref(), &recent_block_slot.to_le_bytes()],
&solana_program::address_lookup_table::program::id(),
)
}
vec![
AccountMeta::new(self.queue, false),
AccountMeta::new_readonly(self.authority, true),
AccountMeta::new(self.payer, true),
AccountMeta::new_readonly(system_program.to_bytes().into(), false),
AccountMeta::new_readonly(program_state, false),
AccountMeta::new_readonly(lut_signer, false),
AccountMeta::new(
derive_lookup_table_address(&lut_signer, self.recent_slot).0,
false,
),
AccountMeta::new_readonly(address_lookup_table_program.to_bytes().into(), false),
]
}
}
cfg_client! {
use solana_client::nonblocking::rpc_client::RpcClient;
// use crate::get_sb_program_id; // Commented out due to unused import
use solana_program::address_lookup_table::AddressLookupTableAccount;
// fn derive_lookup_table_address(authority_address: &Pubkey, recent_block_slot: u64) -> (Pubkey, u8) {
// Pubkey::find_program_address(
// &[authority_address.as_ref(), &recent_block_slot.to_le_bytes()],
// &solana_program::address_lookup_table::program::id(),
// )
// }
impl QueueResetLut {
// TODO: Fix serialization errors - commented out due to missing trait implementations
/*
pub async fn build_ix(client: &RpcClient, args: QueueResetLutArgs) -> Result<Instruction, OnDemandError> {
let pid = if crate::utils::is_devnet() {
get_sb_program_id("devnet")
} else {
get_sb_program_id("mainnet")
};
let lut_signer = find_lut_signer(&args.queue);
let (lut_address, _) = derive_lookup_table_address(&lut_signer, args.recent_slot);
let program_state = State::get_pda();
let system_program = system_program::id();
let address_lookup_table_program = solana_program::address_lookup_table::program::id();
let accounts = vec![
AccountMeta::new(args.queue, false),
AccountMeta::new_readonly(args.authority, true),
AccountMeta::new(args.payer, true),
AccountMeta::new_readonly(system_program.to_bytes().into(), false),
AccountMeta::new_readonly(program_state, false),
AccountMeta::new_readonly(lut_signer, false),
AccountMeta::new(lut_address, false),
AccountMeta::new_readonly(address_lookup_table_program.to_bytes().into(), false),
];
Ok(Instruction {
program_id: pid,
accounts,
data: [
QueueResetLut::DISCRIMINATOR,
&QueueResetLutParams {
recent_slot: args.recent_slot,
}.try_to_vec().map_err(|_| OnDemandError::SerializationError)?
].concat(),
})
}
*/
pub async fn fetch_luts(client: &RpcClient, args: QueueResetLutArgs) -> Result<Vec<AddressLookupTableAccount>, OnDemandError> {
let queue_data = QueueAccountData::fetch_async(client, args.queue).await?;
let queue_lut = queue_data.fetch_lut(&args.queue, client).await?;
Ok(vec![queue_lut])
}
}
}