1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use crate::serializer::{
Packer,
Encoder,
Decoder,
};
use crate::structs::{
TimePointSec,
};
use crate::varint::{
VarUint32,
};
use crate::action::{
Action,
};
use crate::{
vec::Vec,
};
#[cfg_attr(feature = "std", derive(crate::eosio_scale_info::TypeInfo))]
#[derive(Clone, Eq, PartialEq, Default)]
pub struct TransactionExtension {
ty: u16,
data: Vec<u8>,
}
impl Packer for TransactionExtension {
fn size(&self) -> usize {
let mut _size: usize = 0;
_size += self.ty.size();
_size += self.data.size();
return _size;
}
fn pack(&self) -> Vec<u8> {
let mut enc = Encoder::new(self.size());
enc.pack::<u16>(&self.ty);
enc.pack::<Vec<u8>>(&self.data);
return enc.get_bytes();
}
fn unpack(&mut self, data: &[u8]) -> usize {
let mut dec = Decoder::new(data);
dec.unpack::<u16>(&mut self.ty);
dec.unpack::<Vec<u8>>(&mut self.data);
return dec.get_pos();
}
}
#[cfg_attr(feature = "std", derive(crate::eosio_scale_info::TypeInfo))]
#[derive(Clone, Eq, PartialEq, Default)]
pub struct Transaction {
expiration: TimePointSec,
ref_block_num: u16,
ref_block_prefix: u32,
max_net_usage_words: VarUint32, max_cpu_usage_ms: u8, delay_sec: VarUint32, context_free_actions: Vec<Action>,
actions: Vec<Action>,
extention: Vec<TransactionExtension>,
}
impl Transaction {
pub fn expiration(&self) -> TimePointSec {
return self.expiration;
}
pub fn ref_block_num(&self) -> u32 {
return self.ref_block_num as u32;
}
pub fn ref_block_prefix(&self) -> u32 {
return self.ref_block_prefix;
}
pub fn max_net_usage_words(&self) -> u32 {
return self.max_net_usage_words.value();
}
pub fn max_cpu_usage_ms(&self) -> u32 {
return self.max_cpu_usage_ms as u32;
}
pub fn delay_sec(&self) -> u32 {
return self.delay_sec.value();
}
pub fn actions(&self) -> Vec<Action> {
return self.actions.clone();
}
pub fn context_free_actions(&self) -> Vec<Action> {
return self.context_free_actions.clone();
}
pub fn extention(&self) -> Vec<TransactionExtension> {
return self.extention.clone();
}
}
impl Packer for Transaction {
fn size(&self) -> usize {
let mut _size: usize = 0;
_size += self.expiration.size();
_size += self.ref_block_num.size();
_size += self.ref_block_prefix.size();
_size += self.max_net_usage_words.size();
_size += self.max_cpu_usage_ms.size();
_size += self.delay_sec.size();
_size += self.context_free_actions.size();
_size += self.actions.size();
_size += self.extention.size();
return _size;
}
fn pack(&self) -> Vec<u8> {
let mut enc = Encoder::new(self.size());
enc.pack::<TimePointSec>(&self.expiration);
enc.pack::<u16>(&self.ref_block_num);
enc.pack::<u32>(&self.ref_block_prefix);
enc.pack::<VarUint32>(&self.max_net_usage_words);
enc.pack::<u8>(&self.max_cpu_usage_ms);
enc.pack::<VarUint32>(&self.delay_sec);
enc.pack::<Vec<Action>>(&self.context_free_actions);
enc.pack::<Vec<Action>>(&self.actions);
enc.pack::<Vec<TransactionExtension>>(&self.extention);
return enc.get_bytes();
}
fn unpack(&mut self, data: &[u8]) -> usize {
let mut dec = Decoder::new(data);
dec.unpack::<TimePointSec>(&mut self.expiration);
dec.unpack::<u16>(&mut self.ref_block_num);
dec.unpack::<u32>(&mut self.ref_block_prefix);
dec.unpack::<VarUint32>(&mut self.max_net_usage_words);
dec.unpack::<u8>(&mut self.max_cpu_usage_ms);
dec.unpack::<VarUint32>(&mut self.delay_sec);
dec.unpack::<Vec<Action>>(&mut self.context_free_actions);
dec.unpack::<Vec<Action>>(&mut self.actions);
dec.unpack::<Vec<TransactionExtension>>(&mut self.extention);
return dec.get_pos();
}
}