def __init__(self, txn_validator, config, data_dir, admin_node, log_config, static_node=False): self._txn_validator = txn_validator self.id = config['id'] 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: 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 __init__(self, txn_validator, config, data_dir, admin_node, log_config, static_node=False): self._txn_validator = txn_validator self.id = config['id'] 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: 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 __init__(self, cfg, n_mag, use_genesis=True, base_host=None, base_name='validator', base_port=9000, base_http_port=8800, provider=None): self.n_mag = n_mag self.use_genesis = use_genesis self.provider = None if provider is not None: self.provider = provider # set up nodes self.nodes = [] for idx in range(n_mag): node_name = "{0}-{1}".format(base_name, idx) # get base node configuration nd = None if self.provider is None: nd = OrderedDict() nd["NodeName"] = node_name key = generate_private_key() nd["SigningKey"] = key nd["Identifier"] = get_address_from_private_key_wif(key) else: nd = self.provider.provision_validator(node_name) # update basic configuration nd.update(cfg) nd["id"] = idx # ...networking information nd['Host'] = "localhost" if base_host is not None: nd['Host'] = "%s-%s" % (base_host, idx) nd["Port"] = base_port + idx nd["HttpPort"] = base_http_port + idx nd['Listen'] = [ '%s:%s/UDP gossip' % (nd['Host'], nd['Port']), '%s:%s/TCP http' % (nd['Host'], nd['HttpPort']), ] nd["Nodes"] = [] nd["Peers"] = [] # ...role information nd["LedgerURL"] = [] nd["GenesisLedger"] = False if idx == 0 and use_genesis is True: nd["GenesisLedger"] = True # aux information nd["Quorum"] = [] self.nodes.append(nd) self.node_mat = None self.peer_mat = None self.quorum_mat = None self.blacklist_mat = None self.con_mat = AdjacencyMatrixAnimation(n_mag)
def __init__(self, txnvalidater, config, dataDir, adminNode): self.txnvalidater = txnvalidater self.Id = config['id'] self.Name = config['NodeName'] self.config = config self.AdminNode = adminNode self.dataDir = dataDir # Generate key for validator self.Key = generate_private_key() self.Address = get_address_from_private_key_wif(self.Key)
def __init__(self, txnvalidater, config, dataDir, adminNode): self.txnvalidater = txnvalidater self.Id = config['id'] self.Name = config['NodeName'] self.config = config self.AdminNode = adminNode self.dataDir = dataDir # Generate key for validator self.Key = generate_private_key() self.Address = get_address_from_private_key_wif(self.Key)
def __init__(self, n_mag, overrides=None, base_name='validator', base_port=None, base_http_port=None, host=None, endpoint_host=None, provider=None): overrides = {} if overrides is None else overrides base_port = 9000 if base_port is None else base_port base_http_port = 8800 if base_http_port is None else base_http_port self.n_mag = n_mag self.provider = None if provider is not None: self.provider = provider # set up nodes self.nodes = [] for idx in range(n_mag): node_name = "{0}-{1}".format(base_name, idx) # get base node configuration nd = None if self.provider is None: nd = OrderedDict() nd["NodeName"] = node_name key = generate_private_key() nd["SigningKey"] = key nd["Identifier"] = get_address_from_private_key_wif(key) else: nd = self.provider.provision_validator(node_name) # update basic configuration nd.update(overrides) nd["id"] = idx # ...networking information net_info = self.resolve_networking_info(host, base_port + idx, base_http_port + idx, endpoint_host) nd.update(net_info) nd["Nodes"] = [] nd["Peers"] = [] nd["Blacklist"] = [] # initial athourity nd["LedgerURL"] = [] # aux information nd["Quorum"] = [] self.nodes.append(nd) self.node_mat = None self.peer_mat = None self.quorum_mat = None self.blacklist_mat = None
def __init__(self, n_mag, overrides=None, base_name='validator', base_port=None, base_http_port=None, host=None, endpoint_host=None, provider=None): overrides = {} if overrides is None else overrides base_port = 9000 if base_port is None else base_port base_http_port = 8800 if base_http_port is None else base_http_port self.n_mag = n_mag self.provider = None if provider is not None: self.provider = provider # set up nodes self.nodes = [] for idx in range(n_mag): node_name = "{0}-{1}".format(base_name, idx) # get base node configuration nd = None if self.provider is None: nd = OrderedDict() nd["NodeName"] = node_name key = generate_private_key() nd["SigningKey"] = key nd["Identifier"] = get_address_from_private_key_wif(key) else: nd = self.provider.provision_validator(node_name) # update basic configuration nd.update(overrides) nd["id"] = idx # ...networking information net_info = self.resolve_networking_info(host, base_port + idx, base_http_port + idx, endpoint_host) nd.update(net_info) nd["Nodes"] = [] nd["Peers"] = [] nd["Blacklist"] = [] # initial athourity nd["LedgerURL"] = [] # aux information self.nodes.append(nd) self.node_mat = None self.peer_mat = None self.blacklist_mat = None
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 __init__( self, cfg, n_mag, use_genesis=True, base_host=None, base_name='validator', base_port=9000, base_http_port=8800, ): self.n_mag = n_mag self.use_genesis = use_genesis self.keys = [generate_private_key() for _ in range(n_mag)] self.nodes = [] for (idx, wif) in enumerate(self.keys): nd = OrderedDict() nd.update(cfg) nd["id"] = idx nd["NodeName"] = "{0}-{1}".format(base_name, idx) nd["Identifier"] = get_address_from_private_key_wif(wif) nd['Host'] = "localhost" if base_host is not None: nd['Host'] = "%s-%s" % (base_host, idx) nd["Port"] = base_port + idx nd["HttpPort"] = base_http_port + idx nd["Nodes"] = [] nd["Peers"] = [] nd["Quorum"] = [] nd['Listen'] = [ '%s:%s/UDP gossip' % (nd['Host'], nd['Port']), '%s:%s/TCP http' % (nd['Host'], nd['HttpPort']), ] nd["LedgerURL"] = [] nd["GenesisLedger"] = False if idx == 0 and use_genesis is True: nd["GenesisLedger"] = True self.nodes.append(nd) self.node_mat = None self.peer_mat = None self.quorum_mat = None self.blacklist_mat = None self.con_mat = AdjacencyMatrixAnimation(n_mag)
def __init__(self, cfg, n_mag, use_genesis=True, base_host=None, base_name='validator', base_port=9000, base_http_port=8800, ): self.n_mag = n_mag self.use_genesis = use_genesis self.keys = [generate_private_key() for _ in range(n_mag)] self.nodes = [] for (idx, wif) in enumerate(self.keys): nd = OrderedDict() nd.update(cfg) nd["id"] = idx nd["NodeName"] = "{0}-{1}".format(base_name, idx) nd["Identifier"] = get_address_from_private_key_wif(wif) nd['Host'] = "localhost" if base_host is not None: nd['Host'] = "%s-%s" % (base_host, idx) nd["Port"] = base_port + idx nd["HttpPort"] = base_http_port + idx nd["Nodes"] = [] nd["Peers"] = [] nd["Quorum"] = [] nd['Listen'] = [ '%s:%s/UDP gossip' % (nd['Host'], nd['Port']), '%s:%s/TCP http' % (nd['Host'], nd['HttpPort']), ] nd["LedgerURL"] = [] nd["GenesisLedger"] = False if idx == 0 and use_genesis is True: nd["GenesisLedger"] = True self.nodes.append(nd) self.node_mat = None self.peer_mat = None self.quorum_mat = None self.blacklist_mat = None self.con_mat = AdjacencyMatrixAnimation(n_mag)
def __init__(self, name, ledger_url, key=None, state=None): # record of all transactions this actor has committed self.transactions = [] self.accounts = None self.assetType = None self.assets = {} self.holdings = {} # map, fully qualified names self.holdingsByAsset = {} # map, fqn asset to fqn holding id. self.Name = name self.state = state if self.state is None: self.state = mktplace_state.MarketPlaceState(ledger_url) # create keys # Generate key for validator self.Key = key if not self.Key: self.Key = generate_private_key() self.creator = self.state.n2i('//{0}'.format(name)) if self.creator: addr = get_address_from_private_key_wif(self.Key) partxn = self.state.State[self.creator] if addr != partxn["address"]: raise Exception("Participant key mismatch") self.client = mktplace_client.MarketPlaceClient(ledger_url, creator=self.creator, name=name, keystring=self.Key, state=self.state) if not self.creator: self.creator = self.client.register_participant(name) self.client.CreatorID = self.creator self.transactions.append(self.creator) if not self.creator: raise self.state.CreatorID = self.creator self._register_account() self._register_asset_type() # LOAD objects from state for no in self.state.list(creator=self.creator, fields="*"): n = no['name'] if n.startswith(self.get_qualified_name("/assets/")): o = self.get_state_object(n) if self.creator != o["creator"]: raise Exception("Transaction namespace violation.") self.assets[n] = no elif n.startswith(self.get_qualified_name("/assets")): o = self.get_state_object(n) if self.creator != o["creator"]: raise Exception("Transaction namespace violation.") self.assetType = no elif n.startswith(self.get_qualified_name("/account/")): o = self.get_state_object(n) if self.creator != o["creator"]: raise Exception("Transaction namespace violation.") self.holdings[n] = self.state.NameMap[n] asset_name = self.state.i2n(o["asset"]) self.holdingsByAsset[asset_name] = no
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 __init__(self, name, ledger_url, key=None, state=None): # record of all transactions this actor has committed self.transactions = [] self.accounts = None self.assetType = None self.assets = {} self.holdings = {} # map, fully qualified names self.holdingsByAsset = {} # map, fqn asset to fqn holding id. self.Name = name self.state = state if self.state is None: self.state = mktplace_state.MarketPlaceState(ledger_url) # create keys # Generate key for validator self.Key = key if not self.Key: self.Key = generate_private_key() self.creator = self.state.n2i('//{0}'.format(name)) if self.creator: addr = get_address_from_private_key_wif(self.Key) partxn = self.state.State[self.creator] if addr != partxn["address"]: raise Exception("Participant key mismatch") self.client = mktplace_client.MarketPlaceClient(ledger_url, creator=self.creator, name=name, keystring=self.Key, state=self.state) if not self.creator: self.creator = self.client.register_participant(name) self.client.CreatorID = self.creator self.transactions.append(self.creator) if not self.creator: raise self.state.CreatorID = self.creator self._register_account() self._register_asset_type() # LOAD objects from state for no in self.state.list(creator=self.creator, fields="*"): n = no['name'] if n.startswith(self.get_qualified_name("/assets/")): o = self.get_state_object(n) if self.creator != o["creator"]: raise Exception("Transaction namespace violation.") self.assets[n] = no elif n.startswith(self.get_qualified_name("/assets")): o = self.get_state_object(n) if self.creator != o["creator"]: raise Exception("Transaction namespace violation.") self.assetType = no elif n.startswith(self.get_qualified_name("/account/")): o = self.get_state_object(n) if self.creator != o["creator"]: raise Exception("Transaction namespace violation.") self.holdings[n] = self.state.NameMap[n] asset_name = self.state.i2n(o["asset"]) self.holdingsByAsset[asset_name] = no
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