def build_scenario(ctx, hosts, nodes_per_host): pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) accounts = generate_accounts(node_list) addresses = [] for node, data in accounts.items(): for k, v in data.items(): if k == 'address': addresses.append(v) random.shuffle(addresses) scenario = dict() scenario['assets'] = assets = list() # TODO: this builds a simple test scenario connecting each # node to some other node one-by-one (for odd number, # ignores last one)... total_assets = len(addresses) // 2 index = 0 for asset_num in range(total_assets): data_for_asset = { "name": str(asset_num), "channels": [addresses[index], addresses[index + 1]], "transfers_with_amount": { addresses[index]: 100, addresses[index + 1]: 100, } } assets.append(data_for_asset) index += 2 print json.dumps(scenario, indent=2 if pretty else None)
def genesis(ctx, hosts, nodes_per_host): pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) accounts = generate_accounts(node_list) # pylint: disable=redefined-outer-name all_addresses = [account['address'] for account in accounts.values()] genesis = mk_genesis(all_addresses) # pylint: disable=redefined-outer-name print json.dumps(genesis, indent=2 if pretty else None)
def full_genesis(ctx, hosts, nodes_per_host, scenario): # pylint: disable=too-many-locals pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) accounts = generate_accounts(node_list) # pylint: disable=redefined-outer-name all_addresses = [ account['address'] for account in accounts.values() ] genesis = mk_genesis(all_addresses) # pylint: disable=redefined-outer-name if scenario is not None: with open(scenario) as handler: script = json.load(handler) token_groups = { asset['name']: asset['channels'] for asset in script['assets'] } else: # create tokens for addresses x addresses token_groups = { account['address']: all_addresses for account in accounts.values() } dump, blockchain_config = deploy_all(token_groups=token_groups) for account, data in dump.items(): if account not in genesis['alloc']: genesis['alloc'][account] = data genesis['config']['raidenFlags'] = blockchain_config['raiden_flags'] genesis['config']['token_groups'] = blockchain_config['token_groups'] if scenario is not None: for asset in script['assets']: asset['token_address'] = blockchain_config['token_groups'][asset['name']] with open(scenario, 'w') as handler: json.dump(script, handler) print json.dumps(genesis, indent=2 if pretty else None)
def full_genesis(ctx, hosts, nodes_per_host, scenario): # pylint: disable=too-many-locals pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) accounts = generate_accounts(node_list) # pylint: disable=redefined-outer-name all_addresses = [ account['address'] for account in accounts.values() ] genesis = mk_genesis(all_addresses) # pylint: disable=redefined-outer-name if scenario is not None: with open(scenario) as handler: script = json.load(handler) token_groups = { token['name']: token['channels'] for token in script['tokens'] } else: # create tokens for addresses x addresses token_groups = { account['address']: all_addresses for account in accounts.values() } dump, blockchain_config = deploy_all(token_groups=token_groups) for account, data in dump.items(): if account not in genesis['alloc']: genesis['alloc'][account] = data genesis['config']['raidenFlags'] = blockchain_config['raiden_flags'] genesis['config']['token_groups'] = blockchain_config['token_groups'] if scenario is not None: for token in script['tokens']: token['token_address'] = blockchain_config['token_groups'][token['name']] with open(scenario, 'w') as handler: json.dump(script, handler) print(json.dumps(genesis, indent=2 if pretty else None))
def full_genesis(ctx, hosts, nodes_per_host, scenario): pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) accounts = generate_accounts(node_list) genesis = mk_genesis([acc['address'] for acc in accounts.values()]) if scenario is not None: with open(scenario) as f: script = json.load(f) token_groups = { asset['name']: asset['channels'] for asset in script['assets'] } else: # create tokens for addresses x addresses token_groups = { account['address']: [acc['address'] for acc in accounts.values()] for account in accounts.values() } dump, blockchain_config = deploy_all(token_groups=token_groups) for account, data in dump.items(): if not account in genesis['alloc']: genesis['alloc'][account] = data genesis['config']['raidenFlags'] = blockchain_config['raiden_flags'] genesis['config']['token_groups'] = blockchain_config['token_groups'] if scenario is not None: for asset in script['assets']: asset['token_address'] = blockchain_config['token_groups'][ asset['name']] with open(scenario, 'w') as f: json.dump(script, f) print json.dumps(genesis, indent=2 if pretty else None)
def build_scenario(ctx, hosts, nodes_per_host, nodes_per_transfer): # pylint: disable=too-many-locals pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) accounts = generate_accounts(node_list) # pylint: disable=redefined-outer-name if nodes_per_transfer < 2: nodes_per_transfer = 2 addresses = [] for node, data in sorted(accounts.items()): for k, v in data.items(): if k == 'address': addresses.append(v) scenario = dict() scenario['tokens'] = tokens = list() # NOTE: this builds a simple ring scenario connecting the nodes # in groups of `node_per_transfer`. The setup assumes # unidirectional transfer from the first node to the last. total_tokens = len(addresses) // nodes_per_transfer index = 0 for token_num in range(total_tokens): data_for_token = { "name": str(token_num), "channels": addresses[index:index + nodes_per_transfer], "transfers_with_amount": { addresses[index + nodes_per_transfer - 1]: 3000, } } tokens.append(data_for_token) index += nodes_per_transfer print json.dumps(scenario, indent=2 if pretty else None)
def build_scenario(ctx, hosts, nodes_per_host, nodes_per_transfer): # pylint: disable=too-many-locals pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) accounts = generate_accounts(node_list) # pylint: disable=redefined-outer-name if nodes_per_transfer < 2: nodes_per_transfer = 2 addresses = [] for node, data in sorted(accounts.items()): for k, v in data.items(): if k == 'address': addresses.append(v) scenario = dict() scenario['assets'] = assets = list() # NOTE: this builds a simple ring scenario connecting the nodes # in groups of `node_per_transfer`. The setup assumes # unidirectional transfer from the first node to the last. total_assets = len(addresses) // nodes_per_transfer index = 0 for asset_num in range(total_assets): data_for_asset = { "name": str(asset_num), "channels": addresses[index : index + nodes_per_transfer], "transfers_with_amount": { addresses[index + nodes_per_transfer - 1]: 3000, } } assets.append(data_for_asset) index += nodes_per_transfer print json.dumps(scenario, indent=2 if pretty else None)
def accounts(ctx, hosts, nodes_per_host): pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) print json.dumps(generate_accounts(node_list), indent=2 if pretty else None)
def genesis(ctx, hosts, nodes_per_host): pretty = ctx.obj['pretty'] node_list = build_node_list(hosts, nodes_per_host) accounts = generate_accounts(node_list) genesis = mk_genesis([acc['address'] for acc in accounts.values()]) print json.dumps(genesis, indent=2 if pretty else None)
# 'node configuration' NODE_CONFIG = [ 'nodekeyhex', 'port', 'rpcport', 'bootnodes', 'minerthreads', 'unlock' ] # a list of `num_raiden_accounts` account addresses with a predictable privkey: # privkey = sha3('127.0.0.1:`raiden_port + i`') DEFAULTACCOUNTS = [ value['address'] for value in generate_accounts([ '127.0.0.1:{}'.format(RAIDEN_PORT + i) for i in range(NUM_RAIDEN_ACCOUNTS) ]).values() ] def prepare_for_exec(nodes, parentdir, accounts=DEFAULTACCOUNTS): """ Prepare the configurations from `nodes` for execution, i.e. - prepare dataddirs - create genesis-files - create accounts (if necessary) - transform node configuration to `geth ...` cmd args :param nodes: list of node configurations :param parentdir: the datadir parent for all nodes :return: list of cmds for `Popen`
'--nodiscover', '--rpc', '--networkid {}'.format(sum(ord(c) for c in CLUSTER_NAME)), ] # the node specific arguments to pass to `geth` that will be extracted from a # 'node configuration' NODE_CONFIG = [ 'nodekeyhex', 'port', 'rpcport', 'bootnodes', 'minerthreads', 'unlock' ] # a list of `num_raiden_accounts` account addresses with a predictable privkey: # privkey = sha3('127.0.0.1:`raiden_port + i`') DEFAULTACCOUNTS = [ value['address'] for value in generate_accounts([ '127.0.0.1:{}'.format(RAIDEN_PORT + i) for i in range(NUM_RAIDEN_ACCOUNTS) ]).values() ] def prepare_for_exec(nodes, parentdir, accounts=DEFAULTACCOUNTS): """ Prepare the configurations from `nodes` for execution, i.e. - prepare dataddirs - create genesis-files - create accounts (if necessary) - transform node configuration to `geth ...` cmd args :param nodes: list of node configurations :param parentdir: the datadir parent for all nodes :return: list of cmds for `Popen`