Skip to content

Commit

Permalink
Merge pull request #73 from lyfsn/master-pr
Browse files Browse the repository at this point in the history
feat: Added support for all 'alloc' fields in EL premine addresses
  • Loading branch information
parithosh authored Dec 5, 2023
2 parents aaa17d7 + 1bfc70c commit 166fafa
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 10 deletions.
34 changes: 30 additions & 4 deletions apps/el-gen/genesis_besu.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,36 @@
out["alloc"][acct.address] = {"balance": weival}


# Some hardcoded addrs
for key, value in data['el_premine_addrs'].items():
weival = value.replace('ETH', '0' * 18)
out["alloc"][key] = {"balance": weival}
# Some hardcoded addrs
for addr, account in data['el_premine_addrs'].items():
# Convert balance format
if isinstance(account, dict) and 'balance' in account:
balance_value = account['balance'].replace('ETH', '0' * 18)
else:
# If it's not a dictionary, assume it's a single value for backward compatibility
balance_value = account.replace('ETH', '0' * 18)

# Create alloc dictionary entry
alloc_entry = {"balance": balance_value}

# Optionally add code
if 'code' in account:
alloc_entry['code'] = account['code']

# Optionally add storage
if 'storage' in account:
alloc_entry['storage'] = account['storage']

# Optionally set nonce
if 'nonce' in account:
alloc_entry['nonce'] = account['nonce']

# Optionally set private key
if 'secretKey' in account:
alloc_entry['secretKey'] = account['secretKey']

# Add alloc entry to output's alloc field
out["alloc"][addr] = alloc_entry

out['config']['ethash'] = {}
out['config']['cancunTime'] = int(data['genesis_timestamp']) + int(data['genesis_delay']) + (int(data['deneb_fork_epoch']) * 32 * int(data['slot_duration_in_seconds']))
Expand Down
32 changes: 29 additions & 3 deletions apps/el-gen/genesis_chainspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,35 @@
out["accounts"][acct.address] = {"balance": weival}

# Some hardcoded addrs
for key, value in data['el_premine_addrs'].items():
weival = value.replace('ETH', '0' * 18)
out["accounts"][key] = {"balance": weival}
for addr, account in data['el_premine_addrs'].items():
# Convert balance format
if isinstance(account, dict) and 'balance' in account:
balance_value = account['balance'].replace('ETH', '0' * 18)
else:
# If it's not a dictionary, assume it's a single value for backward compatibility
balance_value = account.replace('ETH', '0' * 18)

# Create alloc dictionary entry
alloc_entry = {"balance": balance_value}

# Optionally add code
if 'code' in account:
alloc_entry['code'] = account['code']

# Optionally add storage
if 'storage' in account:
alloc_entry['storage'] = account['storage']

# Optionally set nonce
if 'nonce' in account:
alloc_entry['nonce'] = account['nonce']

# Optionally set private key
if 'secretKey' in account:
alloc_entry['secretKey'] = account['secretKey']

# Add alloc entry to output's alloc field
out["accounts"][addr] = alloc_entry

out['params']['eip4844TransitionTimestamp']= hex(int(data['genesis_timestamp']) + int(data['genesis_delay']) + (int(data['deneb_fork_epoch']) * 32 * int(data['slot_duration_in_seconds'])))
out['params']['eip4788TransitionTimestamp']= hex(int(data['genesis_timestamp']) + int(data['genesis_delay']) + (int(data['deneb_fork_epoch']) * 32 * int(data['slot_duration_in_seconds'])))
Expand Down
33 changes: 30 additions & 3 deletions apps/el-gen/genesis_geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,36 @@
out["alloc"][acct.address] = {"balance": weival}

# Some hardcoded addrs
for key, value in data['el_premine_addrs'].items():
weival = value.replace('ETH', '0' * 18)
out["alloc"][key] = {"balance": weival}
for addr, account in data['el_premine_addrs'].items():
# Convert balance format
if isinstance(account, dict) and 'balance' in account:
balance_value = account['balance'].replace('ETH', '0' * 18)
else:
# If it's not a dictionary, assume it's a single value for backward compatibility
balance_value = account.replace('ETH', '0' * 18)

# Create alloc dictionary entry
alloc_entry = {"balance": balance_value}

# Optionally add code
if 'code' in account:
alloc_entry['code'] = account['code']

# Optionally add storage
if 'storage' in account:
alloc_entry['storage'] = account['storage']

# Optionally set nonce
if 'nonce' in account:
alloc_entry['nonce'] = account['nonce']

# Optionally set private key
if 'secretKey' in account:
alloc_entry['secretKey'] = account['secretKey']

# Add alloc entry to output's alloc field
out["alloc"][addr] = alloc_entry


out['config']['cancunTime'] = int(data['genesis_timestamp']) + int(data['genesis_delay']) + (int(data['deneb_fork_epoch']) * 32 * int(data['slot_duration_in_seconds']))
print(json.dumps(out, indent=' '))

0 comments on commit 166fafa

Please sign in to comment.