core icon indicating copy to clipboard operation
core copied to clipboard

[Feature] Macros to parse Ether and other units from string to U256

Open cakevm opened this issue 1 year ago • 3 comments

Component

primitives

Describe the feature you would like

Often you have fixed values that could already be parsed during compile time. Currently I am initializing those values using lazy_static. My proposal would be to have macros to parse ether, wei, etc. from a string to U256.

Currently you will write:

let val: U256 = parse_units("0.01", "ether").unwrap().get_absolute();

Proposal:

let val: U256 = ether!("0.01");

If the parsing fails it will throw an error during compile time.

Additional context

No response

cakevm avatar Oct 25 '24 20:10 cakevm