def node_from_config(config): name = config['NodeName'] signing_key = generate_signing_key(wifstr=read_key_file(config['KeyFile'])) (gossip_host, gossip_port) = parse_listen_directives(config)['gossip'] # stubbing endpoint address for now endpoint_addr = (None, None) nd = node.Node(address=(socket.gethostbyname(gossip_host), gossip_port), identifier=generate_identifier(signing_key), signingkey=signing_key, name=name, endpoint_address=endpoint_addr, ) return nd
def launch(self, launch=True): self.Url = "http://{}:{}".format(self.config['Host'], self.config['HttpPort']) self.config['LogFile'] = os.path.join(self.dataDir, "{}.log".format(self.Name)) self.logFile = self.config['LogFile'] self.config['KeyFile'] = os.path.join(self.dataDir, "{}.wif".format(self.Name)) if not os.path.isfile(self.config['KeyFile']): with open(self.config['KeyFile'], 'w') as fp: fp.write(self.Key) fp.write("\n") else: self.Key = read_key_file(self.config['KeyFile']) self.Address = get_address_from_private_key_wif(self.Key) configFileName = "{}.json".format(self.Name) self.configFile = os.path.join(self.dataDir, configFileName) with open(self.configFile, 'w') as fp: json.dump(self.config, fp) args = [ sys.executable, # Fix for windows, where script are not executable self.txnvalidater, "--conf-dir", self.dataDir, "--config", configFileName ] # redirect stdout and stderror self.stdoutFile = os.path.join(self.dataDir, "{}.out".format(self.Name)) self.stderrFile = os.path.join(self.dataDir, "{}.err".format(self.Name)) self.command = " ".join(args) env = os.environ.copy() env["PYTHONPATH"] = os.pathsep.join(sys.path) if launch: self.output = open(self.stdoutFile, 'w') self.outerr = open(self.stderrFile, 'w') self.handle = subprocess.Popen(args, stdout=self.output, stderr=self.outerr, env=env) else: self.handle = None
def node_from_config(config): name = config['NodeName'] signing_key = generate_signing_key(wifstr=read_key_file(config['KeyFile'])) listen_info = config.get("Listen") (gossip_host, gossip_port) = parse_listen_directives(listen_info)['gossip'] # stubbing endpoint address for now endpoint_addr = (None, None) nd = node.Node( address=(socket.gethostbyname(gossip_host), gossip_port), identifier=generate_identifier(signing_key), signingkey=signing_key, name=name, endpoint_address=endpoint_addr, ) return nd
def setup(self): self.state = mktplace_state.MarketPlaceState(self.urls[0]) with Progress("Creating participants") as p: for i in range(0, self.count): name = "actor-{}".format(i) keyfile = os.path.join(self.testDir, "{}.wif".format(name)) if os.path.exists(keyfile): key = read_key_file(keyfile) else: key = signing.encode_privkey(signing.generate_privkey(), 'wif') write_key_file(keyfile, key) url = self.urls[random.randint(0, len(self.urls) - 1)] a = MktActor(name, url, key) self.Actors.append(a) p.step() with Progress("Registering actors assets") as p: for a in self.Actors: # create assets a.register_asset(a.Name + "-asset") p.step() self.wait_for_transaction_commits() with Progress("Registering holdings") as p: for a in self.Actors: a.update() a.offers = [] for a2 in self.Actors: count = 0 if a is a2: # for each iteration we need 1 to pay with and 1 to # give count = 2 * self.count * self.iterations for ast in a2.assets.keys(): a.register_holding(ast, count) p.step() self.wait_for_transaction_commits()
def setup(self): self.state = mktplace_state.MarketPlaceState(self.urls[0]) with Progress("Creating participants") as p: for i in range(0, self.count): name = "actor-{}".format(i) keyfile = os.path.join(self.testDir, "{}.wif".format(name)) if os.path.exists(keyfile): key = read_key_file(keyfile) else: key = pybitcointools.encode_privkey( pybitcointools.random_key(), 'wif') write_key_file(keyfile, key) url = self.urls[random.randint(0, len(self.urls) - 1)] a = MktActor(name, url, key) self.Actors.append(a) p.step() with Progress("Registering actors assets") as p: for a in self.Actors: # create assets a.register_asset(a.Name + "-asset") p.step() self.wait_for_transaction_commits() with Progress("Registering holdings") as p: for a in self.Actors: a.update() a.offers = [] for a2 in self.Actors: count = 0 if a is a2: # for each iteration we need 1 to pay with and 1 to # give count = 2 * self.count * self.iterations for ast in a2.assets.keys(): a.register_holding(ast, count) p.step() self.wait_for_transaction_commits()
def mirror_validator_parsing(args): # Get ledger config: # ...set the default value of config because argparse 'default' in # ...combination with action='append' does the wrong thing. if args.config is None: args.config = ['txnvalidator.js'] # ...convert any comma-delimited argument strings to list elements for arglist in [args.config]: if arglist is not None: for arg in arglist: if ',' in arg: loc = arglist.index(arg) arglist.pop(loc) for element in reversed(arg.split(',')): arglist.insert(loc, element) options_config = ArgparseOptionsConfig([('conf_dir', 'ConfigDirectory'), ('data_dir', 'DataDirectory'), ('type', 'LedgerType'), ('log_config', 'LogConfigFile'), ('keyfile', 'KeyFile'), ('node', 'NodeName'), ('verbose', 'Verbose'), ('family', 'TransactionFamilies')], args) cfg = get_validator_configuration(args.config, options_config) # Duplicate some configuration massaging done by validator_cli from txnintegration.utils import read_key_file # avoids dependency issue if "KeyFile" in cfg: keyfile = cfg["KeyFile"] if os.path.isfile(keyfile): LOGGER.info('read signing key from %s', keyfile) key = read_key_file(keyfile) cfg['SigningKey'] = key else: LOGGER.warn('unable to locate key file %s', keyfile) else: LOGGER.warn('no key file specified') return cfg
def __init__(self, txn_validator, config, data_dir, admin_node, log_config, static_node=False): self._txn_validator = txn_validator self.name = config['NodeName'] self.config = config self.log_config = log_config self._admin_node = admin_node self.static_node = static_node self._data_dir = data_dir # Handle validator keys if self.static_node and 'KeyFile' in config.keys(): self._key = read_key_file(config['KeyFile']) self._address = get_address_from_private_key_wif(self._key) elif self.static_node: self._key = config['SigningKey'] self._address = config['Identifier'] else: self._key = generate_private_key() self._address = get_address_from_private_key_wif(self._key) self.url = None self._command = None self._stdout_file = None self._output = None self._stderr_file = None self._outerr = None self._config_file = None self._log_file = None self._handle = None
def launch(self, launch=True, genesis=False, daemon=False, delay=False): self.Url = "http://{}:{}".format(self.config['Host'], self.config['HttpPort']) self.config['LogDirectory'] = self.dataDir self.logFile = os.path.join(self.dataDir, "{}.log".format(self.Name)) if os.path.exists(self.logFile): # delete existing log file os.remove(self.logFile) self.config['KeyFile'] = os.path.join(self.dataDir, "{}.wif".format(self.Name)) if not os.path.isfile(self.config['KeyFile']): with open(self.config['KeyFile'], 'w') as fp: fp.write(self.Key) fp.write("\n") else: self.Key = read_key_file(self.config['KeyFile']) self.Address = get_address_from_private_key_wif(self.Key) if self.log_config: for v in self.log_config["handlers"].itervalues(): if 'filename' in v: filename = os.path.join( self.dataDir, "{}-{}".format(self.Name, os.path.basename(v['filename']))) v['filename'] = filename log_config_file = os.path.join(self.dataDir, "{}-log-config.js" .format(self.Name)) with open(log_config_file, 'w') as fp: json.dump(self.log_config, fp) self.config['LogConfigFile'] = log_config_file configFileName = "{}.json".format(self.Name) self.configFile = os.path.join(self.dataDir, configFileName) with open(self.configFile, 'w') as fp: json.dump(self.config, fp) args = [ sys.executable, # Fix for windows, where script are not executable self.txnvalidater, "--conf-dir", self.dataDir, "--config", configFileName ] if genesis: args.append("--genesis") if daemon: args.append("--daemon") if delay: args.append("--delay-start") # redirect stdout and stderror self.stdoutFile = os.path.join(self.dataDir, "{}.out".format(self.Name)) self.stderrFile = os.path.join(self.dataDir, "{}.err".format(self.Name)) self.command = " ".join(args) env = os.environ.copy() env["PYTHONPATH"] = os.pathsep.join(sys.path) if launch: self.output = open(self.stdoutFile, 'w') self.outerr = open(self.stderrFile, 'w') self.handle = subprocess.Popen(args, stdout=self.output, stderr=self.outerr, env=env) else: self.handle = None
def launch(self, launch=True, genesis=False, daemon=False, delay=False, node=None): listen_directives = parse_listen_directives(self.config) self.url = "http://{}:{}".format(listen_directives['http'].host, listen_directives['http'].port) self.config['LogDirectory'] = self._data_dir self._log_file = os.path.join(self._data_dir, "{}-debug.log".format(self.name)) if os.path.exists(self._log_file): # delete existing log file os.remove(self._log_file) self.config['KeyFile'] = os.path.join(self._data_dir, "{}.wif".format(self.name)) if self.static_node: if os.path.isfile(self.config['KeyFile']): os.remove(self.config['KeyFile']) if not os.path.isfile(self.config['KeyFile']): with open(self.config['KeyFile'], 'w') as fp: fp.write(self._key) fp.write("\n") else: self._key = read_key_file(self.config['KeyFile']) self._address = get_address_from_private_key_wif(self._key) if self.log_config: for v in self.log_config["handlers"].itervalues(): if 'filename' in v: filename = os.path.join( self._data_dir, "{}-{}".format(self.name, os.path.basename(v['filename']))) v['filename'] = filename # pick the last log file... not sure # how we can pick a better one with out completely # parsing the log config or adding our own entry self._log_file = filename log_config_file = os.path.join( self._data_dir, "{}-log-config.js".format(self.name)) with open(log_config_file, 'w') as fp: json.dump(self.log_config, fp, sort_keys=True, indent=4, separators=(',', ': ')) self.config['LogConfigFile'] = log_config_file config_file_name = "{}.json".format(self.name) self._config_file = os.path.join(self._data_dir, config_file_name) with open(self._config_file, 'w') as fp: json.dump(self.config, fp, sort_keys=True, indent=4, separators=(',', ': ')) args = [ sys.executable, # Fix for windows, where script are not executable self._txn_validator, "--conf-dir", self._data_dir, "--config", config_file_name ] if genesis: args.append("--genesis") if daemon: args.append("--daemon") if delay: args.append("--delay-start") # redirect stdout and stderror self._stdout_file = os.path.join(self._data_dir, "{}.out".format(self.name)) self._stderr_file = os.path.join(self._data_dir, "{}.err".format(self.name)) self._command = " ".join(args) env = os.environ.copy() env["PYTHONPATH"] = os.pathsep.join(sys.path) if launch: self._output = open(self._stdout_file, 'w') self._outerr = open(self._stderr_file, 'w') self._handle = subprocess.Popen(args, stdout=self._output, stderr=self._outerr, env=env) else: self._handle = None
def launch(self, launch=True, genesis=False, daemon=False, delay=False, node=None): listen_directives = parse_listen_directives(self.config) self.url = "http://{}:{}".format(listen_directives['http'].host, listen_directives['http'].port) self.config['LogDirectory'] = self._data_dir self._log_file = os.path.join(self._data_dir, "{}-debug.log".format(self.name)) if os.path.exists(self._log_file): # delete existing log file os.remove(self._log_file) self.config['KeyFile'] = os.path.join(self._data_dir, "{}.wif".format(self.name)) if self.static_node: if os.path.isfile(self.config['KeyFile']): os.remove(self.config['KeyFile']) if not os.path.isfile(self.config['KeyFile']): with open(self.config['KeyFile'], 'w') as fp: fp.write(self._key) fp.write("\n") else: self._key = read_key_file(self.config['KeyFile']) self._address = get_address_from_private_key_wif(self._key) if self.log_config: for v in self.log_config["handlers"].itervalues(): if 'filename' in v: filename = os.path.join( self._data_dir, "{}-{}".format(self.name, os.path.basename(v['filename']))) v['filename'] = filename # pick the last log file... not sure # how we can pick a better one with out completely # parsing the log config or adding our own entry self._log_file = filename log_config_file = os.path.join(self._data_dir, "{}-log-config.js" .format(self.name)) with open(log_config_file, 'w') as fp: json.dump(self.log_config, fp, sort_keys=True, indent=4, separators=(',', ': ')) self.config['LogConfigFile'] = log_config_file config_file_name = "{}.json".format(self.name) self._config_file = os.path.join(self._data_dir, config_file_name) with open(self._config_file, 'w') as fp: json.dump(self.config, fp, sort_keys=True, indent=4, separators=(',', ': ')) args = [ sys.executable, # Fix for windows, where script are not executable self._txn_validator, "--conf-dir", self._data_dir, "--config", config_file_name ] if genesis: args.append("--genesis") if daemon: args.append("--daemon") if delay: args.append("--delay-start") # redirect stdout and stderror self._stdout_file = os.path.join(self._data_dir, "{}.out".format(self.name)) self._stderr_file = os.path.join(self._data_dir, "{}.err".format(self.name)) self._command = " ".join(args) env = os.environ.copy() env["PYTHONPATH"] = os.pathsep.join(sys.path) if launch: self._output = open(self._stdout_file, 'w') self._outerr = open(self._stderr_file, 'w') self._handle = subprocess.Popen(args, stdout=self._output, stderr=self._outerr, env=env) else: self._handle = None