Repository navigation
Expand file tree
/
Copy pathcall_handler.rs
More file actions
76 lines (71 loc) · 2.3 KB
/
Copy pathcall_handler.rs
File metadata and controls
76 lines (71 loc) · 2.3 KB
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
use dlp::{
args::CallHandlerArgs,
discriminator::DlpDiscriminator,
pda::{
ephemeral_balance_pda_from_payer,
validator_fees_vault_pda_from_validator,
},
total_size_budget, AccountSizeClass, DLP_PROGRAM_DATA_SIZE_CLASS,
};
use solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
};
use crate::compat::{borsh::to_vec, Compatize, Modernize};
/// Builds a call handler instruction.
/// See [dlp::processor::call_handler] for docs.
#[deprecated(since = "1.1.4", note = "Use `call_handler_v2` instead")]
pub fn call_handler(
validator: Pubkey,
destination_program: Pubkey,
escrow_authority: Pubkey,
other_accounts: Vec<AccountMeta>,
args: CallHandlerArgs,
) -> Instruction {
let validator_compat = validator.compatize();
let validator_fees_vault_pda =
validator_fees_vault_pda_from_validator(&validator_compat).modernize();
// handler accounts
let escrow_authority_compat = escrow_authority.compatize();
let escrow_account = ephemeral_balance_pda_from_payer(
&escrow_authority_compat,
args.escrow_index,
)
.modernize();
let mut accounts = vec![
AccountMeta::new(validator, true),
AccountMeta::new(validator_fees_vault_pda, false),
AccountMeta::new_readonly(destination_program, false),
AccountMeta::new(escrow_authority, false),
AccountMeta::new(escrow_account, false),
];
// append other accounts at the end
accounts.extend(other_accounts);
Instruction {
program_id: dlp::id().modernize(),
accounts,
data: [
DlpDiscriminator::CallHandler.to_vec(),
to_vec(&args).unwrap(),
]
.concat(),
}
}
///
/// Returns accounts-data-size budget for call_handler instruction.
///
/// This value can be used with ComputeBudgetInstruction::SetLoadedAccountsDataSizeLimit
///
pub fn call_handler_size_budget(
destination_program: AccountSizeClass,
other_accounts: u32,
) -> u32 {
total_size_budget(&[
DLP_PROGRAM_DATA_SIZE_CLASS,
AccountSizeClass::Tiny, // validator
AccountSizeClass::Tiny, // validator_fees_vault_pda
destination_program,
AccountSizeClass::Tiny, // escrow_authority
AccountSizeClass::Tiny, // escrow_account
]) + other_accounts
}