From 1bfc70c7c6dc3ca1da6534f9a9efbdd963ae4d4c Mon Sep 17 00:00:00 2001 From: wangyufsn Date: Thu, 9 Nov 2023 15:43:46 +0800 Subject: [PATCH] feat: Added support for all 'alloc' fields in EL premine addresses --- apps/el-gen/genesis_besu.py | 34 ++++++++++++++++++++++++++++---- apps/el-gen/genesis_chainspec.py | 32 +++++++++++++++++++++++++++--- apps/el-gen/genesis_geth.py | 33 ++++++++++++++++++++++++++++--- 3 files changed, 89 insertions(+), 10 deletions(-) diff --git a/apps/el-gen/genesis_besu.py b/apps/el-gen/genesis_besu.py index 88f33ef..27e7483 100644 --- a/apps/el-gen/genesis_besu.py +++ b/apps/el-gen/genesis_besu.py @@ -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'])) diff --git a/apps/el-gen/genesis_chainspec.py b/apps/el-gen/genesis_chainspec.py index ef7f2a5..081ab5e 100644 --- a/apps/el-gen/genesis_chainspec.py +++ b/apps/el-gen/genesis_chainspec.py @@ -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']))) diff --git a/apps/el-gen/genesis_geth.py b/apps/el-gen/genesis_geth.py index 3beb3b7..54a5479 100644 --- a/apps/el-gen/genesis_geth.py +++ b/apps/el-gen/genesis_geth.py @@ -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=' '))