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
use canonical::Canon;
use canonical_derive::Canon;
pub use dusk_abi::{ContractId, ContractState};
#[derive(Clone, Canon)]
pub struct Contract {
state: ContractState,
code: Vec<u8>,
}
impl Contract {
pub fn new<State, Code>(state: State, code: Code) -> Self
where
State: Canon,
Code: Into<Vec<u8>>,
{
Contract {
state: ContractState::from_canon(&state),
code: code.into(),
}
}
pub fn bytecode(&self) -> &[u8] {
&self.code
}
pub fn state(&self) -> &ContractState {
&self.state
}
pub fn state_mut(&mut self) -> &mut ContractState {
&mut self.state
}
}