embark: Support unit parsing in all relevant configs (e.g "10 ether", "200 wei", etc..)
Outline
A lot of configurations in embark need to define an amount in wei. The goal of this task is to support specifying these values as a nice string of the type “<number> <unit>” for e.g “200 finney”. The code for this is already available in embark in the utils class here. The goal is to support this feature in all the required configs.
Acceptance Criteria
- support “<number> <unit>” config
**
unitcan be:wei,kwei,Kwei,babbage,femtoether,mwei,Mwei,lovelace,picoether,gwei,Gwei,shannon,nanoether,nano,szabo,microether,micro,finney,milliether,milli,ether,kether,grand,mether,gether,tether** in the following fields: ***config/blockchain.js:gasPrice***config/contracts.js:gasPrice*** any other relevant fields - if the config value is a) not a string nor b) the unit is not specified nor c) is a string starting with ‘0x’ then the value should be assumed to be in
wei
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 23 (7 by maintainers)
@kpulkit29 It is indeed a bit hard to follow if you aren’t familiar with the codebase (neither am I). However, I did some digging and I think what needs to be done is this:
@iurimatias mentioned that a lot of gas related configurations in embark need to be defined in Wei. AFAICT, he’s referring to configuration options like
gas,gasLimitandtargetGasLimit. Notice that those options are used incontracts.json,genesis.jsonandblockchain.jsonrespectively. Every embark project has these files.Now, you can see that all of these options define their value in different formats, sometimes it’s a string (
"auto"), sometimes it’s a hex string ("0x...") and sometimes it can be a number (800000). All of these values are just different representations. A value can be represented as hex code, binary or decimal number.Specifying values in Wei can be quite cumbersome, considering how huge the numbers can get (1 Ether = 1,000,000,000,000,000,000 Wei (10^18)), that’s why programs often us hex codes to make values easier to read, parse and digest. For humans, it’d be even better if one could say
"1 ether"instead of1000000000000000000, or use any other unit that makes sense (Gwei, shannon, finney etc.)It turns out that embark already comes with utility functions to take such a human readable string representation and turn that into the Wei format that embark needs to do its work. One of those functions is
getWeiBalanceFromString()So what needs to be done is find the places where those configuration files are being loaded (e.g. here and here) and pipe their
gas,gasLimitandtargetGasLimitvalues through the utility function before they get merge into the overall configuration object, which essentially results in users being able to specify their values in human readable formats 😃To be fair, I couldn’t find a configuration option for
gasPricein the codebase that is configurable for users/consumers, but I’m sure @iurimatias can shed some light into darkness here.I hope this makes sense and @iurimatias and @jrainville please correct me here if anything of this is wrong!
Does this help @kpulkit29 ?