Skip to content

Commit

Permalink
Standard eosio.py fixing issue #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariusz Kedzierski committed Nov 5, 2018
1 parent 6e59587 commit 884df0c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 71 deletions.
62 changes: 30 additions & 32 deletions cd-scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,47 +551,45 @@ def configure_genesis_json():
out_f.write(dst)

def initialize_beos():
import asyncio
import async_eosio
import eosio
try:
loop = asyncio.get_event_loop()
result = loop.run_until_complete(async_eosio.run_keosd(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT, config.DEFAULT_WALLET_DIR))
result = loop.run_until_complete(async_eosio.create_wallet("http://{0}:{1}".format(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT)))
result = loop.run_until_complete(async_eosio.run_nodeos(config.START_NODE_INDEX, "eosio", config.EOSIO_PUBLIC_KEY))

result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.msig", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.names", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.saving", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.vpay", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.unregd", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))

result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.bpay", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
eosio.run_keosd(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT, config.DEFAULT_WALLET_DIR)
eosio.create_wallet("http://{0}:{1}".format(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT), False)
eosio.run_nodeos(config.START_NODE_INDEX, "eosio", config.EOSIO_PUBLIC_KEY)

eosio.create_account("eosio", "eosio.msig", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)
eosio.create_account("eosio", "eosio.names", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)
eosio.create_account("eosio", "eosio.saving", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)
eosio.create_account("eosio", "eosio.vpay", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)
eosio.create_account("eosio", "eosio.unregd", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)

eosio.create_account("eosio", "eosio.bpay", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)

result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.ram", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.ramfee", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.stake", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
eosio.create_account("eosio", "eosio.ram", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)
eosio.create_account("eosio", "eosio.ramfee", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)
eosio.create_account("eosio", "eosio.stake", config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)

result = loop.run_until_complete(async_eosio.create_account("eosio", "eosio.token", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY))
result = loop.run_until_complete(async_eosio.create_account("eosio", "beos.init", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY))
eosio.create_account("eosio", "eosio.token", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_ACTIVE_PUBLIC_KEY)
eosio.create_account("eosio", "beos.init", config.EOSIO_PUBLIC_KEY, config.COMMON_SYSTEM_ACCOUNT_OWNER_PUBLIC_KEY)

result = loop.run_until_complete(async_eosio.set_contract("eosio.token", config.CONTRACTS_DIR + "/eosio.token", "eosio.token"))
eosio.set_contract("eosio.token", config.CONTRACTS_DIR + "/eosio.token", "eosio.token")

result = loop.run_until_complete(async_eosio.push_action("eosio.token", "create", '[ "beos.distrib", "{0} {1}"]'.format(config.CORE_INITIAL_AMOUNT, config.CORE_SYMBOL_NAME), "eosio.token"))
result = loop.run_until_complete(async_eosio.push_action("eosio.token", "create", '[ "beos.gateway", "{0} {1}"]'.format(config.PROXY_INITIAL_AMOUNT, config.PROXY_ASSET_NAME), "eosio.token"))
eosio.push_action("eosio.token", "create", '[ "beos.distrib", "{0} {1}"]'.format(config.CORE_INITIAL_AMOUNT, config.CORE_SYMBOL_NAME), "eosio.token")
eosio.push_action("eosio.token", "create", '[ "beos.gateway", "{0} {1}"]'.format(config.PROXY_INITIAL_AMOUNT, config.PROXY_ASSET_NAME), "eosio.token")

result = loop.run_until_complete(async_eosio.set_contract("eosio", config.CONTRACTS_DIR + "eosio.system", "eosio"))
result = loop.run_until_complete(async_eosio.set_contract("beos.init", config.CONTRACTS_DIR + "eosio.init", "beos.init"))
result = loop.run_until_complete(async_eosio.set_contract("beos.gateway", config.CONTRACTS_DIR + "eosio.gateway", "beos.gateway"))
result = loop.run_until_complete(async_eosio.set_contract("beos.distrib", config.CONTRACTS_DIR + "eosio.distribution", "beos.distrib"))
eosio.set_contract("eosio", config.CONTRACTS_DIR + "eosio.system", "eosio")
eosio.set_contract("beos.init", config.CONTRACTS_DIR + "eosio.init", "beos.init")
eosio.set_contract("beos.gateway", config.CONTRACTS_DIR + "eosio.gateway", "beos.gateway")
eosio.set_contract("beos.distrib", config.CONTRACTS_DIR + "eosio.distribution", "beos.distrib")

