mirror of
https://gitlab.com/pulsechaincom/staking-deposit-cli.git
synced 2024-12-22 11:41:06 +00:00
56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
|
import asyncio
|
||
|
import os
|
||
|
|
||
|
# For not importing eth2deposit here
|
||
|
DEFAULT_VALIDATOR_KEYS_FOLDER_NAME = 'validator_keys'
|
||
|
|
||
|
|
||
|
async def main():
|
||
|
my_folder_path = os.path.join(os.getcwd(), 'TESTING_TEMP_FOLDER')
|
||
|
if not os.path.exists(my_folder_path):
|
||
|
os.mkdir(my_folder_path)
|
||
|
|
||
|
cmd_args = [
|
||
|
'./deposit.sh',
|
||
|
'--num_validators', '1',
|
||
|
'--mnemonic_language', 'english',
|
||
|
'--password', 'MyPassword',
|
||
|
'--folder', my_folder_path,
|
||
|
]
|
||
|
proc = await asyncio.create_subprocess_shell(
|
||
|
' '.join(cmd_args),
|
||
|
stdin=asyncio.subprocess.PIPE,
|
||
|
stdout=asyncio.subprocess.PIPE,
|
||
|
)
|
||
|
|
||
|
seed_phrase = ''
|
||
|
parsing = False
|
||
|
async for out in proc.stdout:
|
||
|
output = out.decode('utf-8').rstrip()
|
||
|
if output.startswith("This is your seed phrase."):
|
||
|
parsing = True
|
||
|
elif output.startswith("Please type your mnemonic"):
|
||
|
parsing = False
|
||
|
elif parsing:
|
||
|
seed_phrase += output
|
||
|
if len(seed_phrase) > 0:
|
||
|
encoded_phrase = seed_phrase.encode()
|
||
|
proc.stdin.write(encoded_phrase)
|
||
|
proc.stdin.write(b'\n')
|
||
|
print(output)
|
||
|
|
||
|
assert len(seed_phrase) > 0
|
||
|
|
||
|
# Check files
|
||
|
validator_keys_folder_path = os.path.join(my_folder_path, DEFAULT_VALIDATOR_KEYS_FOLDER_NAME)
|
||
|
_, _, key_files = next(os.walk(validator_keys_folder_path))
|
||
|
|
||
|
# Clean up
|
||
|
for key_file_name in key_files:
|
||
|
os.remove(os.path.join(validator_keys_folder_path, key_file_name))
|
||
|
os.rmdir(validator_keys_folder_path)
|
||
|
os.rmdir(my_folder_path)
|
||
|
|
||
|
|
||
|
asyncio.run(main())
|