Skip to content

Commit

Permalink
Parse genesis account amount as string
Browse files Browse the repository at this point in the history
Annoyingly `toml` (the crate) doesn't support `u128`
(toml-rs/toml#540), so we instead take
the configured values as strings and parse them into `u128`s
later.
  • Loading branch information
JamesHinshelwood committed Sep 11, 2023
1 parent eb82be5 commit 9e10945
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions config-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ eth_chain_id = 0x8001
consensus_timeout = { secs = 5, nanos = 0 }
genesis_accounts = [
# Accounts with private key 0x1, 0x2, 0x3, 0x4.
["7E5F4552091A69125d5DfCb7b8C2659029395Bdf", 5000000000000000000000],
["2B5AD5c4795c026514f8317c7a215E218DcCD6cF", 5000000000000000000000],
["6813Eb9362372EEF6200f3b1dbC3f819671cBA69", 5000000000000000000000],
["1efF47bc3a10a45D4B230B5d10E37751FE6AA718", 5000000000000000000000],
["7E5F4552091A69125d5DfCb7b8C2659029395Bdf", "5000000000000000000000"],
["2B5AD5c4795c026514f8317c7a215E218DcCD6cF", "5000000000000000000000"],
["6813Eb9362372EEF6200f3b1dbC3f819671cBA69", "5000000000000000000000"],
["1efF47bc3a10a45D4B230B5d10E37751FE6AA718", "5000000000000000000000"],
]

[[nodes]]
Expand Down
8 changes: 4 additions & 4 deletions infra/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ otlp_collector_endpoint = "http://otel-collector:4317"
genesis_committee = [ ["b27aebb3b54effd7af87c4a064a711554ee0f3f5abf56ca910b46422f2b21603bc383d42eb3b927c4c3b0b8381ca30a3", "12D3KooWESMZ2ttSxDwjfnNe23sHCqsJf6sNEKwgHkdgtCHDsbWU"] ]
genesis_accounts = [
# Accounts with private key 0x1, 0x2, 0x3, 0x4.
["7E5F4552091A69125d5DfCb7b8C2659029395Bdf", 5000000000000000000000],
["2B5AD5c4795c026514f8317c7a215E218DcCD6cF", 5000000000000000000000],
["6813Eb9362372EEF6200f3b1dbC3f819671cBA69", 5000000000000000000000],
["1efF47bc3a10a45D4B230B5d10E37751FE6AA718", 5000000000000000000000],
["7E5F4552091A69125d5DfCb7b8C2659029395Bdf", "5000000000000000000000"],
["2B5AD5c4795c026514f8317c7a215E218DcCD6cF", "5000000000000000000000"],
["6813Eb9362372EEF6200f3b1dbC3f819671cBA69", "5000000000000000000000"],
["1efF47bc3a10a45D4B230B5d10E37751FE6AA718", "5000000000000000000000"],
]
2 changes: 1 addition & 1 deletion zilliqa/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct NodeConfig {
/// The maximum time to wait for consensus to proceed as normal, before proposing a new view.
pub consensus_timeout: Duration,
pub genesis_committee: Vec<(NodePublicKey, PeerId)>,
pub genesis_accounts: Vec<(Address, u128)>,
pub genesis_accounts: Vec<(Address, String)>,
}

impl Default for NodeConfig {
Expand Down
4 changes: 2 additions & 2 deletions zilliqa/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct State {
}

impl State {
pub fn new_genesis(database: Tree, genesis_accounts: &[(Address, u128)]) -> Result<State> {
pub fn new_genesis(database: Tree, genesis_accounts: &[(Address, String)]) -> Result<State> {
let db = Arc::new(SledDb::new(database));
let mut state = Self {
db: db.clone(),
Expand All @@ -45,7 +45,7 @@ impl State {
let _ = state.set_gas_price(default_gas_price().into());

for (address, balance) in genesis_accounts {
state.set_native_balance(*address, (*balance).into())?;
state.set_native_balance(*address, balance.parse()?)?;
}

Ok(state)
Expand Down
5 changes: 4 additions & 1 deletion zilliqa/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ fn node(
// Give a genesis account 1 billion ZIL.
genesis_accounts: vec![(
Address(genesis_account),
1_000_000_000u128.checked_mul(10u128.pow(18)).unwrap(),
1_000_000_000u128
.checked_mul(10u128.pow(18))
.unwrap()
.to_string(),
)],
..Default::default()
},
Expand Down

0 comments on commit 9e10945

Please sign in to comment.