1use unc_primitives_core::hash::{hash as sha256, CryptoHash};
2
3pub struct ContractCode {
4 code: Vec<u8>,
5 hash: CryptoHash,
6}
7
8impl ContractCode {
9 pub fn new(code: Vec<u8>, hash: Option<CryptoHash>) -> ContractCode {
10 let hash = hash.unwrap_or_else(|| sha256(&code));
11 debug_assert_eq!(hash, sha256(&code));
12
13 ContractCode { code, hash }
14 }
15
16 pub fn code(&self) -> &[u8] {
17 self.code.as_slice()
18 }
19
20 pub fn into_code(self) -> Vec<u8> {
21 self.code
22 }
23
24 pub fn hash(&self) -> &CryptoHash {
25 &self.hash
26 }
27}