From 9e9bb34aee9c1190ea3147d1c17e1d59e1864809 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Fri, 14 Oct 2022 16:58:46 -0500 Subject: [PATCH] Auto-generate accounts.csv (#25) * Auto-generate accounts.csv --- .../genesis/accounts/accounts.csv | 6 ------ .../genesis/accounts/import_keys.sh | 5 ++--- .../genesis/accounts/mnemonic_to_csv.py | 17 +++++++++++++++++ .../genesis/el/build_el.sh | 4 ++-- .../cerc-fixturenet-eth-geth/run-el.sh | 2 +- .../cerc-fixturenet-eth-lighthouse/Dockerfile | 2 +- .../genesis/cl/vars.env | 2 +- 7 files changed, 24 insertions(+), 14 deletions(-) delete mode 100644 container-build/cerc-fixturenet-eth-geth/genesis/accounts/accounts.csv create mode 100644 container-build/cerc-fixturenet-eth-geth/genesis/accounts/mnemonic_to_csv.py diff --git a/container-build/cerc-fixturenet-eth-geth/genesis/accounts/accounts.csv b/container-build/cerc-fixturenet-eth-geth/genesis/accounts/accounts.csv deleted file mode 100644 index 9f027f71..00000000 --- a/container-build/cerc-fixturenet-eth-geth/genesis/accounts/accounts.csv +++ /dev/null @@ -1,6 +0,0 @@ -m/44'/60'/0'/0/0,0xe6CE22afe802CAf5fF7d3845cec8c736ecc8d61F,0x02cfc16a6212d7bb9dff89b603afbd856157c367de3ef6b626f205d9b150630ea0,0x888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218 -m/44'/60'/0'/0/1,0xe22AD83A0dE117bA0d03d5E94Eb4E0d80a69C62a,0x03481404e1b0541b51468cec6b46baf400a56b3f5c6aeee4a2cc75c8175233fc35,0x570b909da9669b2f35a0b1ac70b8358516d55ae1b5b3710e95e9a94395090597 -m/44'/60'/0'/0/2,0xf1ac8Dd1f6D6F5c0dA99097c57ebF50CD99Ce293,0x02c3ba9ca4321c7ed9dbe9ead24a6b00a79c0e62c1b560e31108ece7ac55f886e5,0x111b7500bdce494d6f4bcfe8c2a0dde2ef92f751d9070fac6475dbd6d8021b3f -m/44'/60'/0'/0/3,0x9d2edB2B30Bce41375179571944A3f92636ce1Cd,0x02b1ff366ff445fe36bc45a37c37c160552442486832036ae95e186b19692999c9,0xfb1e9af328c283ca3e2486e7c24d13582b7912057d8b9542ff41503c85bc05c0 -m/44'/60'/0'/0/4,0x5D81E609c15E292Bb8255bd9b1B2494DC0386062,0x035edb8877dc2c467e5cd5c8d6020d8af8348ad3106a227132bb0843d95628ec09,0xbe4aa664815ea3bc3d63118649a733f6c96b243744310806ecb6d96359ab62cf -m/44'/60'/0'/0/5,0x5929AD4A1d6B899065AcF2a66d5EB086a2863bEe,0x02f8e160837d711d47664264d3ac67be996f71886ded509496172584268c4d3a15,0x6177345b77c4069ac4d553f8b43cf68a799ca4bb63eac93d6cf796d63694ebf0 diff --git a/container-build/cerc-fixturenet-eth-geth/genesis/accounts/import_keys.sh b/container-build/cerc-fixturenet-eth-geth/genesis/accounts/import_keys.sh index 4261338e..719b9f59 100755 --- a/container-build/cerc-fixturenet-eth-geth/genesis/accounts/import_keys.sh +++ b/container-build/cerc-fixturenet-eth-geth/genesis/accounts/import_keys.sh @@ -2,11 +2,10 @@ ACCOUNT_PASSWORD=${ACCOUNT_PASSWORD:-secret1212} -for line in `cat accounts.csv`; do +for line in `cat ../build/el/accounts.csv`; do BIP44_PATH="`echo "$line" | cut -d',' -f1`" ADDRESS="`echo "$line" | cut -d',' -f2`" - PUBLIC_KEY="`echo "$line" | cut -d',' -f3`" - PRIVATE_KEY="`echo "$line" | cut -d',' -f4`" + PRIVATE_KEY="`echo "$line" | cut -d',' -f3`" echo "$ACCOUNT_PASSWORD" > .pw.$$ echo "$PRIVATE_KEY" | sed 's/0x//' > .key.$$ diff --git a/container-build/cerc-fixturenet-eth-geth/genesis/accounts/mnemonic_to_csv.py b/container-build/cerc-fixturenet-eth-geth/genesis/accounts/mnemonic_to_csv.py new file mode 100644 index 00000000..730426bd --- /dev/null +++ b/container-build/cerc-fixturenet-eth-geth/genesis/accounts/mnemonic_to_csv.py @@ -0,0 +1,17 @@ +from web3.auto import w3 +import json +import ruamel.yaml as yaml +import sys + +w3.eth.account.enable_unaudited_hdwallet_features() + +testnet_config_path = "genesis-config.yaml" +if len(sys.argv) > 1: + testnet_config_path = sys.argv[1] + +with open(testnet_config_path) as stream: + data = yaml.safe_load(stream) + +for key, value in data['eth1_premine'].items(): + acct = w3.eth.account.from_mnemonic(data['mnemonic'], account_path=key, passphrase='') + print("%s,%s,%s" % (key, acct.address, acct.key.hex())) diff --git a/container-build/cerc-fixturenet-eth-geth/genesis/el/build_el.sh b/container-build/cerc-fixturenet-eth-geth/genesis/el/build_el.sh index caea1b76..5eeeba51 100755 --- a/container-build/cerc-fixturenet-eth-geth/genesis/el/build_el.sh +++ b/container-build/cerc-fixturenet-eth-geth/genesis/el/build_el.sh @@ -7,6 +7,6 @@ mkdir -p ../build/el tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX) envsubst < el-config.yaml > $tmp_dir/genesis-config.yaml + python3 /apps/el-gen/genesis_geth.py $tmp_dir/genesis-config.yaml > ../build/el/geth.json -python3 /apps/el-gen/genesis_chainspec.py $tmp_dir/genesis-config.yaml > ../build/el/chainspec.json -python3 /apps/el-gen/genesis_besu.py $tmp_dir/genesis-config.yaml > ../build/el/besu.json +python3 ../accounts/mnemonic_to_csv.py $tmp_dir/genesis-config.yaml > ../build/el/accounts.csv diff --git a/container-build/cerc-fixturenet-eth-geth/run-el.sh b/container-build/cerc-fixturenet-eth-geth/run-el.sh index 657dd719..84ff72f4 100755 --- a/container-build/cerc-fixturenet-eth-geth/run-el.sh +++ b/container-build/cerc-fixturenet-eth-geth/run-el.sh @@ -1,6 +1,6 @@ #!/bin/bash -ETHERBASE=`cat /opt/testnet/accounts/accounts.csv | head -1 | cut -d',' -f2` +ETHERBASE=`cat /opt/testnet/build/el/accounts.csv | head -1 | cut -d',' -f2` NETWORK_ID=`cat /opt/testnet/el/el-config.yaml | grep 'chain_id' | awk '{ print $2 }'` if [ "true" == "$RUN_BOOTNODE" ]; then diff --git a/container-build/cerc-fixturenet-eth-lighthouse/Dockerfile b/container-build/cerc-fixturenet-eth-lighthouse/Dockerfile index 7b53397c..08de5537 100644 --- a/container-build/cerc-fixturenet-eth-lighthouse/Dockerfile +++ b/container-build/cerc-fixturenet-eth-lighthouse/Dockerfile @@ -20,7 +20,7 @@ COPY --from=ethgen /usr/local/bin/eth2-testnet-genesis /usr/local/bin/eth2-testn COPY --from=ethgen /usr/local/bin/eth2-val-tools /usr/local/bin/eth2-val-tools COPY --from=ethgen /apps /apps COPY --from=fnetgeth /opt/testnet/el /opt/testnet/el -COPY --from=fnetgeth /opt/testnet/accounts /opt/testnet/accounts +COPY --from=fnetgeth /opt/testnet/build/el /opt/testnet/build/el RUN cd /opt/testnet && make genesis-cl diff --git a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/vars.env b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/vars.env index ccc82028..b7e2a939 100644 --- a/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/vars.env +++ b/container-build/cerc-fixturenet-eth-lighthouse/genesis/cl/vars.env @@ -49,4 +49,4 @@ ETH1_CHAIN_ID=${ETH1_CHAIN_ID:-`cat $ETH1_CONFIG_YAML | grep 'chain_id' | awk '{ ETH1_TTD=${ETH1_TTD:-`cat $ETH1_CONFIG_YAML | grep 'terminal_total_difficulty' | awk '{ print $2 }'`} ETH1_DEPOSIT_CONTRACT_ADDRESS=${ETH1_DEPOSIT_CONTRACT_ADDRESS:-`cat $ETH1_CONFIG_YAML | grep 'deposit_contract_address' | awk '{ print $2 }' | sed 's/"//g'`} ETH1_DEPOSIT_CONTRACT_BLOCK=${ETH1_DEPOSIT_CONTRACT_BLOCK:-0x0} -SUGGESTED_FEE_RECIPIENT=`cat ../accounts/accounts.csv | head -1 | cut -d',' -f2` +SUGGESTED_FEE_RECIPIENT=`cat ../build/el/accounts.csv | head -1 | cut -d',' -f2`