result = loop.run_until_complete(async_eosio.push_action("eosio", "initram", '[ "beos.gateway", "{0}"]'.format(config.INIT_RAM), "eosio"))
eosio.push_action("eosio", "initram", '[ "beos.gateway", "{0}"]'.format(config.INIT_RAM), "eosio")

result = loop.run_until_complete(async_eosio.terminate_running_tasks())
result = loop.run_until_complete(async_eosio.show_keosd_postconf(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT, config.DEFAULT_WALLET_DIR))
result = loop.run_until_complete(async_eosio.show_wallet_unlock_postconf())
result = loop.run_until_complete(async_eosio.show_nodeos_postconf(0, "eosio", config.EOSIO_PUBLIC_KEY))
eosio.terminate_running_tasks()
eosio.show_keosd_postconf(config.KEOSD_IP_ADDRESS, config.KEOSD_PORT, config.DEFAULT_WALLET_DIR)
eosio.show_wallet_unlock_postconf()
eosio.show_nodeos_postconf(0, "eosio", config.EOSIO_PUBLIC_KEY)
except Exception as ex:
result = loop.run_until_complete(async_eosio.terminate_running_tasks())
eosio.terminate_running_tasks()
logger.error("Exception during initialize: {0}".format(ex))
sys.exit(1)

Expand Down
77 changes: 38 additions & 39 deletions cd-scripts/eosio.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import time
import sys

global KEOSD
KEOSD = None
global NODEOS
NODEOS = None

try:
import config
except Exception as ex:
Expand Down Expand Up @@ -106,7 +111,6 @@ def show_nodeos_postconf(node_index, name, public_key, use_https = False):
logger.info("Configuration complete, you can now run nodeos with command (consider running in screen): {0}".format(" ".join(parameters)))

def run_keosd(ip_address, port, wallet_dir, use_https = False):
import select
logger.info("*** Running KLEOSD at {0}:{1} in {2}".format(ip_address, port, wallet_dir))
from sys import exit
if os.path.exists(config.DEFAULT_WALLET_DIR):
Expand All @@ -120,8 +124,6 @@ def run_keosd(ip_address, port, wallet_dir, use_https = False):
os.makedirs(config.DEFAULT_WALLET_DIR)
os.makedirs(config.WALLET_PASSWORD_DIR)

time.sleep(0.5)

parameters = None
if use_https:
# run kleosd in https mode
Expand All @@ -138,7 +140,18 @@ def run_keosd(ip_address, port, wallet_dir, use_https = False):
"--wallet-dir", wallet_dir,
]
logger.info("Executing command: {0}".format(" ".join(parameters)))
subprocess.Popen(parameters, stdout=config.log_main, stderr=config.log_main)
global KEOSD
KEOSD = subprocess.Popen(parameters, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
line = KEOSD.stdout.readline()
line = line.decode('utf-8').strip()
if line.startswith("error"):
raise EOSIOException("Error during KEOSD run")
else:
logger.debug(line)
if line.endswith("add api url: /v1/wallet/unlock"):
logger.info("KEOSD is up and running")
break

def unlock_wallet(wallet_name, wallet_password):
parameters = [config.CLEOS_EXECUTABLE,
Expand All @@ -149,7 +162,6 @@ def unlock_wallet(wallet_name, wallet_password):
logger.info("Executing command: {0}".format(" ".join(parameters)))
ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main)
retcode = ret.returncode
time.sleep(1)
if retcode == 0:
logger.debug("Executed with ret: {0}".format(ret))
else:
Expand All @@ -175,7 +187,6 @@ def import_key(wallet_name, key, wallet_url = None):
logger.info("Executing command: {0}".format(" ".join(parameters)))
ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main)
retcode = ret.returncode
time.sleep(1)
if retcode == 0:
logger.debug("Executed with ret: {0}".format(ret))
else:
Expand Down Expand Up @@ -206,7 +217,6 @@ def create_wallet(wallet_url = None, unlock = False):
logger.info("Executing command: {0}".format(" ".join(parameters)))
ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main)
retcode = ret.returncode
time.sleep(1)
if retcode == 0:
logger.debug("Executed with ret: {0}".format(ret))
else:
Expand Down Expand Up @@ -277,13 +287,18 @@ def run_nodeos(node_index, name, public_key, use_https = False):
parameters = parameters + https_opts + plugins

