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
use ethereum_types::{Address, U256};

#[derive(Debug, Clone, Copy)]
pub struct Call {
    /// The sender of the call.
    pub sender: Address,
    /// The amount of gas to include in the call.
    pub gas: U256,
    /// The price willing to pay for gas during the call (in WEI).
    pub gas_price: U256,
    /// The amount of ethereum attached to the call (in WEI).
    pub value: U256,
}

impl Call {
    /// Build a new call with the given sender.
    pub fn new(sender: Address) -> Self {
        Self {
            sender,
            gas: 0.into(),
            gas_price: 0.into(),
            value: 0.into(),
        }
    }

    /// Modify sender of call.
    pub fn sender<S: Into<Address>>(self, sender: S) -> Self {
        Self {
            sender: sender.into(),
            ..self
        }
    }

    /// Set the call to have the specified amount of gas.
    pub fn gas<E: Into<U256>>(self, gas: E) -> Self {
        Self {
            gas: gas.into(),
            ..self
        }
    }

    /// Set the call to have the specified gas price.
    pub fn gas_price<E: Into<U256>>(self, gas_price: E) -> Self {
        Self {
            gas_price: gas_price.into(),
            ..self
        }
    }

    /// Set the call to have the specified value.
    pub fn value<E: Into<U256>>(self, value: E) -> Self {
        Self {
            value: value.into(),
            ..self
        }
    }
}