alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
763 stars 137 forks source link

[Feature][Primitive] Allow ParseUnits to be converted to u128 #598

Closed NicolasWent closed 3 months ago

NicolasWent commented 5 months ago

Component

primitives

Describe the feature you would like

The gas configurations have been set to u128 instead of U256 in the alloy TransactionBuilder

It would be nice to have an into() implementation for a ParseUnits to convert it directly to u128.

This way we would be able to set the max priority fee per gas (and max_fee_per_gas) more smoothly:

// Currently not working:
my_transaction_builder.max_priority_fee_per_gas(parse_units("0.1", "gwei").unwrap().into());

Instead of the current workaround:

let max_priority_fee_per_gas: U256 = parse_units("0.1", "gwei").unwrap().into();
my_transaction_build.max_priority_fee_per_gas(max_priority_fee_per_gas.to());
DaniPopes commented 5 months ago

This should be TryFrom since 256 -> 128 bits is fallible. Other options: