massa_deferred_calls/
macros.rs1pub(crate) const CALLS_TAG: u8 = 0u8;
2pub(crate) const SLOT_TOTAL_GAS: u8 = 1u8;
4pub(crate) const SLOT_BASE_FEE: u8 = 2u8;
5
6pub(crate) const CALL_FIELD_SENDER_ADDRESS: u8 = 1u8;
8pub(crate) const CALL_FIELD_TARGET_SLOT: u8 = 2u8;
9pub(crate) const CALL_FIELD_TARGET_ADDRESS: u8 = 3u8;
10pub(crate) const CALL_FIELD_TARGET_FUNCTION: u8 = 4u8;
11pub(crate) const CALL_FIELD_PARAMETERS: u8 = 5u8;
12pub(crate) const CALL_FIELD_COINS: u8 = 6u8;
13pub(crate) const CALL_FIELD_MAX_GAS: u8 = 7u8;
14pub(crate) const CALL_FIELD_FEE: u8 = 8u8;
15pub(crate) const CALL_FIELD_CANCELED: u8 = 9u8;
16
17#[macro_export]
18macro_rules! deferred_call_slot_total_gas_key {
19 ($slot:expr) => {
20 [
21 DEFERRED_CALLS_PREFIX.as_bytes(),
22 &$slot[..],
23 &[$crate::macros::SLOT_TOTAL_GAS],
24 ]
25 .concat()
26 };
27}
28
29#[macro_export]
30macro_rules! deferred_call_slot_base_fee_key {
31 ($slot:expr) => {
32 [
33 DEFERRED_CALLS_PREFIX.as_bytes(),
34 &$slot[..],
35 &[$crate::macros::SLOT_BASE_FEE],
36 ]
37 .concat()
38 };
39}
40
41#[macro_export]
42macro_rules! deferred_slot_call_prefix_key {
43 ($slot:expr) => {
44 [
45 DEFERRED_CALLS_PREFIX.as_bytes(),
46 &$slot[..],
47 &[$crate::macros::CALLS_TAG],
48 ]
49 .concat()
50 };
51}
52
53#[macro_export]
54macro_rules! deferred_call_prefix_key {
55 ($id:expr, $slot:expr) => {
56 [&deferred_slot_call_prefix_key!($slot), &$id[..]].concat()
57 };
58}
59
60#[macro_export]
62macro_rules! deferred_call_field_key {
63 ($id:expr, $slot:expr, $field:expr) => {
64 [deferred_call_prefix_key!($id, $slot), vec![$field]].concat()
65 };
66}
67
68#[macro_export]
70macro_rules! sender_address_key {
71 ($id:expr, $slot:expr) => {
72 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_SENDER_ADDRESS)
73 };
74}
75
76#[macro_export]
78macro_rules! target_slot_key {
79 ($id:expr, $slot:expr) => {
80 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_TARGET_SLOT)
81 };
82}
83
84#[macro_export]
86macro_rules! target_address_key {
87 ($id:expr, $slot:expr) => {
88 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_TARGET_ADDRESS)
89 };
90}
91
92#[macro_export]
94macro_rules! target_function_key {
95 ($id:expr, $slot:expr) => {
96 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_TARGET_FUNCTION)
97 };
98}
99
100#[macro_export]
102macro_rules! parameters_key {
103 ($id:expr, $slot:expr) => {
104 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_PARAMETERS)
105 };
106}
107
108#[macro_export]
110macro_rules! coins_key {
111 ($id:expr, $slot:expr) => {
112 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_COINS)
113 };
114}
115
116#[macro_export]
118macro_rules! max_gas_key {
119 ($id:expr, $slot:expr) => {
120 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_MAX_GAS)
121 };
122}
123
124#[macro_export]
126macro_rules! fee_key {
127 ($id:expr, $slot:expr) => {
128 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_FEE)
129 };
130}
131
132#[macro_export]
134macro_rules! cancelled_key {
135 ($id:expr, $slot:expr) => {
136 deferred_call_field_key!($id, $slot, $crate::macros::CALL_FIELD_CANCELED)
137 };
138}
139
140#[cfg(test)]
141mod tests {
142 use massa_db_exports::DEFERRED_CALLS_PREFIX;
143 use massa_models::{
144 deferred_calls::{DeferredCallId, DeferredCallIdSerializer},
145 slot::Slot,
146 };
147 use massa_serialization::Serializer;
148
149 #[test]
150 fn test_deferred_call_prefix_key() {
151 let slot_ser = Slot {
152 period: 1,
153 thread: 5,
154 }
155 .to_bytes_key();
156
157 let id = DeferredCallId::new(
158 0,
159 Slot {
160 thread: 5,
161 period: 1,
162 },
163 1,
164 &[],
165 )
166 .unwrap();
167
168 let id_ser = DeferredCallIdSerializer::new();
169 let mut buf_id = Vec::new();
170 id_ser.serialize(&id, &mut buf_id).unwrap();
171
172 let prefix = ["deferred_calls/".as_bytes(), &slot_ser, &[0u8], &buf_id].concat();
173
174 assert_eq!(deferred_call_prefix_key!(buf_id, slot_ser), prefix);
175
176 }
179}