devol_accounts_kit/instructions_data/
dvl_instruction_data.rs1use std::error::Error;
2use crate::instructions_data::dvl_deserializable_instruction::DvlDeserializableInstruction;
3cfg_if::cfg_if! {
4 if #[cfg(not(feature = "on-chain"))] {
5 use crate::instructions_data::as_transaction_instruction::as_transaction_instruction::AsTransactionInstruction;
6 }
7 else {
8 use crate::instructions_data::as_transaction_instruction_on_chain::AsTransactionInstruction;
9 }
10}
11
12
13pub trait DvlInstructionData<'a>: AsTransactionInstruction + DvlDeserializableInstruction<'a> {
14 type DvlInstrParams: 'a;
15 fn new(params: Self::DvlInstrParams) -> Result<Box<Self>, Box<dyn Error>> where Self: Sized;
16
17 fn to_vec_le(&self) -> Vec<u8> where Self: Sized {
18 let data_bytes = unsafe {
19 std::slice::from_raw_parts(self as *const Self as *const u8, std::mem::size_of::<Self>())
20 };
21 data_bytes.to_vec()
22 }
23}
24
25pub struct DvlInstruction;
26
27impl DvlInstruction {
28 pub fn new<'a, T>(params: T::DvlInstrParams) -> Result<Box<T>, Box<dyn Error>>
29 where
30 T: DvlInstructionData<'a>
31 {
32 T::new(params)
33 }
34}