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