Last active
March 18, 2019 22:19
-
-
Save tonymorony/b0b2128f4fa5587b9c8f48bf931f5e92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Node preparation for gateway binding: | |
1) Starting and syncing KMD | |
2) Starting gw testing assetchain with valid pubkey | |
3) Import privkey from assetchain to KMD chain | |
4) Save pubkey on assetchain, wallet address and IP as output in text file | |
5) Mine until balance >0, to have some coins for oracle subscribe, then stop mining | |
5) Register as oracle publisher and subscribe X times, wait until these transactions mined | |
Needs gateway binding (in case if gatewaybindtxid passed as script argument): | |
6) Starting oraclefeed with given params | |
""" | |
import json | |
import time | |
import readline | |
import re | |
import sys | |
import platform | |
import os | |
import subprocess | |
# script params | |
# ./komodod -ac_name=GWTEST2 -ac_supply=5555555 -ac_reward=10000000000000 -ac_cc=2 -addnode=159.69.45.70 -daemon | |
test_assetchain = "GWTEST2" | |
oracle_txid = "" | |
def wait_till_chain_ready(asset_chain): | |
while True: | |
try: | |
if asset_chain == "KMD": | |
test_daemon_state = json.loads(subprocess.check_output(["./komodo-cli", "getinfo"])) | |
else: | |
test_daemon_state = json.loads(subprocess.check_output(["./komodo-cli", "-ac_name=" + asset_chain, "getinfo"])) | |
blocks_have = test_daemon_state["blocks"] | |
longest_chain = test_daemon_state["longestchain"] | |
except Exception as e: | |
print(e) | |
time.sleep(10) | |
else: | |
if blocks_have == longest_chain: | |
print(test_assetchain + " succesfully synced") | |
print("Have " + str(blocks_have) + " blocks") | |
print("Longest chain: " + str(longest_chain) + " blocks") | |
break | |
else: | |
print("KMD chain not synced yet") | |
print("Have " + str(blocks_have) + " blocks") | |
print("Longest chain: " + str(longest_chain) + " blocks") | |
time.sleep(10) | |
# starting KMD Daemon | |
subprocess.call(["./komodod", "-daemon"]) | |
# waiting until KMD daemon is ready to interact and synced | |
wait_till_chain_ready("KMD") | |
# starting test_assetchain | |
subprocess.call(["./komodod", "-ac_name="+test_assetchain, "-ac_supply=5555555", "-ac_reward=10000000000000", "-ac_cc=2", "-addnode=159.69.45.70", "-daemon"]) | |
# waiting until test_assetchain daemon is ready to interact and synced | |
wait_till_chain_ready(test_assetchain) | |
# getting assetchain address | |
assetchain_address = subprocess.call(["./komodod", "-ac_name="+test_assetchain, "getnewaddress"]) | |
# getting pubkey for this address | |
assetchain_pubkey = json.loads(subprocess.check_output(["./komodo-cli", "-ac_name="+test_assetchain, "validateaddress", assetchain_address]))["pubkey"] | |
# stopping daemon | |
subprocess.call(["./komodod", "-ac_name="+test_assetchain, "stop"]) | |
time.sleep(5) | |
# restarting with valid pubkey | |
subprocess.call(["./komodod", "-ac_name="+test_assetchain, "-ac_supply=5555555", "-ac_reward=10000000000000", "-ac_cc=2", "-addnode=159.69.45.70", "-pubkey="+assetchain_pubkey, "-daemon"]) | |
# waiting till daemon is ready | |
wait_till_chain_ready(test_assetchain) | |
# ensuring that daemon started with valid pubkey | |
test_daemon_state = json.loads(subprocess.check_output(["./komodo-cli", "-ac_name=" + asset_chain, "getinfo"]))["pubkey"] | |
assert_equal(test_daemon_state, assetchain_pubkey) | |
# saving wallet address and pubkey to file | |
with open("wallet_data.txt", "w+") as file: | |
file.write("Address: " + assetchain_address) | |
file.write("Pubkey: " + assetchain_pubkey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment