def _get_account_for_cp2(network: Network, accounts: int, deploy_idx: int) -> Account: """Returns counter-party 2 account. """ if accounts != 0: account_idx = _get_account_idx_for_deploy(accounts, deploy_idx) if not account_idx in _ACCOUNTS: _ACCOUNTS[account_idx] = factory.create_account(network.name, AccountType.OTHER, index=account_idx) return _ACCOUNTS[account_idx] return factory.create_account(network.name, AccountType.OTHER, index=deploy_idx)
def _register_network(chainspec: dict, network_idx: int, count_of_bootstrap_nodes: int, count_of_genesis_nodes: int, path_to_faucet_pvk: pathlib.Path): """Register a network. """ # Set network. network = factory.create_network( f"lrt{network_idx}", chainspec['genesis']['name'], count_of_bootstrap_nodes, count_of_genesis_nodes, ) # Set faucet. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_to_faucet_pvk, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX) network.faucet = factory.create_account( network=network.name, typeof=AccountType.NETWORK_FAUCET, index=0, key_algo=crypto.DEFAULT_KEY_ALGO, private_key=private_key, public_key=public_key, ) # Push to cache. cache.infra.set_network(network) utils.log(f"registered network") return network
def main(args): """Entry point. :param args: Parsed CLI arguments. """ utils.log(f"Dispatching {args.transfers} native transfers:") network, nodeset = get_network_nodeset_by_node(args) cp1 = network.faucet cp2 = factory.create_account(network.name, AccountType.OTHER, index=1) utils.log( f"... node : {nodeset[0].address if len(nodeset) == 1 else 'any'}" ) utils.log(f"... amount / transfer : {args.amount}") utils.log(f"... counter-party 1 : {cp1.account_key}") utils.log(f"... counter-party 2 : {cp2.account_key}") with Timer() as timer: for idx in range(1, args.transfers + 1): chain.set_transfer_native( chain.DeployDispatchInfo(cp1, network, random.choice(nodeset)), cp2, args.amount, verbose=False, ) utils.log(f"Dispatch complete") utils.log(f"... total amount : {args.amount * args.transfers}") utils.log(f"... total time : {timer.elapsed:.2f} seconds") utils.log( f"... dispatch rate : {(args.transfers / timer.elapsed):.2f} / second" )
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Pull. network_id = factory.create_network_id(args.network) network = cache.infra.get_network(network_id) if network is None: raise ValueError("Unregistered network.") # Set key pair. pvk, pbk = crypto.get_key_pair_from_pvk_pem_file( args.pem_path, crypto.KeyAlgorithm.ED25519, crypto.KeyEncoding.HEX, ) # Set faucet. network.faucet = factory.create_account( network=network.name, typeof=AccountType.NETWORK_FAUCET, index=0, key_algo=crypto.KeyAlgorithm.ED25519, private_key=pvk, public_key=pbk, ) # Push. cache.infra.set_network(network) # Inform. utils.log(f"Network {args.network} faucet key was successfully registered")
def _register_faucet(network: Network, path_pvk_pem: str): """Register a network's faucet account. """ # Set key pair. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_pvk_pem, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX ) # Set faucet. network.faucet = factory.create_account( network=network.name, typeof=AccountType.NETWORK_FAUCET, index=0, key_algo=crypto.DEFAULT_KEY_ALGO, private_key=private_key, public_key=public_key, ) # Push. cache.infra.set_network(network) # Inform. utils.log(f"Registered {network.name} - faucet key")
def _register_node( network: Network, index: int, info: typing.Tuple[str, int, pathlib.Path] ): """Register a network node. """ # Destructure node info. host, weight, path_sk_pem = info # Set default ports. port_rpc = 7777 port_rest = 8888 port_sse = 9999 # Set node. node = factory.create_node( group=NodeGroup.UNKNOWN, host=host, index=index, network_id=factory.create_network_id(network.name_raw), port_rest=port_rest, port_rpc=port_rpc, port_event=port_sse, typeof=NodeType.VALIDATOR, weight=weight, ) # Set bonding key pair. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_sk_pem, algo=crypto.KeyAlgorithm.ED25519, encoding=crypto.KeyEncoding.HEX, ) # Set bonding account. node.account = factory.create_account( network=network.name, typeof=AccountType.VALIDATOR_BOND, index=index, key_algo=crypto.KeyAlgorithm.ED25519, private_key=private_key, public_key=public_key, ) # Push. cache.infra.set_node(node) # Inform. utils.log(f"registered {network.name_raw} - {node.address_rpc} : {node.typeof.name}")
def _register_node(network: Network, accounts: dict, index: int, info: typing.Tuple[str, dict, pathlib.Path]): """Register a network node. """ host, cfg, path_to_pvk, is_boostrap = info # Set bonding key pair. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_to_pvk, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX) # Set staking weight. _, _, _, stake_weight = _get_account(accounts, public_key, crypto.DEFAULT_KEY_ALGO) # Set group. group = NodeGroup.BOOTSTRAP if is_boostrap else NodeGroup.GENESIS # Set node. node = factory.create_node( group=group, host=host, index=index, network_id=factory.create_network_id(network.name_raw), port_rest=8888, port_rpc=7777, port_event=9999, typeof=NodeType.VALIDATOR, use_to_dispatch=True, use_to_monitor=random.choice(range(4)) == 0, use_to_query=True, weight=stake_weight, ) # Set bonding account. node.account = factory.create_account( network=network.name, typeof=AccountType.VALIDATOR_BOND, index=index, key_algo=crypto.KeyAlgorithm.ED25519, private_key=private_key, public_key=public_key, ) # Push. cache.infra.set_node(node) utils.log(f"Registered {node.label}")
def main(args): """Entry point. :param args: Parsed CLI arguments. """ # Unpack. network_id = factory.create_network_id(args.network) node_id = factory.create_node_id(network_id, int(args.node)) # Pull. node = cache.infra.get_node(node_id) if node is None: raise ValueError("Unregistered node.") # Set key pair. pvk, pbk = crypto.get_key_pair_from_pvk_pem_file( args.pem_path, algo=crypto.KeyAlgorithm.ED25519, encoding=crypto.KeyEncoding.HEX) # Set bonding account. node.account = factory.create_account( network=network_id.name, typeof=AccountType.VALIDATOR_BOND, index=-node_id.index, key_algo=crypto.KeyAlgorithm.ED25519, private_key=pvk, public_key=pbk, ) # Push. cache.infra.set_node(node) # Inform. utils.log( f"Node {args.network}:{args.node} bonding key was successfully registered" )
def _register_faucet(network: Network, info: typing.Tuple[str, crypto.KeyAlgorithm]): """Register a network's faucet account. """ # Set key pair. path_secret_key_pem, secret_key_algo = info private_key, public_key = \ crypto.get_key_pair_from_pvk_pem_file(path_secret_key_pem, algo=secret_key_algo, encoding=crypto.KeyEncoding.HEX) # Set faucet. network.faucet = factory.create_account( network=network.name, typeof=AccountType.NETWORK_FAUCET, index=0, key_algo=crypto.KeyAlgorithm.ED25519, private_key=private_key, public_key=public_key, ) # Push. cache.infra.set_network(network) # Inform. utils.log(f"registered {network.name_raw} - faucet key")
def _register_node(network: Network, accounts: dict, info: typing.Tuple[int, dict, pathlib.Path]): """Register a network node. """ # Destructure node info. index, cfg, path_pvk_pem = info # Set bonding key pair. private_key, public_key = crypto.get_key_pair_from_pvk_pem_file( path_pvk_pem, crypto.DEFAULT_KEY_ALGO, crypto.KeyEncoding.HEX) # Set entry in accounts.toml. account_info = _get_account(accounts, public_key, crypto.DEFAULT_KEY_ALGO) if account_info is None: return # Set staking weight. _, _, _, stake_weight = account_info # Set node addrress. node_address_event = cfg['event_stream_server']['address'] node_address_rest = cfg['rest_server']['address'] node_address_rpc = cfg['rpc_server']['address'] # Set node host. node_host_event = node_address_event.split(":")[0] node_host_rest = node_address_rest.split(":")[0] node_host_rpc = node_address_rpc.split(":")[0] assert node_host_event == node_host_rest == node_host_rpc, "hostname mismatch" node_host = node_host_event # Set node ports - derived. node_port_event = _get_node_port("event", network.index, index) node_port_rpc = _get_node_port("rpc", network.index, index) node_port_rest = _get_node_port("rest", network.index, index) # Set node group. if index <= network.count_of_bootstrap_nodes: group = NodeGroup.BOOTSTRAP elif index <= network.count_of_genesis_nodes: group = NodeGroup.GENESIS else: group = NodeGroup.OTHER # Set function flags - initially only interact with genesis nodes. use_to_dispatch = group in (NodeGroup.BOOTSTRAP, NodeGroup.GENESIS) use_to_monitor = group in (NodeGroup.BOOTSTRAP, NodeGroup.GENESIS) use_to_query = group in (NodeGroup.BOOTSTRAP, NodeGroup.GENESIS) # Set node. node = factory.create_node( group=group, host=node_host, index=index, network_id=factory.create_network_id(network.name_raw), port_rest=node_port_rest, port_rpc=node_port_rpc, port_event=node_port_event, typeof=NodeType.VALIDATOR, use_to_dispatch=use_to_dispatch, use_to_monitor=use_to_monitor, use_to_query=use_to_query, weight=stake_weight, ) # Set bonding account. node.account = factory.create_account( network=network.name, typeof=AccountType.VALIDATOR_BOND, index=index, key_algo=crypto.KeyAlgorithm.ED25519, private_key=private_key, public_key=public_key, ) # Push. cache.infra.set_node(node) # Inform. utils.log(f"Registered {node.label}")
def create_account() -> types.chain.Account: return factory.create_account( network="lrt1", typeof=random.choice(list(types.chain.AccountType)), )