logger.info("Executing command: {0}".format(" ".join(parameters)))
try:
import time
subprocess.Popen(parameters, stdout=config.log_main, stderr=config.log_main)
time.sleep(2.0)
except Exception as ex:
logger.error("Exception during spawning nodeos process: {0}".format(ex))
return 0
global NODEOS
NODEOS = subprocess.Popen(parameters, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
line = NODEOS.stdout.readline()
line = line.decode('utf-8').strip()
if line.startswith("error"):
logger.error(line)
else:
logger.debug(line)
if "] Produced block" in line:
logger.info("NODEOS is up and running")
break

def create_account(creator, name, owner_key, active_key, schema = "http"):
if not owner_key and not active_key:
Expand All @@ -296,7 +311,6 @@ def create_account(creator, name, owner_key, active_key, schema = "http"):
logger.info("Executing command: {0}".format(" ".join(parameters)))
ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main)
retcode = ret.returncode
time.sleep(1)
if retcode == 0:
logger.debug("Executed with ret: {0}".format(ret))
else:
Expand All @@ -312,7 +326,6 @@ def set_contract(account, contract, permission, schema = "http"):
logger.info("Executing command: {0}".format(" ".join(parameters)))
ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main)
retcode = ret.returncode
time.sleep(1)
if retcode == 0:
logger.debug("Executed with ret: {0}".format(ret))
else:
Expand All @@ -328,7 +341,6 @@ def push_action(account, action, data, permission, schema = "http"):
logger.info("Executing command: {0}".format(" ".join(parameters)))
ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main)
retcode = ret.returncode
time.sleep(1)
if retcode == 0:
logger.debug("Executed with ret: {0}".format(ret))
else:
Expand All @@ -337,29 +349,16 @@ def push_action(account, action, data, permission, schema = "http"):
raise EOSIOException("Initialization failed on last command")

def terminate_running_tasks():
parameters = ["pkill", "nodeos"]
logger.info("Executing command: {0}".format(" ".join(parameters)))
ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main)
retcode = ret.returncode
time.sleep(1)
if retcode == 0:
logger.debug("Executed with ret: {0}".format(ret))
else:
logger.error("Executed with ret: {0}".format(ret))
logger.error("Initialization failed on last command")
raise EOSIOException("Initialization failed on last command")
try:
if NODEOS is not None:
logger.info("Terminating NODEOS")
NODEOS.terminate()

parameters = ["pkill", "keosd"]
logger.info("Executing command: {0}".format(" ".join(parameters)))
ret = subprocess.run(parameters, stdout=config.log_main, stderr=config.log_main)
retcode = ret.returncode
time.sleep(1)
if retcode == 0:
logger.debug("Executed with ret: {0}".format(ret))
else:
logger.error("Executed with ret: {0}".format(ret))
logger.error("Initialization failed on last command")
raise EOSIOException("Initialization failed on last command")
if KEOSD is not None:
logger.info("Terminating KEOSD")
KEOSD.terminate()
except Exception as ex:
logger.error("Exception occured: {0}".format(ex))

if __name__ == '__main__':
name = "eosio"
Expand Down

0 comments on commit 884df0c

Please sign in to comment.