devol_accounts_kit/instructions_data/constructors/
withdraw_token.rs1use std::error::Error;
2use crate::instructions_data::dvl_instruction_data::DvlInstructionData;
3use crate::instructions_data::instructions::Instructions;
4use crate::instructions_data::withdraw_token::{INSTRUCTION_WITHDRAW_TOKEN_VERSION, InstructionWithdrawToken};
5
6pub struct WithdrawTokenParams {
7 pub mint_id: u32,
8 pub amount: u64,
9}
10
11impl<'a> DvlInstructionData<'a> for InstructionWithdrawToken {
12
13 type DvlInstrParams = WithdrawTokenParams;
14
15 fn new(params: Self::DvlInstrParams) -> Result<Box<InstructionWithdrawToken>, Box<dyn Error>> {
16 Ok(Box::new(InstructionWithdrawToken {
17 cmd: Instructions::WithdrawToken as u8,
18 version: INSTRUCTION_WITHDRAW_TOKEN_VERSION,
19 reserved: [0; 2],
20 mint_id: params.mint_id,
21 amount: params.amount,
22 }))
23 }
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29 use crate::instructions_data::dvl_instruction_data::DvlInstruction;
30
31 #[test]
32 fn test_instruction_withdraw_token_params() {
33 const TEST_MINT_ID: u32 = 1;
34 const TEST_AMOUNT: u64 = 2;
35
36 let withdraw_token_params = WithdrawTokenParams {
37 mint_id: TEST_MINT_ID,
38 amount: TEST_AMOUNT,
39 };
40 let data = DvlInstruction::new::<InstructionWithdrawToken>(withdraw_token_params).unwrap();
41 assert_eq!(data.cmd, Instructions::WithdrawToken as u8);
42 assert_eq!(data.version, INSTRUCTION_WITHDRAW_TOKEN_VERSION);
43 assert_eq!(data.mint_id, TEST_MINT_ID);
44 assert_eq!(data.amount, TEST_AMOUNT);
45 }
46}