howmuch_rs/
model.rs

1use std::str::FromStr;
2
3use ethers::types::U256;
4
5use eyre::Result;
6use jsonp::Pointer;
7
8/// A transaction.
9#[derive(Debug)]
10pub struct Transaction(pub String);
11
12/// A transaction receipt.
13#[derive(Debug)]
14pub struct TransactionReceipt(pub String);
15
16impl TransactionReceipt {
17    /// Returns the transaction actual fee.
18    /// # Returns
19    /// The transaction actual fee.
20    pub fn actual_fee(&self) -> Result<U256> {
21        let p = Pointer::default();
22        let raw = self.0.as_str();
23        let actual_fee: &str = p.dotted(raw, ".actual_fee")?;
24        Ok(U256::from_str(actual_fee)?)
25    }
26}
27
28#[derive(Debug)]
29pub struct Block(pub String);
30
31impl Block {
32    /// Returns the block gas price.
33    /// # Returns
34    /// The block gas price.
35    pub fn gas_price(&self) -> Result<U256> {
36        let p = Pointer::default();
37        let raw = self.0.as_str();
38        let gas_used: &str = p.dotted(raw, ".gas_price")?;
39        Ok(U256::from_str(gas_used)?)
40    }
41}