t3rn_sdk_primitives/
state.rs1use crate::{storage::BoundedVec, xc::Chain, BTreeMap, Debug, Vec, MAX_PARAMETERS_IN_FUNCTION};
2use codec::{Decode, Encode, MaxEncodedLen};
3use t3rn_types::side_effect::SideEffect;
4
5#[derive(Encode, Decode, MaxEncodedLen)]
7pub struct SideEffects<AccountId, Balance, Hash>
8where
9 Hash: Encode + Decode,
10 AccountId: Encode + Decode,
11 Balance: Encode + Decode,
12{
13 pub execution_id: Hash,
15 pub side_effects: BoundedVec<Chain<AccountId, Balance, Hash>, MAX_PARAMETERS_IN_FUNCTION>,
17}
18
19#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug, Default)]
22pub struct ExecutionState<Hash>
23where
24 Hash: Encode + Decode + Debug + Clone + PartialEq + Eq,
25{
26 pub state: BTreeMap<[u8; 32], Vec<u8>>,
28 pub side_effects: Vec<Vec<SideEffect<[u8; 32], u64, u128>>>,
30 pub steps_cnt: (u32, u32),
32 pub execution_id: Hash,
34}
35
36pub trait GetExecutionId<Hash>
38where
39 Hash: Encode + Decode + Debug + Clone + PartialEq + Eq,
40{
41 fn get_execution_id(&self) -> &Hash;
42}
43
44impl<Hash> GetExecutionId<Hash> for ExecutionState<Hash>
45where
46 Hash: Encode + Decode + Debug + Clone + PartialEq + Eq,
47{
48 fn get_execution_id(&self) -> &Hash {
49 &self.execution_id
50 }
51}
52
53pub trait GetSteps {
55 fn get_index(&self) -> u32;
56
57 fn get_len(&self) -> u32;
58
59 fn reached_end(&self) -> bool;
60}
61
62impl<Hash> GetSteps for ExecutionState<Hash>
63where
64 Hash: Encode + Decode + Debug + Clone + PartialEq + Eq,
65{
66 fn get_index(&self) -> u32 {
67 self.steps_cnt.0
68 }
69
70 fn get_len(&self) -> u32 {
71 self.steps_cnt.1
72 }
73
74 fn reached_end(&self) -> bool {
75 self.steps_cnt.0 >= self.steps_cnt.1
76 }
77}
78
79pub trait Getters<Hash>: GetExecutionId<Hash> + GetSteps
81where
82 Hash: Encode + Decode + Debug + Clone + PartialEq + Eq,
83{
84}
85
86impl<Hash> Getters<Hash> for ExecutionState<Hash> where
87 Hash: Encode + Decode + Debug + Clone + PartialEq + Eq
88{
89}