From b1a650a63e60e26e551caa9052e687d1fcaaf16e Mon Sep 17 00:00:00 2001 From: Alexander Molchevsky Date: Sun, 30 Oct 2022 16:39:42 +0200 Subject: [PATCH 1/2] The code has been reformatted according to PEP8 style guide --- src/dune/__main__.py | 290 ++++++------ src/dune/args.py | 210 +++++---- src/dune/context.py | 142 +++--- src/dune/docker.py | 244 +++++----- src/dune/dune.py | 1030 ++++++++++++++++++++++++------------------ 5 files changed, 1080 insertions(+), 836 deletions(-) diff --git a/src/dune/__main__.py b/src/dune/__main__.py index 421f10cb..d58fcfd7 100644 --- a/src/dune/__main__.py +++ b/src/dune/__main__.py @@ -1,140 +1,162 @@ +from args import arg_parser +from args import parse_optional from dune import dune -from dune import node from dune import dune_error from dune import dune_node_not_found +from dune import node from dune import version_full -from args import arg_parser -from args import parse_optional - -import os if __name__ == '__main__': - parser = arg_parser() - - dune_sys = dune() - - if parser.is_forwarding(): - dune_sys.execute_interactive_cmd(parser.get_forwarded_args()) - else: - args = parser.parse() - - try: - if args.start != None: - n = None - if len(args.start) == 1: - n = node(args.start[0]) - else: - n = node(args.start[0], dune_sys._docker.abs_host_path(args.start[1])) - dune_sys.start_node(n) - - elif args.remove != None: - dune_sys.remove_node( node(args.remove) ) - - elif args.destroy_container: - dune_sys.destroy() - - elif args.stop_container: - dune_sys.stop_container() - - elif args.start_container: - dune_sys.start_container() - - elif args.stop != None: - dune_sys.stop_node( node(args.stop) ) - - elif args.list: - dune_sys.list_nodes() - - elif args.simple_list: - dune_sys.list_nodes(True) - - elif args.set_active != None: - dune_sys.set_active( node(args.set_active) ) - - elif args.get_active: - print(dune_sys.get_active()) - - elif args.monitor: - dune_sys.monitor() - - elif args.export_wallet: - dune_sys.export_wallet() - - elif args.import_wallet != None: - dune_sys.import_wallet(args.import_wallet) - - elif args.export_node != None: - dune_sys.export_node( node(args.export_node[0]), args.export_node[1]) - - elif args.import_node != None: - dune_sys.import_node( args.import_node[0], node(args.import_node[1]) ) - - elif args.import_dev_key != None: - dune_sys.import_key(args.import_dev_key) - - elif args.create_key: - print(dune_sys.create_key()) - - elif args.create_account != None: - if len(args.create_account) > 2: - dune_sys.create_account(args.create_account[0], args.create_account[1], args.create_account[2], args.create_account[3]) - elif len(args.create_account) > 1: - dune_sys.create_account(args.create_account[0], args.create_account[1]) - else: - dune_sys.create_account(args.create_account[0]) - - elif args.create_cmake_app != None: - dune_sys.init_project(args.create_cmake_app[0], dune_sys._docker.abs_host_path(args.create_cmake_app[1]), True) - - elif args.create_bare_app != None: - dune_sys.init_project(args.create_bare_app[0], dune_sys._docker.abs_host_path(args.create_bare_app[1]), False) - - elif args.cmake_build != None: - dune_sys.build_cmake_proj(args.cmake_build[0], parse_optional(args.remainder)) - - elif args.ctest != None: - dune_sys.ctest_runner(args.ctest[0], parse_optional(args.remainder)) - - elif args.gdb != None: - dune_sys.gdb(args.gdb[0], parse_optional(args.remainder)) - - elif args.deploy != None: - dune_sys.deploy_contract(dune_sys._docker.abs_host_path(args.deploy[0]), args.deploy[1]) - - elif args.set_bios_contract != None: - dune_sys.deploy_contract( '/app/reference-contracts/build/contracts/eosio.bios', args.set_bios_contract) - - elif args.set_core_contract != None: - dune_sys.deploy_contract( '/app/reference-contracts/build/contracts/eosio.system', args.set_core_contract) - - elif args.set_token_contract != None: - dune_sys.deploy_contract( '/app/reference-contracts/build/contracts/eosio.token', args.set_token_contract) - - elif args.bootstrap_system: - dune_sys.bootstrap_system(False) - - elif args.bootstrap_system_full: - dune_sys.bootstrap_system(True) - - elif args.activate_feature != None: - dune_sys.activate_feature(args.activate_feature, True) - - elif args.list_features: - for f in dune_sys.features(): - print(f) - - elif args.send_action != None: - dune_sys.send_action(args.send_action[1], args.send_action[0], args.send_action[2], args.send_action[3]) - - elif args.get_table != None: - dune_sys.get_table(args.get_table[0], args.get_table[1], args.get_table[2]) - - elif args.version: - print ("DUNE "+version_full()) - - except KeyboardInterrupt: - pass - except dune_node_not_found as err: - print('Node not found ['+err.name()+']') - except dune_error as err: - print("Internal Error") + parser = arg_parser() + + dune_sys = dune() + + if parser.is_forwarding(): + dune_sys.execute_interactive_cmd(parser.get_forwarded_args()) + else: + args = parser.parse() + + try: + if args.start is not None: + n: object + if len(args.start) == 1: + n = node(args.start[0]) + else: + n = node(args.start[0], + dune_sys.docker.abs_host_path(args.start[1])) + dune_sys.start_node(n) + + elif args.remove is not None: + dune_sys.remove_node(node(args.remove)) + + elif args.destroy_container: + dune_sys.destroy() + + elif args.stop_container: + dune_sys.stop_container() + + elif args.start_container: + dune_sys.start_container() + + elif args.stop is not None: + dune_sys.stop_node(node(args.stop)) + + elif args.list: + dune_sys.list_nodes() + + elif args.simple_list: + dune_sys.list_nodes(True) + + elif args.set_active is not None: + dune_sys.set_active(node(args.set_active)) + + elif args.get_active: + print(dune_sys.get_active()) + + elif args.monitor: + dune_sys.monitor() + + elif args.export_wallet: + dune_sys.export_wallet() + + elif args.import_wallet is not None: + dune_sys.import_wallet(args.import_wallet) + + elif args.export_node is not None: + dune_sys.export_node(node(args.export_node[0]), + args.export_node[1]) + + elif args.import_node is not None: + dune_sys.import_node(args.import_node[0], + node(args.import_node[1])) + + elif args.import_dev_key is not None: + dune_sys.import_key(args.import_dev_key) + + elif args.create_key: + print(dune_sys.create_key()) + + elif args.create_account is not None: + if len(args.create_account) > 2: + dune_sys.create_account(args.create_account[0], + args.create_account[1], + args.create_account[2], + args.create_account[3]) + elif len(args.create_account) > 1: + dune_sys.create_account(args.create_account[0], + args.create_account[1]) + else: + dune_sys.create_account(args.create_account[0]) + + elif args.create_cmake_app is not None: + dune_sys.init_project(args.create_cmake_app[0], + dune_sys.docker.abs_host_path( + args.create_cmake_app[1]), True) + + elif args.create_bare_app is not None: + dune_sys.init_project(args.create_bare_app[0], + dune_sys.docker.abs_host_path( + args.create_bare_app[1]), + False) + + elif args.cmake_build is not None: + dune_sys.build_cmake_proj(args.cmake_build[0], + parse_optional(args.remainder)) + + elif args.ctest is not None: + dune_sys.ctest_runner(args.ctest[0], + parse_optional(args.remainder)) + + elif args.gdb is not None: + dune_sys.gdb(args.gdb[0], parse_optional(args.remainder)) + + elif args.deploy is not None: + dune_sys.deploy_contract( + dune_sys.docker.abs_host_path(args.deploy[0]), + args.deploy[1]) + + elif args.set_bios_contract is not None: + dune_sys.deploy_contract( + '/app/reference-contracts/build/contracts/eosio.bios', + args.set_bios_contract) + + elif args.set_core_contract is not None: + dune_sys.deploy_contract( + '/app/reference-contracts/build/contracts/eosio.system', + args.set_core_contract) + + elif args.set_token_contract is not None: + dune_sys.deploy_contract( + '/app/reference-contracts/build/contracts/eosio.token', + args.set_token_contract) + + elif args.bootstrap_system: + dune_sys.bootstrap_system(False) + + elif args.bootstrap_system_full: + dune_sys.bootstrap_system(True) + + elif args.activate_feature is not None: + dune_sys.activate_feature(args.activate_feature, True) + + elif args.list_features: + for f in dune_sys.features(): + print(f) + + elif args.send_action is not None: + dune_sys.send_action(args.send_action[1], args.send_action[0], + args.send_action[2], args.send_action[3]) + + elif args.get_table is not None: + dune_sys.get_table(args.get_table[0], args.get_table[1], + args.get_table[2]) + + elif args.version: + print("DUNE " + version_full()) + + except KeyboardInterrupt: + pass + except dune_node_not_found as err: + print('Node not found [' + err.name() + ']') + except dune_error as err: + print("Internal Error") diff --git a/src/dune/args.py b/src/dune/args.py index e677ba14..320c048d 100644 --- a/src/dune/args.py +++ b/src/dune/args.py @@ -1,91 +1,147 @@ import argparse import sys + class fix_action_data(argparse.Action): - def __call__(self, parser, namespace, values, option_string=None): - fixed_list = [] - fixed_list.append(values[0]) - fixed_list.append(values[1]) - fixed_list.append(values[2].strip()) - fixed_list.append(values[3]) - setattr(namespace, self.dest, fixed_list) + def __call__(self, parser, namespace, values, option_string=None): + fixed_list = [values[0], values[1], values[2].strip(), values[3]] + setattr(namespace, self.dest, fixed_list) + def fix_args(args): - arg_list = list() - arg_so_far = "" - state = False - for arg in args: - if not state: - if arg.startswith('['): - state = True - arg_so_far = arg[1:] - continue - else: + arg_list = [] + arg_so_far = "" + state = False + for arg in args: + if not state: + if arg.startswith('['): + state = True + arg_so_far = arg[1:] + continue arg_list.append(arg) continue - if state: - if arg.endswith(']'): - arg_so_far = arg_so_far + arg[:-1] - state = False - arg_list.append(arg_so_far) - arg_so_far = "" - continue - else: + if state: + if arg.endswith(']'): + arg_so_far = arg_so_far + arg[:-1] + state = False + arg_list.append(arg_so_far) + arg_so_far = "" + continue arg_so_far = arg_so_far + arg - return arg_list + return arg_list + def parse_optional(cmd): - if cmd is not None: - return cmd[1:] # remove leading -- - else: - return cmd # empty list + if cmd is not None: + return cmd[1:] # remove leading -- + return cmd # empty list + + class arg_parser: - def __init__(self): - self._parser = argparse.ArgumentParser(description='DUNE: Docker Utilities for Node Execution') - self._parser.add_argument('--start', nargs='+', metavar=["NODE", "CONFIG-DIR (Optional)"], help='start a new node with a given name and an optional config.ini') - self._parser.add_argument('--stop', metavar="NODE", help='stop a node with a given name') - self._parser.add_argument('--remove', metavar="NODE", help='a node with a given name, will stop the node if running') - self._parser.add_argument('--list', action='store_true', help='list all nodes available and their statuses') - self._parser.add_argument('--simple-list', action='store_true', help='list all nodes available and their statuses without formatting and unicode') - self._parser.add_argument('--set-active', metavar=("NODE"), help='set a node to active status') - self._parser.add_argument('--get-active', action='store_true', help='get the name of the node that is currently active') - self._parser.add_argument('--export-node', metavar=("NODE", "DIR"), nargs=2, help='export state and blocks log for the given node.') - self._parser.add_argument('--import-node', metavar=("DIR", "NODE"), nargs=2, help='import state and blocks log to a given node') - self._parser.add_argument('--monitor', action='store_true', help='monitor the currently active node') - self._parser.add_argument('--import-dev-key', metavar="KEY", help='import a private key into developement wallet') - self._parser.add_argument('--create-key', action='store_true', help='create an public key private key pair') - self._parser.add_argument('--export-wallet', action='store_true', help='export the internal development wallet') - self._parser.add_argument('--import-wallet', metavar=["DIR"], help='import a development wallet') - self._parser.add_argument('--create-account', nargs='+', metavar=["NAME","CREATOR (Optional)", "PUB_KEY (Optional)", "PRIV_KEY (Optional)"], help='create an EOSIO account and an optional creator (the default is eosio)') - self._parser.add_argument('--create-cmake-app', nargs=2, metavar=["PROJ_NAME", "DIR"], help='create a smart contract project at from a specific host location') - self._parser.add_argument('--create-bare-app', nargs=2, metavar=["PROJ_NAME", "DIR"], help='create a smart contract project at from a specific host location') - self._parser.add_argument('--cmake-build', nargs=1, metavar=["DIR", "-- FLAGS (Optional)"], help='build a smart contract project at the directory given optional flags are of the form -- -DFLAG1=On -DFLAG2=Off]') - self._parser.add_argument('--ctest', nargs=1, metavar=["DIR", "-- FLAGS (Optional)"], help='run the ctest tests for a smart contract project at the directory given optional flags are of the form -- -VV') - self._parser.add_argument('--gdb', nargs=1, metavar=["DIR", "-- FLAGS (Optional)"], help='run the ctest tests for a smart contract project at the directory given optional flags are of the form -- -VV') - self._parser.add_argument('--deploy', nargs=2, metavar=["DIR", "ACCOUNT"], help='deploy a smart contract and ABI to account given') - self._parser.add_argument('--destroy-container', action='store_true', help='destroy context container ') - self._parser.add_argument('--stop-container', action='store_true', help='stop the context container') - self._parser.add_argument('--start-container', action='store_true', help='start the context container') - self._parser.add_argument('--set-core-contract', metavar=["ACCOUNT"], help='set the core contract to an account given (default normally is `eosio`)') - self._parser.add_argument('--set-bios-contract', metavar=["ACCOUNT"], help='set the bios contract to an account given (default normally is `eosio`)') - self._parser.add_argument('--set-token-contract', metavar=["ACCOUNT"], help='set the token contract to an account given (default normally is`eosio.token`)') - self._parser.add_argument('--bootstrap-system', action='store_true', help='install boot contract to eosio and activate all protocol features') - self._parser.add_argument('--bootstrap-system-full', action='store_true', help='same as `--bootstrap-system` but also creates accounts needed for core contract and deploys core, token, and multisig contracts') - self._parser.add_argument('--send-action', nargs=4, action=fix_action_data, metavar=["ACCOUNT", "ACTION", "DATA", "PERMISSION"], help='send action to account with data given and permission') - self._parser.add_argument('--get-table', nargs=3, metavar=["ACCOUNT", "SCOPE", "TABLE"], help='get the data from the given table') - self._parser.add_argument('--activate-feature', metavar=["CODENAME"], help='active protocol feature') - self._parser.add_argument('--list-features', action='store_true', help='list available protocol feature code names') - self._parser.add_argument('--version', action='store_true', help='display the current version of DUNE') - self._parser.add_argument('remainder', nargs=argparse.REMAINDER) # used to store arguments to individual programs, starting with -- - #TODO readdress after the launch - #self._parser.add_argument('--start-webapp', metavar=["DIR"], help='start a webapp with ') - - def is_forwarding(self): - return len(sys.argv) > 1 and sys.argv[1] == '--' - - def get_forwarded_args(self): - return sys.argv[2:] + def __init__(self): + self._parser = argparse.ArgumentParser( + description='DUNE: Docker Utilities for Node Execution') + self._parser.add_argument('--start', nargs='+', metavar=["NODE", "CONFIG-DIR (Optional)"], + help='start a new node with a given name and an optional ' + 'config.ini') + self._parser.add_argument('--stop', metavar="NODE", help='stop a node with a given name') + self._parser.add_argument('--remove', metavar="NODE", + help='a node with a given name, will stop the node if running') + self._parser.add_argument('--list', action='store_true', + help='list all nodes available and their statuses') + self._parser.add_argument('--simple-list', action='store_true', + help='list all nodes available and their statuses without ' + 'formatting and unicode') + self._parser.add_argument('--set-active', metavar="NODE", + help='set a node to active status') + self._parser.add_argument('--get-active', action='store_true', + help='get the name of the node that is currently active') + self._parser.add_argument('--export-node', metavar=("NODE", "DIR"), nargs=2, + help='export state and blocks log for the given node.') + self._parser.add_argument('--import-node', metavar=("DIR", "NODE"), nargs=2, + help='import state and blocks log to a given node') + self._parser.add_argument('--monitor', action='store_true', + help='monitor the currently active node') + self._parser.add_argument('--import-dev-key', metavar="KEY", + help='import a private key into developement wallet') + self._parser.add_argument('--create-key', action='store_true', + help='create an public key private key pair') + self._parser.add_argument('--export-wallet', action='store_true', + help='export the internal development wallet') + self._parser.add_argument('--import-wallet', metavar="DIR", + help='import a development wallet') + self._parser.add_argument('--create-account', nargs='+', + metavar=["NAME", "CREATOR (Optional)", "PUB_KEY (Optional)", + "PRIV_KEY (Optional)"], + help='create an EOSIO account and an optional creator (the ' + 'default is eosio)') + self._parser.add_argument('--create-cmake-app', nargs=2, metavar=["PROJ_NAME", "DIR"], + help='create a smart contract project at from a specific host ' + 'location') + self._parser.add_argument('--create-bare-app', nargs=2, metavar=["PROJ_NAME", "DIR"], + help='create a smart contract project at from a specific host ' + 'location') + self._parser.add_argument('--cmake-build', nargs=1, metavar=["DIR", "-- FLAGS (Optional)"], + help='build a smart contract project at the directory given ' + 'optional flags are of the form -- -DFLAG1=On ' + '-DFLAG2=Off]') + self._parser.add_argument('--ctest', nargs=1, metavar=["DIR", "-- FLAGS (Optional)"], + help='run the ctest tests for a smart contract project at the ' + 'directory given optional flags are of the form -- -VV') + self._parser.add_argument('--gdb', nargs=1, metavar=["DIR", "-- FLAGS (Optional)"], + help='run the ctest tests for a smart contract project at the ' + 'directory given optional flags are of the form -- -VV') + self._parser.add_argument('--deploy', nargs=2, metavar=["DIR", "ACCOUNT"], + help='deploy a smart contract and ABI to account given') + self._parser.add_argument('--destroy-container', action='store_true', + help='destroy context container ') + self._parser.add_argument('--stop-container', action='store_true', + help='stop the context container') + self._parser.add_argument('--start-container', action='store_true', + help='start the context container') + self._parser.add_argument('--set-core-contract', metavar="ACCOUNT", + help='set the core contract to an account given (default ' + 'normally is `eosio`)') + self._parser.add_argument('--set-bios-contract', metavar="ACCOUNT", + help='set the bios contract to an account given (default ' + 'normally is `eosio`)') + self._parser.add_argument('--set-token-contract', metavar="ACCOUNT", + help='set the token contract to an account given (default ' + 'normally is`eosio.token`)') + self._parser.add_argument('--bootstrap-system', action='store_true', + help='install boot contract to eosio and activate all protocol ' + 'features') + self._parser.add_argument('--bootstrap-system-full', action='store_true', + help='same as `--bootstrap-system` but also creates accounts ' + 'needed for core contract and deploys core, token, ' + 'and multisig contracts') + self._parser.add_argument('--send-action', nargs=4, action=fix_action_data, + metavar=["ACCOUNT", "ACTION", "DATA", "PERMISSION"], + help='send action to account with data given and permission') + self._parser.add_argument('--get-table', nargs=3, metavar=["ACCOUNT", "SCOPE", "TABLE"], + help='get the data from the given table') + self._parser.add_argument('--activate-feature', metavar="CODENAME", + help='active protocol feature') + self._parser.add_argument('--list-features', action='store_true', + help='list available protocol feature code names') + self._parser.add_argument('--version', action='store_true', + help='display the current version of DUNE') + # used to store arguments to individual programs, starting with -- + self._parser.add_argument('remainder', + nargs=argparse.REMAINDER) + # pylint: disable=fixme + # TODO readdress after the launch + # self._parser.add_argument('--start-webapp', metavar=["DIR"], help='start a webapp with ') + + @staticmethod + def is_forwarding(): + return len(sys.argv) > 1 and sys.argv[1] == '--' + + @staticmethod + def get_forwarded_args(): + return sys.argv[2:] - def parse(self): - return self._parser.parse_args() + def parse(self): + return self._parser.parse_args() diff --git a/src/dune/context.py b/src/dune/context.py index 5d6f10bb..08ef054d 100644 --- a/src/dune/context.py +++ b/src/dune/context.py @@ -1,79 +1,79 @@ -from docker import docker - -import os, sys, tempfile - class ctx: - active = "" # active node - http_port = "" # active node's http port - p2p_port = "" # active node's p2p port - ship_port = "" # active node's ship port + active = "" # active node + http_port = "" # active node's http port + p2p_port = "" # active node's p2p port + ship_port = "" # active node's ship port + class context: - _file_name = ".dune.ctx" - _dir = '/home/www-data/' - _docker = None - _ctx = ctx() + _file_name = ".dune.ctx" + _dir = '/home/www-data/' + _docker = None + _ctx = ctx() + + def __init__(self, dockr): + self._docker = dockr + if self._docker.file_exists(self._dir + self._file_name): + self.read_ctx() + + def read_ctx(self): + arr = self._docker.execute_cmd(['cat', self._dir + self._file_name])[0].splitlines() + self._ctx.active = arr[0] + self._ctx.http_port = arr[1] + self._ctx.p2p_port = arr[2] + self._ctx.ship_port = arr[3] + + def write_ctx(self): + ctx_str = self._ctx.active + "\\n" + ctx_str = ctx_str + self._ctx.http_port + "\\n" + ctx_str = ctx_str + self._ctx.p2p_port + "\\n" + ctx_str = ctx_str + self._ctx.ship_port + stdout, stderr, exit_code = self._docker.execute_cmd(['/app/write_context.sh', ctx_str]) + print(stdout) + print(stderr) + + @staticmethod + def is_commented(string): + for char in string: + if char == '#': + return True + if char == ' ': + continue + return False + + def get_ctx(self): + return self._ctx + + def get_active(self): + return self._ctx.active - def __init__(self, dockr): - self._docker = dockr - if self._docker.file_exists(self._dir + self._file_name): - self.read_ctx() - - def read_ctx(self): - arr = self._docker.execute_cmd(['cat', self._dir + self._file_name])[0].splitlines() - self._ctx.active = arr[0] - self._ctx.http_port = arr[1] - self._ctx.p2p_port = arr[2] - self._ctx.ship_port = arr[3] - - def write_ctx(self): - ctx_str = self._ctx.active + "\\n" - ctx_str = ctx_str + self._ctx.http_port + "\\n" - ctx_str = ctx_str + self._ctx.p2p_port + "\\n" - ctx_str = ctx_str + self._ctx.ship_port - stdout, stderr, ec = self._docker.execute_cmd(['/app/write_context.sh', ctx_str]) - print(stdout) - print(stderr) - - def is_commented(self, s): - for c in s: - if c == '#': - return True - if c == ' ': - continue - return False + def get_config_args(self, nod): + conf, stderr, exit_code = self._docker.execute_cmd( + ['cat', '/home/www-data/nodes/' + nod.name() + '/config.ini']) - def get_ctx(self): - return self._ctx - def get_active(self): - return self._ctx.active + http_port = None + p2p_port = None + ship_port = None - def get_config_args(self, n): - conf, stderr, ec = self._docker.execute_cmd(['cat', '/home/www-data/nodes/'+n.name()+'/config.ini']) - - http_port = None - p2p_port = None - ship_port = None + for line in conf.splitlines(): + if not self.is_commented(line): + if "http-server-address" in line: + http_port = line.split('=')[1][1:] + elif "p2p-listen-endpoint" in line: + p2p_port = line.split('=')[1][1:] + elif "state-history-endpoint" in line: + ship_port = line.split('=')[1][1:] - for line in conf.splitlines(): - if not self.is_commented(line): - if "http-server-address" in line: - http_port = line.split('=')[1][1:] - elif "p2p-listen-endpoint" in line: - p2p_port = line.split('=')[1][1:] - elif "state-history-endpoint" in line: - ship_port = line.split('=')[1][1:] - - # if they don't exist just set to normal default values - if http_port == None: - http_port = "127.0.0.1:8888" - if p2p_port == None: - p2p_port = "0.0.0.0:9876" - if ship_port == None: - ship_port = "127.0.0.1:8080" - return [http_port, p2p_port, ship_port] + # if they don't exist just set to normal default values + if http_port is None: + http_port = "127.0.0.1:8888" + if p2p_port is None: + p2p_port = "0.0.0.0:9876" + if ship_port is None: + ship_port = "127.0.0.1:8080" + return [http_port, p2p_port, ship_port] - def set_active(self, n): - self._ctx.active = n.name() - self._ctx.http_port, self._ctx.p2p_port, self._ctx.ship_port = self.get_config_args(n) - self.write_ctx() \ No newline at end of file + def set_active(self, nod): + self._ctx.active = nod.name() + self._ctx.http_port, self._ctx.p2p_port, self._ctx.ship_port = self.get_config_args(nod) + self.write_ctx() diff --git a/src/dune/docker.py b/src/dune/docker.py index 2a31e3a8..771c678e 100644 --- a/src/dune/docker.py +++ b/src/dune/docker.py @@ -1,116 +1,132 @@ -import subprocess, platform, os, getpass +import os +import platform +import subprocess + class docker: - _container = "" - _image = "" - def __init__(self, container, image): - self._container = container - self._image = image - - # check if container is running - stdout, stderr, ec = self.execute_docker_cmd(['container', 'ls']) - - # if container is not in the list then create one - if not self._container in stdout: - # check if container is stopped - stdout, stderr, ec = self.execute_docker_cmd(['container', 'ls', '-a']) - if self._container in stdout: - self.execute_docker_cmd(['container', 'start', self._container]) - else: - # start a new container - print("Creating docker container ["+self._container+"]") - host_dir = '/' - if platform.system() == 'Windows': - host_dir = 'C:/' - - stdout, stderr, ec = self.execute_docker_cmd(['run', '-p', '8888:8888', '-p', '9876:9876', '-p', '8080:8080', '-p', '3000:3000', '-p', '8000:8000', '-v', host_dir+':/host', '-d', '--name='+self._container, self._image, 'tail', '-f', '&>', '/dev/null', '&']) - - def abs_host_path(self, dir): - abs_path = os.path.abspath(dir) - if platform.system() == 'Windows': - abs_path = abs_path[3:].replace('\\', '/') # remove the drive letter prefix and replace the separators - else: - abs_path = abs_path[1:] - - return '/host/'+abs_path - - def get_container(self): - return self._container - - def get_image(self): - return self._image - - def execute_docker_cmd(self, cmd): - proc = subprocess.Popen(['docker']+cmd, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = proc.communicate() - return [stdout.decode('UTF-8'), stderr.decode('UTF-8'), proc.poll()] - - def file_exists(self, fn): - return self.execute_cmd(['test', '-f', fn])[2] == 0 - - def dir_exists(self, d): - return self.execute_cmd(['test', '-d', d])[2] == 0 - - def tar_dir(self, n, d): - return self.execute_cmd(['tar', 'cvzf', n+'.tgz', d]) - - def untar(self, d): - return self.execute_cmd(['tar', 'xvzf', d]) - - def cp_to_host(self, cf, hf): - return self.execute_docker_cmd(['cp', self._container+":"+cf, hf]) - - def cp_from_host(self, hf, cf): - return self.execute_docker_cmd(['cp', hf, self._container+":"+cf]) - - def rm(self, f): - self.execute_cmd(['rm', '-rf', f]) - - def find_pid(self, s): - stdout, stderr, ec = self.execute_cmd(['ps', 'ax']) - for line in stdout.splitlines(True): - if "PID TTY" in line: - continue - else: - if s in line: - return line.split()[0] - - return -1 - - def get_container_name(self): - return self._container - - def commit(self, name): - self.execute_docker_cmd(['commit', 'dune', 'dune']) - - def start(self): - print("Starting docker container ["+self._container+"]") - self.execute_docker_cmd(['container', 'start', self._container]) - - def stop(self): - print("Stopping docker container ["+self._container+"]") - self.execute_docker_cmd(['container', 'stop', self._container]) - - def destroy(self): - print("Destroying docker container ["+self._container+"]") - self.execute_docker_cmd(['container', 'stop', self._container]) - self.execute_docker_cmd(['container', 'rm', self._container]) - - def execute_cmd_at(self, dir, cmd): - proc = subprocess.Popen(['docker', 'container', 'exec', '-w', dir, self._container]+cmd) - proc.communicate() - - def execute_cmd(self, cmd): - return self.execute_docker_cmd(['container', 'exec', self._container] + cmd) - - def execute_interactive_cmd(self, cmd): - proc = subprocess.Popen(['docker', 'container', 'exec', '-i', self._container]+cmd) - proc.communicate() - - def execute_cmd2(self, cmd): - proc = subprocess.Popen(['docker', 'container', 'exec', self._container] + cmd) - proc.communicate() - - def execute_bg_cmd(self, cmd): - return self.execute_cmd(cmd+['&']) + _container = "" + _image = "" + + def __init__(self, container, image): + self._container = container + self._image = image + + # check if container is running + stdout, stderr, exit_code = self.execute_docker_cmd(['container', 'ls']) + + # if container is not in the list then create one + if self._container not in stdout: + # check if container is stopped + stdout, stderr, exit_code = self.execute_docker_cmd( + ['container', 'ls', '-a']) + if self._container in stdout: + self.execute_docker_cmd( + ['container', 'start', self._container]) + else: + # start a new container + print("Creating docker container [" + self._container + "]") + host_dir = '/' + if platform.system() == 'Windows': + host_dir = 'C:/' + + stdout, stderr, exit_code = self.execute_docker_cmd( + ['run', '-p', '8888:8888', '-p', '9876:9876', '-p', + '8080:8080', '-p', '3000:3000', '-p', '8000:8000', '-v', + host_dir + ':/host', '-d', '--name=' + self._container, + self._image, 'tail', '-f', '&>', '/dev/null', '&']) + + @staticmethod + def abs_host_path(directory): + abs_path = os.path.abspath(directory) + if platform.system() == 'Windows': + # remove the drive letter prefix and replace the separators + abs_path = abs_path[3:].replace('\\', '/') + else: + abs_path = abs_path[1:] + + return '/host/' + abs_path + + def get_container(self): + return self._container + + def get_image(self): + return self._image + + @staticmethod + def execute_docker_cmd(cmd): + with subprocess.Popen(['docker'] + cmd, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: + stdout, stderr = proc.communicate() + return [stdout.decode('UTF-8'), stderr.decode('UTF-8'), proc.poll()] + + def file_exists(self, file_name): + return self.execute_cmd(['test', '-f', file_name])[2] == 0 + + def dir_exists(self, directory): + return self.execute_cmd(['test', '-d', directory])[2] == 0 + + def tar_dir(self, file_name, directory): + return self.execute_cmd(['tar', 'cvzf', file_name + '.tgz', directory]) + + def untar(self, directory): + return self.execute_cmd(['tar', 'xvzf', directory]) + + def cp_to_host(self, container_file, host_file): + return self.execute_docker_cmd(['cp', self._container + ":" + container_file, host_file]) + + def cp_from_host(self, host_file, container_file): + return self.execute_docker_cmd(['cp', host_file, self._container + ":" + container_file]) + + def rm_file(self, file_name): + self.execute_cmd(['rm', '-rf', file_name]) + + def find_pid(self, process_name): + stdout, stderr, exit_code = self.execute_cmd(['ps', 'ax']) + for line in stdout.splitlines(True): + if "PID TTY" in line: + continue + if process_name in line: + return line.split()[0] + + return -1 + + def get_container_name(self): + return self._container + + def commit(self, name): + self.execute_docker_cmd(['commit', 'dune', 'dune']) + + def start(self): + print("Starting docker container [" + self._container + "]") + self.execute_docker_cmd(['container', 'start', self._container]) + + def stop(self): + print("Stopping docker container [" + self._container + "]") + self.execute_docker_cmd(['container', 'stop', self._container]) + + def destroy(self): + print("Destroying docker container [" + self._container + "]") + self.execute_docker_cmd(['container', 'stop', self._container]) + self.execute_docker_cmd(['container', 'rm', self._container]) + + def execute_cmd_at(self, directory, cmd): + with subprocess.Popen(['docker', 'container', 'exec', '-w', directory, + self._container] + cmd) as proc: + proc.communicate() + + def execute_cmd(self, cmd): + return self.execute_docker_cmd( + ['container', 'exec', self._container] + cmd) + + def execute_interactive_cmd(self, cmd): + with subprocess.Popen(['docker', 'container', + 'exec', '-i', self._container] + cmd) as proc: + proc.communicate() + + def execute_cmd2(self, cmd): + with subprocess.Popen(['docker', 'container', + 'exec', self._container] + cmd) as proc: + proc.communicate() + + def execute_bg_cmd(self, cmd): + return self.execute_cmd(cmd + ['&']) diff --git a/src/dune/dune.py b/src/dune/dune.py index 0318e22d..28235671 100644 --- a/src/dune/dune.py +++ b/src/dune/dune.py @@ -1,460 +1,610 @@ -from docker import docker +# pylint: disable=missing-function-docstring, missing-module-docstring from context import context - -import os, platform, getpass +from docker import docker # VERSION INFORMATION def version_major(): - return 1 + return 1 + + def version_minor(): - return 0 + return 0 + + def version_patch(): - return 0 + return 0 + + def version_suffix(): - return "" + return "" + + def version_full(): - main_version = "v"+str(version_major())+"."+str(version_minor())+"."+str(version_patch()) - if version_suffix() == "": - return main_version - else: - return main_version+"."+version_suffix() + main_version = "v" + str(version_major()) + "." + str( + version_minor()) + "." + str(version_patch()) + if version_suffix() == "": + return main_version + return main_version + "." + version_suffix() + + class dune_error(Exception): - pass + pass + + class dune_node_not_found(dune_error): - _name = "" - def __init__(self, n): - self._name = n + _name = "" + + def __init__(self, n): + self._name = n + + def name(self): + return self._name - def name(self): - return self._name class node: - _name = "" - _cfg = "" - def __init__(self, nm, cfg = None): - self._name = nm - self._cfg = cfg - - def name(self): - return self._name - - def config(self): - return self._cfg - - def set_config(self, cfg): - self._cfg = cfg - - def data_dir(self): - return '/home/www-data/nodes/'+self.name() - - def config_dir(self): - return '/home/www-data/nodes/'+self.name() + _name = "" + _cfg = "" + + def __init__(self, name, cfg=None): + self._name = name + self._cfg = cfg + + def name(self): + return self._name + + def config(self): + return self._cfg + + def set_config(self, cfg): + self._cfg = cfg + + def data_dir(self): + return '/home/www-data/nodes/' + self.name() + + def config_dir(self): + return '/home/www-data/nodes/' + self.name() + class dune: - _docker = None - _wallet_pw = None - _context = None - _token_priv_key = "5JPJoZXizFVi19wHkboX5fwwEU2jZVvtSJpQkQu3uqgNu8LNdQN" - _token_pub_key = "EOS6v86d8DAxjfGu92CLrnEzq7pySpVWYV2LjaxPaDJJvyf9Vpx5R" - - def __init__(self): - self._docker = docker('dune_container', 'dune:latest') - self._wallet_pw = self.get_wallet_pw() - self._context = context(self._docker) - - def node_exists(self, n): - return self._docker.dir_exists('/home/www-data/nodes/'+n.name()) - - def is_node_running(self, n): - return self._docker.find_pid('/home/www-data/nodes/'+n.name()+' ') != -1 - - def set_active(self, n): - if self.node_exists(n): - self._context.set_active(n) - else: - raise dune_node_not_found(n.name()) - - def get_active(self): - return self._context.get_active() - - def create_node(self, n): - print("Creating node ["+n.name()+"]") - self._docker.execute_cmd(['mkdir', '-p', n.data_dir()]) - - def start_node(self, n, snapshot=None): - stdout, stderr, ec = self._docker.execute_cmd(['ls', '/home/www-data/nodes']) - - if self.is_node_running(n): - print("Node ["+n.name()+"] is already running.") - return - - cmd = ['sh', 'start_node.sh', n.data_dir(), n.config_dir()] - - if snapshot != None: - cmd = cmd + ['--snapshot /home/www-data/nodes/'+n.name()+'/snapshots/'+snapshot+' -e'] - else: - cmd = cmd + [' '] - - # if node name is not found we need to create it - if not n.name() in stdout: - self.create_node(n) - - # copy config.ini to config-dir - if n.config() == None: - n.set_config('/home/www-data/config.ini') - - self._docker.execute_cmd(['cp', n.config(), n.config_dir()]) - print("Using Configuration ["+n.config()+"]") - - ctx = self._context.get_ctx() - cfg_args = self._context.get_config_args(n) - - if self.node_exists(node(ctx.active)): - if cfg_args[0] == ctx.http_port: - print("Currently active node ["+ctx.active+"] http port is the same as this nodes ["+n.name()+"]") - self.stop_node(node(ctx.active)) - elif cfg_args[1] == ctx.p2p_port: - print("Currently active node ["+ctx.active+"] p2p port is the same as this nodes ["+n.name()+"]") - self.stop_node(node(ctx.active)) - elif cfg_args[2] == ctx.ship_port: - print("Currently active node ["+ctx.active+"] ship port is the same as this nodes ["+n.name()+"]") - self.stop_node(node(ctx.active)) - - stdout, stderr, ec = self._docker.execute_cmd(cmd+[n.name()]) - - if ec == 0: - self.set_active(n) - print("Active ["+n.name()+"]") - print(stdout) - print(stderr) - else: - print(stderr) - - def cleos_cmd(self, cmd, quiet=True): - self.unlock_wallet() - ctx = self._context.get_ctx() - if quiet: - return self._docker.execute_cmd(['cleos', '--verbose', '-u', 'http://'+ctx.http_port]+cmd) - else: - return self._docker.execute_cmd2(['cleos', '--verbose', '-u', 'http://'+ctx.http_port]+cmd) - - def monitor(self): - stdout, stderr, ec = self.cleos_cmd(['get', 'info']) - print(stdout) - if ec != 0: - print(stderr) - raise dune_error - - def stop_node(self, n): - if self.node_exists(n): - if self.is_node_running(n): - pid = self._docker.find_pid('/home/www-data/nodes/'+n.name()+' ') - print("Stopping node ["+n.name()+"]") - self._docker.execute_cmd(['kill', pid]) - else: - print("Node ["+n.name()+"] is not running") - else: - raise dune_node_not_found(n.name()) - - def remove_node(self, n): - self.stop_node(n) - print("Removing node ["+n.name()+"]") - self._docker.execute_cmd(['rm','-rf', '/home/www-data/nodes/'+n.name()]) - - def destroy(self): - self._docker.destroy() - - def stop_container(self): - stdout, stderr, ec = self._docker.execute_cmd(['ls', '/home/www-data/nodes']) - for s in stdout.split(): - if self.is_node_running(node(s)): - self.stop_node(node(s)) - - self._docker.stop() - - def start_container(self): - self._docker.start() - - def list_nodes(self, simple=False): - if simple: - print("Node|Active|Running|HTTP|P2P|SHiP") - else: - print("Node Name | Active? | Running? | HTTP | P2P | SHiP") - print("--------------------------------------------------------------------------------------") - stdout, stderr, ec = self._docker.execute_cmd(['ls', '/home/www-data/nodes']) - ctx = self._context.get_ctx() - for s in stdout.split(): - print(s, end='') - if s == ctx.active: - if simple: - print('|Y', end='') + _docker = None + _wallet_pw = None + _context = None + _token_priv_key = "5JPJoZXizFVi19wHkboX5fwwEU2jZVvtSJpQkQu3uqgNu8LNdQN" + _token_pub_key = "EOS6v86d8DAxjfGu92CLrnEzq7pySpVWYV2LjaxPaDJJvyf9Vpx5R" + + def __init__(self): + self._docker = docker('dune_container', 'dune:latest') + self._wallet_pw = self.get_wallet_pw() + self._context = context(self._docker) + + def node_exists(self, nod): + return self._docker.dir_exists('/home/www-data/nodes/' + nod.name()) + + def is_node_running(self, nod): + return self._docker.find_pid( + '/home/www-data/nodes/' + nod.name() + ' ') != -1 + + def set_active(self, nod): + if self.node_exists(nod): + self._context.set_active(nod) + else: + raise dune_node_not_found(nod.name()) + + def get_active(self): + return self._context.get_active() + + def create_node(self, nod): + print("Creating node [" + nod.name() + "]") + self._docker.execute_cmd(['mkdir', '-p', nod.data_dir()]) + + def start_node(self, nod, snapshot=None): + stdout, stderr, exit_code = self._docker.execute_cmd( + ['ls', '/home/www-data/nodes']) + + if self.is_node_running(nod): + print("Node [" + nod.name() + "] is already running.") + return + + cmd = ['sh', 'start_node.sh', nod.data_dir(), nod.config_dir()] + + if snapshot is not None: + cmd = cmd + [ + '--snapshot /home/www-data/nodes/' + nod.name() + '/snapshots/' + + snapshot + ' -e'] + else: + cmd = cmd + [' '] + + # if node name is not found we need to create it + if not nod.name() in stdout: + self.create_node(nod) + + # copy config.ini to config-dir + if nod.config() is None: + nod.set_config('/home/www-data/config.ini') + + self._docker.execute_cmd(['cp', nod.config(), nod.config_dir()]) + print("Using Configuration [" + nod.config() + "]") + + ctx = self._context.get_ctx() + cfg_args = self._context.get_config_args(nod) + + if self.node_exists(node(ctx.active)): + if cfg_args[0] == ctx.http_port: + print( + "Currently active node [" + ctx.active + + "] http port is the same as this nodes [" + nod.name() + "]") + self.stop_node(node(ctx.active)) + elif cfg_args[1] == ctx.p2p_port: + print( + "Currently active node [" + ctx.active + + "] p2p port is the same as this nodes [" + nod.name() + "]") + self.stop_node(node(ctx.active)) + elif cfg_args[2] == ctx.ship_port: + print( + "Currently active node [" + ctx.active + + "] ship port is the same as this nodes [" + nod.name() + "]") + self.stop_node(node(ctx.active)) + + stdout, stderr, exit_code = self._docker.execute_cmd(cmd + [nod.name()]) + + if exit_code == 0: + self.set_active(nod) + print("Active [" + nod.name() + "]") + print(stdout) + print(stderr) + else: + print(stderr) + + def cleos_cmd(self, cmd, quiet=True): + self.unlock_wallet() + ctx = self._context.get_ctx() + if quiet: + return self._docker.execute_cmd( + ['cleos', '--verbose', '-u', 'http://' + ctx.http_port] + cmd) + return self._docker.execute_cmd2( + ['cleos', '--verbose', '-u', 'http://' + ctx.http_port] + cmd) + + def monitor(self): + stdout, stderr, exit_code = self.cleos_cmd(['get', 'info']) + print(stdout) + if exit_code != 0: + print(stderr) + raise dune_error + + def stop_node(self, nod): + if self.node_exists(nod): + if self.is_node_running(nod): + pid = self._docker.find_pid( + '/home/www-data/nodes/' + nod.name() + ' ') + print("Stopping node [" + nod.name() + "]") + self._docker.execute_cmd(['kill', pid]) else: - print('\t\t | Y', end='') - else: - if simple: - print('|N', end='') + print("Node [" + nod.name() + "] is not running") + else: + raise dune_node_not_found(nod.name()) + + def remove_node(self, nod): + self.stop_node(nod) + print("Removing node [" + nod.name() + "]") + self._docker.execute_cmd( + ['rm', '-rf', '/home/www-data/nodes/' + nod.name()]) + + def destroy(self): + self._docker.destroy() + + def stop_container(self): + stdout, stderr, exit_code = self._docker.execute_cmd( + ['ls', '/home/www-data/nodes']) + for string in stdout.split(): + if self.is_node_running(node(string)): + self.stop_node(node(string)) + + self._docker.stop() + + def start_container(self): + self._docker.start() + + # pylint: disable=too-many-branches + def list_nodes(self, simple=False): + if simple: + print("Node|Active|Running|HTTP|P2P|SHiP") + else: + print( + "Node Name | Active? | Running? | HTTP | " + "P2P | SHiP") + print( + "---------------------------------------------------------" + "-----------------------------") + stdout, stderr, exit_code = self._docker.execute_cmd( + ['ls', '/home/www-data/nodes']) + ctx = self._context.get_ctx() + for string in stdout.split(): + print(string, end='') + if string == ctx.active: + if simple: + print('|Y', end='') + else: + print('\t\t | Y', end='') else: - print('\t\t | N', end='') - if not self.is_node_running( node(s) ): - if simple: - print('|N', end='') + if simple: + print('|N', end='') + else: + print('\t\t | N', end='') + if not self.is_node_running(node(string)): + if simple: + print('|N', end='') + else: + print('\t | N', end='') else: - print('\t | N', end='') - else: + if simple: + print('|Y', end='') + else: + print('\t | Y', end='') + + ports = self._context.get_config_args(node(string)) if simple: - print('|Y', end='') + print('|' + ports[0] + '|' + ports[1] + '|' + ports[2]) else: - print('\t | Y', end='') - - ports = self._context.get_config_args( node(s) ) - if simple: - print('|'+ports[0]+'|'+ports[1]+'|'+ports[2]) - else: - print(' | '+ports[0]+' | '+ports[1]+' | '+ports[2]) - - def export_node(self, n, dir): - if self.node_exists(n): - self.set_active(n) - print("Exporting data from node ["+n.name()+"] to location "+dir) - if not self.is_node_running(n): - self.start_node(n) - self.create_snapshot() - self.stop_node(n) - self._docker.execute_cmd(['mkdir', '-p', '/home/www-data/tmp/'+n.name()]) - self._docker.execute_cmd(['cp', '-R', '/home/www-data/nodes/'+n.name()+'/blocks', '/home/www-data/tmp/'+n.name()+'/blocks']) - self._docker.execute_cmd(['cp', '/home/www-data/nodes/'+n.name()+'/config.ini', '/home/www-data/tmp/'+n.name()+'/config.ini']) - self._docker.execute_cmd(['cp', '-R', '/home/www-data/nodes/'+n.name()+'/protocol_features', '/home/www-data/tmp/'+n.name()+'/protocol_features']) - self._docker.execute_cmd(['cp', '-R', '/home/www-data/nodes/'+n.name()+'/snapshots', '/home/www-data/tmp/'+n.name()+'/snapshots']) - self._docker.tar_dir(n.name(), 'tmp/'+n.name()) - self._docker.cp_to_host('/home/www-data/'+n.name()+'.tgz', dir) - self._docker.rm('/home/www-data/'+n.name()+'.tgz') - self._docker.rm('/home/www-data/tmp/'+n.name()) - self.start_node(n) - else: - raise dune_node_not_found(n.name()) - - def import_node(self, dir, n): - print("Importing node data ["+n.name()+"]") - if self.node_exists(n): - self.remove_node(n) - stdout, stderr, ec = self._docker.cp_from_host(dir, '/home/www-data/tmp.tgz') - if ec != 0: - print(stderr) - raise dune_error - self._docker.untar('/home/www-data/tmp.tgz') - self._docker.rm('/home/www-data/tmp.tgz') - stdout, stderr, ec = self._docker.execute_cmd(['ls', '/home/www-data/tmp']) - self._docker.execute_cmd(['mkdir', '-p', '/home/www-data/nodes/'+n.name()]) - self._docker.execute_cmd(['mv', '/home/www-data/tmp/'+stdout.split()[0]+'/blocks/blocks.index', '/home/www-data/nodes/'+n.name()+'/blocks/blocks.index']) - self._docker.execute_cmd(['mv', '/home/www-data/tmp/'+stdout.split()[0]+'/blocks/blocks.log', '/home/www-data/nodes/'+n.name()+'/blocks/blocks.log']) - self._docker.execute_cmd(['mv', '/home/www-data/tmp/'+stdout.split()[0]+'/config.ini', '/home/www-data/nodes/'+n.name()+'/config.ini']) - self._docker.execute_cmd(['mv', '/home/www-data/tmp/'+stdout.split()[0]+'/protocol_features', '/home/www-data/nodes/'+n.name()+'/protocol_features']) - self._docker.execute_cmd(['mv', '/home/www-data/tmp/'+stdout.split()[0]+'/snapshots', '/home/www-data/nodes/'+n.name()+'/snapshots']) - self._docker.rm('/home/www-data/tmp/'+stdout.split()[0]) - stdout, stderr, ec = self._docker.execute_cmd(['ls', '/home/www-data/nodes/'+n.name()+'/snapshots']) - self.start_node(n, stdout.split()[0]) - self.set_active(n) - - def get_wallet_pw(self): - pw, stderr, ec = self._docker.execute_cmd(['cat', '.wallet.pw']) - return pw - - def unlock_wallet(self): - so, se, ec = self._docker.execute_cmd(['cleos', 'wallet', 'unlock', '--password', self.get_wallet_pw()]) - - def import_key(self, k): - self.unlock_wallet() - return self.cleos_cmd(['wallet', 'import', '--private-key', k]) - - def create_key(self): - stdout, stderr, ec = self.cleos_cmd(['create', 'key', '--to-console']) - return stdout - - def export_wallet(self): - self._docker.execute_cmd(['mkdir', '/home/www-data/_wallet']) - self._docker.execute_cmd(['cp', '-R', '/root/eosio-wallet', '/home/www-data/_wallet/eosio-wallet']) - self._docker.execute_cmd(['cp', '-R', '/home/www-data/.wallet.pw', '/home/www-data/_wallet/.wallet.pw']) - self._docker.tar_dir("wallet", "/home/www-data/_wallet") - self._docker.cp_to_host("/home/www-data/wallet.tgz", "wallet.tgz") - - def import_wallet(self, d): - self._docker.cp_from_host(d, "/home/www-data/wallet.tgz") - self._docker.untar("/home/www-data/wallet.tgz") - self._docker.execute_cmd(["mv", "/home/www-data/_wallet/.wallet.pw", "/app"]) - self._docker.execute_cmd(["mv", "/home/www-data/_wallet", "/root"]) - - # TODO cleos has a bug displaying keys for K1 so, we need the public key if providing the private key - # Remove that requirement when we fix cleos. - def create_account(self, n, c=None, pub=None, priv=None): - if (priv == None): - keys = self.create_key() - priv = keys.splitlines()[0].split(':')[1][1:] - pub = keys.splitlines()[1].split(':')[1][1:] - print("Creating account ["+n+"] with key pair [Private: "+priv+", Public: "+pub+"]") - - if c == None: - stdout, stderr, ec = self.cleos_cmd(['create', 'account', 'eosio', n, pub]) - else: - stdout, stderr, ec = self.cleos_cmd(['create', 'account', c, n, pub]) - self.import_key(priv) - print(stderr) - - def execute_cmd(self, args): - self._docker.execute_cmd2(args) - - def execute_interactive_cmd(self, args): - self._docker.execute_interactive_cmd(args); - - def build_cmake_proj(self, dir, flags): - container_dir = self._docker.abs_host_path(dir) - build_dir = container_dir+'/build' - if not self._docker.dir_exists(build_dir): - self._docker.execute_cmd(['mkdir', '-p', build_dir]) - self._docker.execute_cmd2(['cmake', '-S', container_dir, '-B', build_dir]+flags) - self._docker.execute_cmd2(['cmake', '--build', build_dir]) - - def ctest_runner(self, dir, flags): - container_dir = self._docker.abs_host_path(dir) - self._docker.execute_cmd_at(container_dir, ['ctest']+flags) - - def gdb(self, exec, flags): - container_exec = self._docker.abs_host_path(exec) - self._docker.execute_interactive_cmd(['gdb', container_exec]+flags) - - def build_other_proj(self, cmd): - self._docker.execute_cmd2([cmd]) - - def init_project(self, name, dir, cmake=True): - if cmake: - bare = [] - else: - bare = ["--bare"] - - stdout, stderr, ec = self._docker.execute_cmd(['cdt-init', '-project', name, '-path', dir]+bare) - if ec != 0: - print(stdout) - raise dune_error() - - - def create_snapshot(self): - ctx = self._context.get_ctx() - url = "http://"+ctx.http_port+"/v1/producer/create_snapshot" - stdout, stderr, ec = self._docker.execute_cmd(['curl', '-X', 'POST', url]) - print(stdout) - print(stderr) - print(url) - - def deploy_contract(self, dir, acnt): - self.cleos_cmd(['set', 'account', 'permission', acnt, 'active', '--add-code']) - stdout, stderr, ec = self.cleos_cmd(['set', 'contract', acnt, dir]) - - if ec == 0: - print(stdout) - else: - print(stderr) - raise dune_error() - - def preactivate_feature(self): - ctx = self._context.get_ctx() - stdout, stderr, ec = self._docker.execute_cmd(['curl', '--noproxy', '-x', 'POST', ctx.http_port+'/v1/producer/schedule_protocol_feature_activations', '-d', '{"protocol_features_to_activate": ["0ec7e080177b2c02b278d5088611686b49d739925a92d9bfcacd7fc6b74053bd"]}']) - - if ec != 0: - print(stderr) - raise dune_error() - else: - print("Preactivate Features: "+stdout) - - def send_action(self, action, acnt, data, permission='eosio@active'): - self.cleos_cmd(['push', 'action', acnt, action, data, '-p', permission], False) - - def get_table(self, acnt, scope, tab): - self.cleos_cmd(['get', 'table', acnt, scope, tab], False) - - def features(self): - return ["KV_DATABASE", - "ACTION_RETURN_VALUE", - "BLOCKCHAIN_PARAMETERS", - "GET_SENDER", - "FORWARD_SETCODE", - "ONLY_BILL_FIRST_AUTHORIZER", - "RESTRICT_ACTION_TO_SELF", - "DISALLOW_EMPTY_PRODUCER_SCHEDULE", - "FIX_LINKAUTH_RESTRICTION", - "REPLACE_DEFERRED", - "NO_DUPLICATE_DEFERRED_ID", - "ONLY_LINK_TO_EXISTING_PERMISSION", - "RAM_RESTRICTIONS", - "WEBAUTHN_KEY", - "WTMSIG_BLOCK_SIGNATURES"] - - def activate_feature(self, code_name, preactivate=False): - if preactivate: - self.preactivate_feature() - self.deploy_contract('/app/reference-contracts/build/contracts/eosio.boot', 'eosio') - - if code_name == "KV_DATABASE": - self.send_action('activate', 'eosio', '["825ee6288fb1373eab1b5187ec2f04f6eacb39cb3a97f356a07c91622dd61d16"]', 'eosio@active') - elif code_name == "ACTION_RETURN_VALUE": - self.send_action('activate', 'eosio', '["c3a6138c5061cf291310887c0b5c71fcaffeab90d5deb50d3b9e687cead45071"]', 'eosio@active') - elif code_name == "BLOCKCHAIN_PARAMETERS": - self.send_action('activate', 'eosio', '["5443fcf88330c586bc0e5f3dee10e7f63c76c00249c87fe4fbf7f38c082006b4"]', 'eosio@active') - elif code_name == "GET_SENDER": - self.send_action('activate', 'eosio', '["f0af56d2c5a48d60a4a5b5c903edfb7db3a736a94ed589d0b797df33ff9d3e1d"]', 'eosio@active') - elif code_name == "FORWARD_SETCODE": - self.send_action('activate', 'eosio', '["2652f5f96006294109b3dd0bbde63693f55324af452b799ee137a81a905eed25"]', 'eosio@active') - elif code_name == "ONLY_BILL_FIRST_AUTHORIZER": - self.send_action('activate', 'eosio', '["8ba52fe7a3956c5cd3a656a3174b931d3bb2abb45578befc59f283ecd816a405"]', 'eosio@active') - elif code_name == "RESTRICT_ACTION_TO_SELF": - self.send_action('activate', 'eosio', '["ad9e3d8f650687709fd68f4b90b41f7d825a365b02c23a636cef88ac2ac00c43"]', 'eosio@active') - elif code_name == "DISALLOW_EMPTY_PRODUCER_SCHEDULE": - self.send_action('activate', 'eosio', '["68dcaa34c0517d19666e6b33add67351d8c5f69e999ca1e37931bc410a297428"]', 'eosio@active') - elif code_name == "FIX_LINKAUTH_RESTRICTION": - self.send_action('activate', 'eosio', '["e0fb64b1085cc5538970158d05a009c24e276fb94e1a0bf6a528b48fbc4ff526"]', 'eosio@active') - elif code_name == "REPLACE_DEFERRED": - self.send_action('activate', 'eosio', '["ef43112c6543b88db2283a2e077278c315ae2c84719a8b25f25cc88565fbea99"]', 'eosio@active') - elif code_name == "NO_DUPLICATE_DEFERRED_ID": - self.send_action('activate', 'eosio', '["4a90c00d55454dc5b059055ca213579c6ea856967712a56017487886a4d4cc0f"]', 'eosio@active') - elif code_name == "ONLY_LINK_TO_EXISTING_PERMISSION": - self.send_action('activate', 'eosio', '["1a99a59d87e06e09ec5b028a9cbb7749b4a5ad8819004365d02dc4379a8b7241"]', 'eosio@active') - elif code_name == "RAM_RESTRICTIONS": - self.send_action('activate', 'eosio', '["4e7bf348da00a945489b2a681749eb56f5de00b900014e137ddae39f48f69d67"]', 'eosio@active') - elif code_name == "WEBAUTHN_KEY": - self.send_action('activate', 'eosio', '["4fca8bd82bbd181e714e283f83e1b45d95ca5af40fb89ad3977b653c448f78c2"]', 'eosio@active') - elif code_name == "WTMSIG_BLOCK_SIGNATURES": - self.send_action('activate', 'eosio', '["299dcb6af692324b899b39f16d5a530a33062804e41f09dc97e9f156b4476707"]', 'eosio@active') - else: - print("Feature Not Found") - raise dune_error() - - def bootstrap_system(self, full): - self.preactivate_feature() - if full: - # create account for multisig contract - self.create_account('eosio.msig', 'eosio') - # create account for token contract - self.create_account('eosio.token', 'eosio') - # create accounts needed by core contract - self.create_account('eosio.bpay', 'eosio') - self.create_account('eosio.names', 'eosio') - self.create_account('eosio.ram', 'eosio') - self.create_account('eosio.ramfee', 'eosio') - self.create_account('eosio.saving', 'eosio') - self.create_account('eosio.stake', 'eosio') - self.create_account('eosio.vpay', 'eosio') - self.create_account('eosio.rex', 'eosio') - - # activate features - self.deploy_contract('/app/reference-contracts/build/contracts/eosio.boot', 'eosio') - - for f in self.features(): - self.activate_feature(f) - - if full: - self.deploy_contract('/app/reference-contracts/build/contracts/eosio.msig', 'eosio.msig') - self.deploy_contract('/app/reference-contracts/build/contracts/eosio.token', 'eosio.token') - self.deploy_contract('/app/reference-contracts/build/contracts/eosio.system', 'eosio') - - def start_webapp(self, dir): - #TODO readdress after the launch - pass - + print( + ' | ' + ports[0] + ' | ' + ports[1] + ' | ' + ports[2]) + + def export_node(self, nod, directory): + if self.node_exists(nod): + self.set_active(nod) + print( + "Exporting data from node [" + nod.name() + "] to location " + + directory) + if not self.is_node_running(nod): + self.start_node(nod) + self.create_snapshot() + self.stop_node(nod) + self._docker.execute_cmd( + ['mkdir', '-p', '/home/www-data/tmp/' + nod.name()]) + self._docker.execute_cmd( + ['cp', '-R', '/home/www-data/nodes/' + nod.name() + '/blocks', + '/home/www-data/tmp/' + nod.name() + '/blocks']) + self._docker.execute_cmd( + ['cp', '/home/www-data/nodes/' + nod.name() + '/config.ini', + '/home/www-data/tmp/' + nod.name() + '/config.ini']) + self._docker.execute_cmd(['cp', '-R', + '/home/www-data/nodes/' + nod.name() + + '/protocol_features', + '/home/www-data/tmp/' + nod.name() + + '/protocol_features']) + self._docker.execute_cmd( + ['cp', '-R', '/home/www-data/nodes/' + nod.name() + '/snapshots', + '/home/www-data/tmp/' + nod.name() + '/snapshots']) + self._docker.tar_dir(nod.name(), 'tmp/' + nod.name()) + self._docker.cp_to_host('/home/www-data/' + nod.name() + '.tgz', + directory) + self._docker.rm_file('/home/www-data/' + nod.name() + '.tgz') + self._docker.rm_file('/home/www-data/tmp/' + nod.name()) + self.start_node(nod) + else: + raise dune_node_not_found(nod.name()) + + def import_node(self, directory, nod): + print("Importing node data [" + nod.name() + "]") + if self.node_exists(nod): + self.remove_node(nod) + stdout, stderr, exit_code = \ + self._docker.cp_from_host(directory, + '/home/www-data/tmp.tgz') + if exit_code != 0: + print(stderr) + raise dune_error + self._docker.untar('/home/www-data/tmp.tgz') + self._docker.rm_file('/home/www-data/tmp.tgz') + stdout, stderr, exit_code = self._docker.execute_cmd( + ['ls', '/home/www-data/tmp']) + self._docker.execute_cmd( + ['mkdir', '-p', '/home/www-data/nodes/' + nod.name()]) + self._docker.execute_cmd(['mv', '/home/www-data/tmp/' + stdout.split()[ + 0] + '/blocks/blocks.index', + '/home/www-data/nodes/' + nod.name() + + '/blocks/blocks.index']) + self._docker.execute_cmd(['mv', '/home/www-data/tmp/' + stdout.split()[ + 0] + '/blocks/blocks.log', + '/home/www-data/nodes/' + nod.name() + + '/blocks/blocks.log']) + self._docker.execute_cmd( + ['mv', '/home/www-data/tmp/' + stdout.split()[0] + '/config.ini', + '/home/www-data/nodes/' + nod.name() + '/config.ini']) + self._docker.execute_cmd(['mv', '/home/www-data/tmp/' + stdout.split()[ + 0] + '/protocol_features', + '/home/www-data/nodes/' + nod.name() + + '/protocol_features']) + self._docker.execute_cmd( + ['mv', '/home/www-data/tmp/' + stdout.split()[0] + '/snapshots', + '/home/www-data/nodes/' + nod.name() + '/snapshots']) + self._docker.rm_file('/home/www-data/tmp/' + stdout.split()[0]) + stdout, stderr, exit_code = self._docker.execute_cmd( + ['ls', '/home/www-data/nodes/' + nod.name() + '/snapshots']) + self.start_node(nod, stdout.split()[0]) + self.set_active(nod) + + def get_wallet_pw(self): + stdout, stderr, exit_code = self._docker.execute_cmd(['cat', '.wallet.pw']) + return stdout + + def unlock_wallet(self): + stdout, stderr, exit_code = self._docker.execute_cmd( + ['cleos', 'wallet', 'unlock', '--password', self.get_wallet_pw()]) + + def import_key(self, key): + self.unlock_wallet() + return self.cleos_cmd(['wallet', 'import', '--private-key', key]) + + def create_key(self): + stdout, stderr, exit_code = self.cleos_cmd(['create', 'key', '--to-console']) + return stdout + + def export_wallet(self): + self._docker.execute_cmd(['mkdir', '/home/www-data/_wallet']) + self._docker.execute_cmd(['cp', '-R', '/root/eosio-wallet', + '/home/www-data/_wallet/eosio-wallet']) + self._docker.execute_cmd(['cp', '-R', '/home/www-data/.wallet.pw', + '/home/www-data/_wallet/.wallet.pw']) + self._docker.tar_dir("wallet", "/home/www-data/_wallet") + self._docker.cp_to_host("/home/www-data/wallet.tgz", "wallet.tgz") + + def import_wallet(self, host): + self._docker.cp_from_host(host, "/home/www-data/wallet.tgz") + self._docker.untar("/home/www-data/wallet.tgz") + self._docker.execute_cmd( + ["mv", "/home/www-data/_wallet/.wallet.pw", "/app"]) + self._docker.execute_cmd(["mv", "/home/www-data/_wallet", "/root"]) + + # pylint: disable=fixme + # TODO cleos has a bug displaying keys for K1 so, we need the public key + # if providing the private key + # Remove that requirement when we fix cleos. + def create_account(self, name, creator=None, pub=None, private=None): + if private is None: + keys = self.create_key() + private = keys.splitlines()[0].split(':')[1][1:] + pub = keys.splitlines()[1].split(':')[1][1:] + print( + "Creating account [" + name + "] with key pair [Private: " + + private + ", Public: " + pub + "]") + + if creator is None: + stdout, stderr, exit_code = self.cleos_cmd( + ['create', 'account', 'eosio', name, pub]) + else: + stdout, stderr, exit_code = self.cleos_cmd( + ['create', 'account', creator, name, pub]) + self.import_key(private) + print(stderr) + + def execute_cmd(self, args): + self._docker.execute_cmd2(args) + + def execute_interactive_cmd(self, args): + self._docker.execute_interactive_cmd(args) + + def build_cmake_proj(self, directory, flags): + container_dir = self._docker.abs_host_path(directory) + build_dir = container_dir + '/build' + if not self._docker.dir_exists(build_dir): + self._docker.execute_cmd(['mkdir', '-p', build_dir]) + self._docker.execute_cmd2( + ['cmake', '-S', container_dir, '-B', build_dir] + flags) + self._docker.execute_cmd2(['cmake', '--build', build_dir]) + + def ctest_runner(self, directory, flags): + container_dir = self._docker.abs_host_path(directory) + self._docker.execute_cmd_at(container_dir, ['ctest'] + flags) + + def gdb(self, executable, flags): + container_exec = self._docker.abs_host_path(executable) + self._docker.execute_interactive_cmd(['gdb', container_exec] + flags) + + def build_other_proj(self, cmd): + self._docker.execute_cmd2([cmd]) + + def init_project(self, name, directory, cmake=True): + if cmake: + bare = [] + else: + bare = ["--bare"] + + stdout, stderr, exit_code = self._docker.execute_cmd( + ['cdt-init', '-project', name, '-path', directory] + bare) + if exit_code != 0: + print(stdout) + raise dune_error() + + def create_snapshot(self): + ctx = self._context.get_ctx() + url = "http://" + ctx.http_port + "/v1/producer/create_snapshot" + stdout, stderr, exit_code = self._docker.execute_cmd( + ['curl', '-X', 'POST', url]) + print(stdout) + print(stderr) + print(url) + + def deploy_contract(self, directory, acnt): + self.cleos_cmd( + ['set', 'account', 'permission', acnt, 'active', '--add-code']) + stdout, stderr, exit_code = self.cleos_cmd( + ['set', 'contract', acnt, directory]) + + if exit_code == 0: + print(stdout) + else: + print(stderr) + raise dune_error() + + def preactivate_feature(self): + ctx = self._context.get_ctx() + stdout, stderr, exit_code = \ + self._docker.execute_cmd( + ['curl', '--noproxy', '-x', 'POST', + ctx.http_port + + '/v1/producer/schedule_protocol_feature_activations', + '-d', + '{"protocol_features_to_activate": [' + '"0ec7e080177b2c02b278d5088611686b49' + 'd739925a92d9bfcacd7fc6b74053bd"]}']) + + if exit_code != 0: + print(stderr) + raise dune_error() + print("Preactivate Features: " + stdout) + + def send_action(self, action, acnt, data, permission='eosio@active'): + self.cleos_cmd( + ['push', 'action', acnt, action, data, '-p', permission], False) + + def get_table(self, acnt, scope, tab): + self.cleos_cmd(['get', 'table', acnt, scope, tab], False) + + @staticmethod + def features(): + return ["KV_DATABASE", + "ACTION_RETURN_VALUE", + "BLOCKCHAIN_PARAMETERS", + "GET_SENDER", + "FORWARD_SETCODE", + "ONLY_BILL_FIRST_AUTHORIZER", + "RESTRICT_ACTION_TO_SELF", + "DISALLOW_EMPTY_PRODUCER_SCHEDULE", + "FIX_LINKAUTH_RESTRICTION", + "REPLACE_DEFERRED", + "NO_DUPLICATE_DEFERRED_ID", + "ONLY_LINK_TO_EXISTING_PERMISSION", + "RAM_RESTRICTIONS", + "WEBAUTHN_KEY", + "WTMSIG_BLOCK_SIGNATURES"] + + def activate_feature(self, code_name, preactivate=False): + if preactivate: + self.preactivate_feature() + self.deploy_contract( + '/app/reference-contracts/build/contracts/eosio.boot', 'eosio') + + if code_name == "KV_DATABASE": + self.send_action( + 'activate', + 'eosio', + '["825ee6288fb1373eab1b5187ec2f04f6ea' + 'cb39cb3a97f356a07c91622dd61d16"]', + 'eosio@active') + elif code_name == "ACTION_RETURN_VALUE": + self.send_action('activate', 'eosio', + '["c3a6138c5061cf291310887c0b5c71' + 'fcaffeab90d5deb50d3b9e687cead45071"]', + 'eosio@active') + elif code_name == "BLOCKCHAIN_PARAMETERS": + self.send_action('activate', 'eosio', + '["5443fcf88330c586bc0e5f3dee10e7f' + '63c76c00249c87fe4fbf7f38c082006b4"]', + 'eosio@active') + elif code_name == "GET_SENDER": + self.send_action('activate', 'eosio', + '["f0af56d2c5a48d60a4a5b5c903edfb7db3a' + '736a94ed589d0b797df33ff9d3e1d"]', + 'eosio@active') + elif code_name == "FORWARD_SETCODE": + self.send_action('activate', 'eosio', + '["2652f5f96006294109b3dd0bbde63693f' + '55324af452b799ee137a81a905eed25"]', + 'eosio@active') + elif code_name == "ONLY_BILL_FIRST_AUTHORIZER": + self.send_action('activate', 'eosio', + '["8ba52fe7a3956c5cd3a656a3174b931d' + '3bb2abb45578befc59f283ecd816a405"]', + 'eosio@active') + elif code_name == "RESTRICT_ACTION_TO_SELF": + self.send_action('activate', 'eosio', + '["ad9e3d8f650687709fd68f4b90b41f7d8' + '25a365b02c23a636cef88ac2ac00c43"]', + 'eosio@active') + elif code_name == "DISALLOW_EMPTY_PRODUCER_SCHEDULE": + self.send_action('activate', 'eosio', + '["68dcaa34c0517d19666e6b33add67351d8' + 'c5f69e999ca1e37931bc410a297428"]', + 'eosio@active') + elif code_name == "FIX_LINKAUTH_RESTRICTION": + self.send_action('activate', 'eosio', + '["e0fb64b1085cc5538970158d05a009c24e2' + '76fb94e1a0bf6a528b48fbc4ff526"]', + 'eosio@active') + elif code_name == "REPLACE_DEFERRED": + self.send_action('activate', 'eosio', + '["ef43112c6543b88db2283a2e077278c315ae' + '2c84719a8b25f25cc88565fbea99"]', + 'eosio@active') + elif code_name == "NO_DUPLICATE_DEFERRED_ID": + self.send_action('activate', 'eosio', + '["4a90c00d55454dc5b059055ca213579c6ea85' + '6967712a56017487886a4d4cc0f"]', + 'eosio@active') + elif code_name == "ONLY_LINK_TO_EXISTING_PERMISSION": + self.send_action('activate', 'eosio', + '["1a99a59d87e06e09ec5b028a9cbb7749b4a5ad' + '8819004365d02dc4379a8b7241"]', + 'eosio@active') + elif code_name == "RAM_RESTRICTIONS": + self.send_action('activate', 'eosio', + '["4e7bf348da00a945489b2a681749eb56f5de00' + 'b900014e137ddae39f48f69d67"]', + 'eosio@active') + elif code_name == "WEBAUTHN_KEY": + self.send_action('activate', 'eosio', + '["4fca8bd82bbd181e714e283f83e1b45d95ca5af' + '40fb89ad3977b653c448f78c2"]', + 'eosio@active') + elif code_name == "WTMSIG_BLOCK_SIGNATURES": + self.send_action('activate', 'eosio', + '["299dcb6af692324b899b39f16d5a530a3306280' + '4e41f09dc97e9f156b4476707"]', + 'eosio@active') + else: + print("Feature Not Found") + raise dune_error() + + def bootstrap_system(self, full): + self.preactivate_feature() + if full: + # create account for multisig contract + self.create_account('eosio.msig', 'eosio') + # create account for token contract + self.create_account('eosio.token', 'eosio') + # create accounts needed by core contract + self.create_account('eosio.bpay', 'eosio') + self.create_account('eosio.names', 'eosio') + self.create_account('eosio.ram', 'eosio') + self.create_account('eosio.ramfee', 'eosio') + self.create_account('eosio.saving', 'eosio') + self.create_account('eosio.stake', 'eosio') + self.create_account('eosio.vpay', 'eosio') + self.create_account('eosio.rex', 'eosio') + + # activate features + self.deploy_contract( + '/app/reference-contracts/build/contracts/eosio.boot', 'eosio') + + for feature in self.features(): + self.activate_feature(feature) + + if full: + self.deploy_contract( + '/app/reference-contracts/build/contracts/eosio.msig', + 'eosio.msig') + self.deploy_contract( + '/app/reference-contracts/build/contracts/eosio.token', + 'eosio.token') + self.deploy_contract( + '/app/reference-contracts/build/contracts/eosio.system', + 'eosio') + + def start_webapp(self, directory): + # pylint: disable=fixme + # TODO readdress after the launch + pass + + @property + def docker(self): + return self._docker From 3d91bce5d037054b4d5254eb03d8bac20706aa79 Mon Sep 17 00:00:00 2001 From: Alexander Molchevsky Date: Fri, 4 Nov 2022 02:23:43 +0200 Subject: [PATCH 2/2] parameter name changed to more understandable --- src/dune/__main__.py | 2 +- src/dune/dune.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dune/__main__.py b/src/dune/__main__.py index bb7af87a..b7a7c552 100644 --- a/src/dune/__main__.py +++ b/src/dune/__main__.py @@ -148,7 +148,7 @@ elif args.send_action is not None: dune_sys.send_action(args.send_action[1], args.send_action[0], args.send_action[2], args.send_action[3]) - + elif args.get_table is not None: dune_sys.get_table(args.get_table[0], args.get_table[1], args.get_table[2]) diff --git a/src/dune/dune.py b/src/dune/dune.py index a072e65f..e139a215 100644 --- a/src/dune/dune.py +++ b/src/dune/dune.py @@ -349,8 +349,8 @@ def export_wallet(self): self._docker.tar_dir("wallet", "_wallet") self._docker.cp_to_host("/app/wallet.tgz", "wallet.tgz") - def import_wallet(self, d): - self._docker.cp_from_host(d, "wallet.tgz") + def import_wallet(self, path): + self._docker.cp_from_host(path, "wallet.tgz") self._docker.untar("wallet.tgz") self._docker.execute_cmd(["mv", "_wallet/.wallet.pw", "/app"]) self._docker.execute_cmd(["mv", "_wallet", "/root"])