• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jhheider / tea-gpg-wallet / 20044835350

08 Dec 2025 10:24PM UTC coverage: 0.0%. Remained the same
20044835350

Pull #28

github

web-flow
Merge 00806b34c into 3dff71edc
Pull Request #28: Bump actions/checkout from 5 to 6

0 of 412 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/src/utils.rs
1
use reqwest::Url as URL;
2
use std::str::FromStr;
3

4
use alloy::primitives::{FixedBytes, U256};
5
use anyhow::{Context, Result, anyhow};
6

7
pub const WEI_PER_ETH: u128 = 1_000_000_000_000_000_000;
8
pub const ETH_DECIMALS: usize = 18;
9

10
#[inline]
11
pub fn get_rpc_url() -> Result<URL> {
×
12
    env!("RPC_URL").parse().context("Invalid RPC URL")
×
13
}
14

15
#[inline]
16
pub fn key_id_to_bytes(key_id: &str) -> Result<FixedBytes<8>> {
×
17
    FixedBytes::from_str(key_id).context("Failed to convert key id to FixedBytes")
×
18
}
19

20
/// Convert a decimal string to U256 representing wei with higher precision
21
/// This method handles larger amounts accurately
22
pub fn decimal_to_wei_precise(amount_str: &str) -> Result<U256> {
×
23
    // Split on decimal point
24
    let parts: Vec<&str> = amount_str.split('.').collect();
×
25

26
    match parts.as_slice() {
×
27
        [whole] => {
×
28
            // No decimal part, just multiply by 10^18
29
            let whole_u256 =
×
30
                U256::from_str_radix(whole, 10).context("Failed to parse whole number")?;
×
31
            Ok(whole_u256 * U256::from(WEI_PER_ETH))
×
32
        }
33
        [whole, decimal] => {
×
34
            // Has decimal part
35
            let whole_u256 =
×
36
                U256::from_str_radix(whole, 10).context("Failed to parse whole number")?;
×
37

38
            // Pad decimal part to 18 digits
39
            let mut padded_decimal = decimal.to_string();
×
40
            while padded_decimal.len() < ETH_DECIMALS {
×
41
                padded_decimal.push('0');
×
42
            }
43
            if padded_decimal.len() > ETH_DECIMALS {
×
44
                padded_decimal.truncate(ETH_DECIMALS);
×
45
            }
46

47
            let decimal_u256 = U256::from_str_radix(&padded_decimal, 10)
×
48
                .context("Failed to parse decimal part")?;
49

50
            Ok(whole_u256 * U256::from(WEI_PER_ETH) + decimal_u256)
×
51
        }
52
        _ => Err(anyhow!("Invalid decimal format")),
×
53
    }
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc