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
use crate::Sandbox;
use ceres_std::Vec;
use parity_scale_codec::{Decode, Encode};
#[derive(Default, Clone, Decode, Encode)]
pub struct GasMeter {
pub gas_limit: u64,
pub gas_left: u64,
}
impl GasMeter {
pub fn new(gas: u64) -> GasMeter {
GasMeter {
gas_limit: gas,
gas_left: gas,
}
}
pub fn gas_left_bytes(&self) -> Vec<u8> {
self.gas_left.encode()
}
pub fn with_nested<R, F>(&mut self, amount: u64, f: F) -> R
where
F: FnOnce(Option<&mut GasMeter>) -> R,
{
if self.gas_left < amount {
f(None)
} else {
self.gas_left -= amount;
let mut nested = GasMeter::new(amount);
let r = f(Some(&mut nested));
self.gas_left += nested.gas_left;
r
}
}
}
#[derive(Default, Clone, Encode, Decode, PartialEq, Eq)]
pub struct RentParams {
total_balance: u64,
free_balance: u64,
subsistence_threshold: u64,
deposit_per_contract: u64,
deposit_per_storage_byte: u64,
deposit_per_storage_item: u64,
rent_allowance: u64,
rent_fraction: u16,
storage_size: u32,
code_size: u32,
code_refcount: u32,
_reserved: Option<()>,
}
impl Sandbox {
pub fn tombstone_deposit(&self) -> [u8; 32] {
[1; 32]
}
pub fn rent_allowance(&self) -> [u8; 32] {
self.ext.rent_allowance
}
pub fn set_rent_allowance(&mut self, rent_allowence: [u8; 32]) {
self.ext.rent_allowance = rent_allowence;
}
pub fn rent_params(&self) -> Vec<u8> {
self.ext.rent_params.encode()
}
}