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
use casper_types::bytesrepr::{self, FromBytes, ToBytes};
use datasize::DataSize;
use rand::{distributions::Standard, prelude::*, Rng};
use serde::{Deserialize, Serialize};
const DEFAULT_PAY_COST: u32 = 10_000;
#[derive(Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Debug, DataSize)]
pub struct StandardPaymentCosts {
pub pay: u32,
}
impl Default for StandardPaymentCosts {
fn default() -> Self {
Self {
pay: DEFAULT_PAY_COST,
}
}
}
impl ToBytes for StandardPaymentCosts {
fn to_bytes(&self) -> Result<Vec<u8>, casper_types::bytesrepr::Error> {
let mut ret = bytesrepr::unchecked_allocate_buffer(self);
ret.append(&mut self.pay.to_bytes()?);
Ok(ret)
}
fn serialized_length(&self) -> usize {
self.pay.serialized_length()
}
}
impl FromBytes for StandardPaymentCosts {
fn from_bytes(bytes: &[u8]) -> Result<(Self, &[u8]), casper_types::bytesrepr::Error> {
let (pay, rem) = FromBytes::from_bytes(bytes)?;
Ok((Self { pay }, rem))
}
}
impl Distribution<StandardPaymentCosts> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> StandardPaymentCosts {
StandardPaymentCosts { pay: rng.gen() }
}
}
#[doc(hidden)]
#[cfg(any(feature = "gens", test))]
pub mod gens {
use proptest::{num, prop_compose};
use super::StandardPaymentCosts;
prop_compose! {
pub fn standard_payment_costs_arb()(
pay in num::u32::ANY,
) -> StandardPaymentCosts {
StandardPaymentCosts {
pay,
}
}
}
}