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
use ethers::types::{Address, Eip1559TransactionRequest, U256};
use std::fmt::Debug;

#[derive(Clone, Debug)]
pub struct TransferRequest {
    pub amount: U256,
    pub to: Address,
    pub from: Address,
}

impl TransferRequest {
    pub fn new(amount: U256) -> Self {
        Self {
            amount,
            to: Default::default(),
            from: Default::default(),
        }
    }

    pub fn from(mut self, from: Address) -> Self {
        self.from = from;
        self
    }

    pub fn to(mut self, to: Address) -> Self {
        self.to = to;
        self
    }

    pub fn amount(mut self, amount: U256) -> Self {
        self.amount = amount;
        self
    }
}

impl From<TransferRequest> for Eip1559TransactionRequest {
    fn from(request: TransferRequest) -> Eip1559TransactionRequest {
        Eip1559TransactionRequest::new()
            .to(request.to)
            .value(request.amount)
            .from(request.from)
    }
}