示例#1
0
def create_local_pool(node_base_dir, cli_base_dir, config=None, node_size=4):
    conf = config or getConfig()

    stewards = []
    node_conf = []
    nodes = []
    genesis_txns = []
    for i in range(node_size):
        w = Wallet("steward")
        s = Steward(wallet=w)
        s.wallet.addIdentifier()

        stewards.append(s)

        node_config_helper = NodeConfigHelper(conf.name,
                                              conf,
                                              chroot=node_base_dir)
        n_config = adict(name='Node' + str(i + 1),
                         basedirpath=node_config_helper.ledger_dir,
                         ha=('127.0.0.1', 9700 + (i * 2)),
                         cliha=('127.0.0.1', 9700 + (i * 2) + 1))

        n_verkey, n_bls_key, n_bls_key_proof = \
            initialize_node_environment(name=n_config.name,
                                        node_config_helper=node_config_helper,
                                        override_keep=True,
                                        sigseed=randomSeed())

        s.set_node(n_config,
                   verkey=n_verkey,
                   blskey=n_bls_key,
                   blsley_proof=n_bls_key_proof)

        node_conf.append(n_config)

        genesis_txns += s.generate_genesis_txns()

    pool = None  # LocalPool(genesis_txns, pool_dir, steward=stewards[0])

    for c in node_conf:
        n = Node(**c)
        pool.add(n)
        nodes.append(n)

    pool.runFor(5)

    return pool
示例#2
0
def create_local_pool(base_dir, node_size=4):
    conf = getConfig(base_dir)
    pool_dir = os.path.join(base_dir, "pool")

    # TODO: Need to come back to this why we need this cleanup
    shutil.rmtree(pool_dir, ignore_errors=True)

    stewards = []
    node_conf = []
    nodes = []
    genesis_txns = []
    for i in range(node_size):
        w = Wallet("steward")
        s = Steward(wallet=w)
        s.wallet.addIdentifier()

        stewards.append(s)

        n_config = adict(name='Node' + str(i + 1),
                         basedirpath=pool_dir,
                         ha=('127.0.0.1', 9700 + (i * 2)),
                         cliha=('127.0.0.1', 9700 + (i * 2) + 1))

        n_verkey, n_bls_key = initialize_node_environment(
            name=n_config.name,
            base_dir=n_config.basedirpath,
            override_keep=True,
            config=conf,
            sigseed=randomSeed())

        s.set_node(n_config, verkey=n_verkey, blskey=n_bls_key)

        node_conf.append(n_config)

        genesis_txns += s.generate_genesis_txns()

    pool = LocalPool(genesis_txns, pool_dir, steward=stewards[0])

    for c in node_conf:
        n = Node(**c)
        pool.add(n)
        nodes.append(n)

    pool.runFor(5)

    return pool
示例#3
0
def create_local_pool(base_dir, node_size=4):
    conf = getConfig(base_dir)
    pool_dir = os.path.join(base_dir, "pool")

    # TODO: Need to come back to this why we need this cleanup
    shutil.rmtree(pool_dir, ignore_errors=True)

    stewards = []
    node_conf = []
    nodes = []
    genesis_txns = []
    for i in range(node_size):
        w = Wallet("steward")
        s = Steward(wallet=w)
        s.wallet.addIdentifier()

        stewards.append(s)

        n_config = adict(name='Node'+str(i+1),
                         basedirpath=pool_dir,
                         ha=('127.0.0.1', 9700+(i * 2)),
                         cliha=('127.0.0.1', 9700+(i * 2)+1))

        n_verkey = initialize_node_environment(name=n_config.name,
                                               base_dir=n_config.basedirpath,
                                               override_keep=True,
                                               config=conf,
                                               sigseed=randomSeed())

        s.set_node(n_config, verkey=n_verkey)

        node_conf.append(n_config)

        genesis_txns += s.generate_genesis_txns()

    pool = LocalPool(genesis_txns, pool_dir, steward=stewards[0])

    for c in node_conf:
        n = Node(**c)
        pool.add(n)
        nodes.append(n)

    pool.runFor(5)

    return pool
示例#4
0
def invalid_identifier_tdir(tdir_for_func):
    ledger = Ledger(CompactMerkleTree(), dataDir=tdir_for_func)
    txn = Steward.node_txn(nym=base58.b58encode(b'whatever').decode("utf-8"),
                           steward_nym="invalid====",
                           node_name='test' + str(2),
                           ip='127.0.0.1',
                           node_port=8080,
                           client_port=8081,
                           client_ip='127.0.0.1')
    ledger.add(txn)
    ledger.stop()
示例#5
0
def create_local_pool(node_base_dir, cli_base_dir, config=None, node_size=4):
    conf = config or getConfig()

    stewards = []
    node_conf = []
    nodes = []
    genesis_txns = []
    for i in range(node_size):
        w = Wallet("steward")
        s = Steward(wallet=w)
        s.wallet.addIdentifier()

        stewards.append(s)

        node_config_helper = NodeConfigHelper(conf.name, conf, chroot=node_base_dir)
        n_config = adict(name='Node' + str(i + 1),
                         basedirpath=node_config_helper.ledger_dir,
                         ha=('127.0.0.1', 9700 + (i * 2)),
                         cliha=('127.0.0.1', 9700 + (i * 2) + 1))

        n_verkey, n_bls_key = initialize_node_environment(name=n_config.name,
                                                          node_config_helper=node_config_helper,
                                                          override_keep=True,
                                                          sigseed=randomSeed())

        s.set_node(n_config, verkey=n_verkey, blskey=n_bls_key)

        node_conf.append(n_config)

        genesis_txns += s.generate_genesis_txns()

    pool = None  # LocalPool(genesis_txns, pool_dir, steward=stewards[0])

    for c in node_conf:
        n = Node(**c)
        pool.add(n)
        nodes.append(n)

    pool.runFor(5)

    return pool
示例#6
0
def invalid_verkey_tdir(tdir_for_func):
    ledger = Ledger(CompactMerkleTree(), dataDir=tdir_for_func)
    for d in range(3):
        txn = Steward.node_txn(steward_nym="Th7MpTaRZVRYnPiabds81Y",
                               node_name='test' + str(d),
                               nym=base58.b58encode(b'whatever') if d != 1 else "invalid====",
                               ip='127.0.0.1',
                               node_port=8080,
                               client_port=8081,
                               client_ip='127.0.0.1')
        ledger.add(txn)
    ledger.stop()
示例#7
0
def getPoolTxnData(poolId, newPoolTxnNodeNames):
    data = {}
    data["seeds"] = {}
    data["txns"] = []
    data['nodesWithBls'] = {}
    for index, n in enumerate(newPoolTxnNodeNames, start=1):
        newStewardAlias = poolId + "Steward" + str(index)
        stewardSeed = (newStewardAlias + "0" *
                       (32 - len(newStewardAlias))).encode()
        data["seeds"][newStewardAlias] = stewardSeed
        stewardSigner = SimpleSigner(seed=stewardSeed)
        data["txns"].append(
            Member.nym_txn(nym=stewardSigner.identifier,
                           verkey=stewardSigner.verkey,
                           role=STEWARD,
                           name=poolId + "Steward" + str(index),
                           seq_no=index,
                           txn_id=sha256("{}".format(
                               stewardSigner.verkey).encode()).hexdigest()))

        newNodeAlias = n
        nodeSeed = (newNodeAlias + "0" * (32 - len(newNodeAlias))).encode()
        data["seeds"][newNodeAlias] = nodeSeed
        nodeSigner = SimpleSigner(seed=nodeSeed)

        _, bls_key, key_proof = create_default_bls_crypto_factory(
        ).generate_bls_keys(seed=data['seeds'][n])
        data['nodesWithBls'][n] = True

        node_txn = Steward.node_txn(
            steward_nym=stewardSigner.verkey,
            node_name=newNodeAlias,
            nym=nodeSigner.verkey,
            ip="127.0.0.1",
            node_port=genHa()[1],
            client_port=genHa()[1],
            client_ip="127.0.0.1",
            blskey=bls_key,
            bls_key_proof=key_proof,
            services=[VALIDATOR],
            txn_id=sha256("{}".format(nodeSigner.verkey).encode()).hexdigest())

        data["txns"].append(node_txn)

    return data
示例#8
0
def getPoolTxnData(poolId, newPoolTxnNodeNames):
    data = {}
    data["seeds"] = {}
    data["txns"] = []
    data['nodesWithBls'] = {}
    for index, n in enumerate(newPoolTxnNodeNames, start=1):
        newStewardAlias = poolId + "Steward" + str(index)
        stewardSeed = (newStewardAlias + "0" *
                       (32 - len(newStewardAlias))).encode()
        data["seeds"][newStewardAlias] = stewardSeed
        stewardSigner = SimpleSigner(seed=stewardSeed)
        data["txns"].append(
            Member.nym_txn(nym=stewardSigner.identifier,
                           verkey=stewardSigner.verkey,
                           role=STEWARD,
                           name=poolId + "Steward" + str(index),
                           seq_no=index,
                           txn_id=sha256("{}".format(stewardSigner.verkey).encode()).hexdigest()))

        newNodeAlias = n
        nodeSeed = (newNodeAlias + "0" * (32 - len(newNodeAlias))).encode()
        data["seeds"][newNodeAlias] = nodeSeed
        nodeSigner = SimpleSigner(seed=nodeSeed)

        _, bls_key = create_default_bls_crypto_factory().generate_bls_keys(
            seed=data['seeds'][n])
        data['nodesWithBls'][n] = True

        node_txn = Steward.node_txn(
            steward_nym=stewardSigner.verkey,
            node_name=newNodeAlias,
            nym=nodeSigner.verkey,
            ip="127.0.0.1",
            node_port=genHa()[1],
            client_port=genHa()[1],
            client_ip="127.0.0.1",
            blskey=bls_key,
            services=[VALIDATOR],
            txn_id=sha256("{}".format(nodeSigner.verkey).encode()).hexdigest()
        )

        data["txns"].append(node_txn)

    return data
def make_pool_genesis(pool_pathname, node_defs):
    pool_ledger = open_ledger(pool_pathname)

    seq_no = 1
    for node_def in node_defs:
        txn = Steward.node_txn(node_def['auth_did'],
                               node_def['alias'],
                               node_def['verkey'],
                               node_def['node_address'],
                               node_def['node_port'],
                               node_def['client_port'],
                               client_ip=node_def['client_address'],
                               blskey=node_def['bls_key'],
                               seq_no=seq_no,
                               protocol_version=None,
                               bls_key_proof=node_def['bls_pop'])
        pool_ledger.add(txn)
        seq_no += 1

    pool_ledger.stop()
示例#10
0
def poolTxnData(request):
    nodeCount = getValueFromModule(request, "nodeCount", 4)
    nodes_with_bls = getValueFromModule(request, "nodes_wth_bls", nodeCount)
    data = {'txns': [], 'seeds': {}, 'nodesWithBls': {}}
    for i, node_name in zip(range(1, nodeCount + 1), genNodeNames(nodeCount)):
        data['seeds'][node_name] = node_name + '0' * (32 - len(node_name))
        steward_name = 'Steward' + str(i)
        data['seeds'][steward_name] = steward_name + \
                                      '0' * (32 - len(steward_name))

        n_idr = SimpleSigner(seed=data['seeds'][node_name].encode()).identifier
        s_idr = DidSigner(seed=data['seeds'][steward_name].encode())

        data['txns'].append(
            Member.nym_txn(nym=s_idr.identifier,
                           verkey=s_idr.verkey,
                           role=STEWARD,
                           name=steward_name,
                           seq_no=i))

        node_txn = Steward.node_txn(steward_nym=s_idr.identifier,
                                    node_name=node_name,
                                    nym=n_idr,
                                    ip='127.0.0.1',
                                    node_port=genHa()[1],
                                    client_port=genHa()[1],
                                    client_ip='127.0.0.1',
                                    services=[VALIDATOR],
                                    seq_no=i)

        if i <= nodes_with_bls:
            _, bls_key, bls_key_proof = create_default_bls_crypto_factory(
            ).generate_bls_keys(seed=data['seeds'][node_name])
            get_payload_data(node_txn)[DATA][BLS_KEY] = bls_key
            get_payload_data(node_txn)[DATA][BLS_KEY_PROOF] = bls_key_proof
            data['nodesWithBls'][node_name] = True

        data['txns'].append(node_txn)

    # Add 4 Trustees
    for i in range(4):
        trustee_name = 'Trs' + str(i)
        data['seeds'][trustee_name] = trustee_name + '0' * (32 -
                                                            len(trustee_name))
        t_sgnr = DidSigner(seed=data['seeds'][trustee_name].encode())
        data['txns'].append(
            Member.nym_txn(nym=t_sgnr.identifier,
                           verkey=t_sgnr.verkey,
                           role=TRUSTEE,
                           name=trustee_name))

    more_data_seeds = \
        {
            "Alice": "99999999999999999999999999999999",
            "Jason": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
            "John": "dddddddddddddddddddddddddddddddd",
            "Les": "ffffffffffffffffffffffffffffffff"
        }
    more_data_users = []
    for more_name, more_seed in more_data_seeds.items():
        signer = DidSigner(seed=more_seed.encode())
        more_data_users.append(
            Member.nym_txn(
                nym=signer.identifier,
                verkey=signer.verkey,
                name=more_name,
                creator="5rArie7XKukPCaEwq5XGQJnM9Fc5aZE3M9HAPVfMU2xC"))

    data['txns'].extend(more_data_users)
    data['seeds'].update(more_data_seeds)
    return data
    def bootstrap_pool_ledger_core(cls,
                                   config,
                                   network,
                                   appendToLedgers,
                                   node_defs,
                                   localNodes,
                                   nodeParamsFileName,
                                   config_helper_class=PConfigHelper,
                                   node_config_helper_class=PNodeConfigHelper,
                                   chroot: str = None):

        if not localNodes:
            localNodes = {}
        try:
            if isinstance(localNodes, int):
                _localNodes = {localNodes}
            else:
                _localNodes = {int(_) for _ in localNodes}
        except BaseException as exc:
            raise RuntimeError(
                'nodeNum must be an int or set of ints') from exc

        config.NETWORK_NAME = network

        config_helper = config_helper_class(config, chroot=chroot)
        os.makedirs(config_helper.genesis_dir, exist_ok=True)
        genesis_dir = config_helper.genesis_dir
        # keys_dir = config_helper.keys_dir

        poolLedger = cls.init_pool_ledger(appendToLedgers, genesis_dir, config)

        genesis_protocol_version = None

        seq_no = 1
        for nd in node_defs:

            verkey = nd.verkey.encode()
            blskey = nd.blskey
            key_proof = nd.bls_proof

            if nd.idx in _localNodes:

                if nd.ip != '127.0.0.1':
                    paramsFilePath = os.path.join(config.GENERAL_CONFIG_DIR,
                                                  nodeParamsFileName)
                    print('Nodes will not run locally, so writing {}'.format(
                        paramsFilePath))
                    PoolLedger.write_node_params_file(paramsFilePath, nd.name,
                                                      "0.0.0.0", nd.node_port,
                                                      "0.0.0.0",
                                                      nd.client_port)

                print(
                    "This node with name {} will use ports {} and {} for nodestack and clientstack respectavely"
                    .format(nd.name, nd.node_port, nd.client_port))

            node_nym = cls.get_nym_from_verkey(verkey)

            node_txn = Steward.node_txn(
                nd.steward_nym,
                nd.name,
                node_nym,
                nd.ip,
                nd.node_port,
                nd.client_port,
                blskey=blskey,
                bls_key_proof=key_proof,
                seq_no=seq_no,
                protocol_version=genesis_protocol_version)

            seq_no += 1
            poolLedger.add(node_txn)

        poolLedger.stop()
示例#12
0
    def bootstrapTestNodesCore(cls, config, envName, appendToLedgers,
                               domainTxnFieldOrder, trustee_def, steward_defs,
                               node_defs, client_defs, localNodes,
                               nodeParamsFileName):

        if not localNodes:
            localNodes = {}
        try:
            if isinstance(localNodes, int):
                _localNodes = {localNodes}
            else:
                _localNodes = {int(_) for _ in localNodes}
        except BaseException as exc:
            raise RuntimeError(
                'nodeNum must be an int or set of ints') from exc

        baseDir = cls.setup_base_dir(config)

        poolLedger = cls.init_pool_ledger(appendToLedgers, baseDir, config,
                                          envName)

        domainLedger = cls.init_domain_ledger(appendToLedgers, baseDir, config,
                                              envName, domainTxnFieldOrder)

        trustee_txn = Member.nym_txn(trustee_def.nym,
                                     trustee_def.name,
                                     role=TRUSTEE)
        domainLedger.add(trustee_txn)

        for sd in steward_defs:
            nym_txn = Member.nym_txn(sd.nym,
                                     sd.name,
                                     role=STEWARD,
                                     creator=trustee_def.nym)
            domainLedger.add(nym_txn)

        for nd in node_defs:

            if nd.idx in _localNodes:
                _, verkey = initLocalKeys(nd.name,
                                          baseDir,
                                          nd.sigseed,
                                          True,
                                          config=config)
                _, verkey = initLocalKeys(nd.name + CLIENT_STACK_SUFFIX,
                                          baseDir,
                                          nd.sigseed,
                                          True,
                                          config=config)
                verkey = verkey.encode()
                assert verkey == nd.verkey

                if nd.ip != '127.0.0.1':
                    paramsFilePath = os.path.join(baseDir, nodeParamsFileName)
                    print('Nodes will not run locally, so writing '
                          '{}'.format(paramsFilePath))
                    TestNetworkSetup.writeNodeParamsFile(
                        paramsFilePath, nd.name, nd.port, nd.client_port)

                print("This node with name {} will use ports {} and {} for "
                      "nodestack and clientstack respectively".format(
                          nd.name, nd.port, nd.client_port))
            else:
                verkey = nd.verkey
            node_nym = cls.getNymFromVerkey(verkey)

            node_txn = Steward.node_txn(nd.steward_nym, nd.name, node_nym,
                                        nd.ip, nd.port, nd.client_port)
            poolLedger.add(node_txn)

        for cd in client_defs:
            txn = Member.nym_txn(cd.nym, cd.name, creator=trustee_def.nym)
            domainLedger.add(txn)

        poolLedger.stop()
        domainLedger.stop()
示例#13
0
    seq_no = 1

    for node_num in range(nodeCountToInit):    
        _, verkey, blskey, key_proof = initNodeKeysForBothStacks(node_defs[node_num].name, keys_dir, node_defs[node_num].sigseed, override=True)
        verkey = verkey.encode()
        assert verkey == node_defs[node_num].verkey

        nodeParamsFileName = 'indy.env'

        paramsFilePath = os.path.join(config.GENERAL_CONFIG_DIR, nodeParamsFileName)
        print('Nodes will not run locally, so writing {}'.format(paramsFilePath))
        TestNetworkSetup.writeNodeParamsFile(paramsFilePath, node_def.name,
                                            node_def.ip, node_def.port,
                                            node_def.ip, node_def.client_port)

        print("This node with name {} will use ports {} and {} for nodestack and clientstack respectively"
                .format(node_defs[node_num].name, node_defs[node_num].port, node_defs[node_num].client_port))

        node_nym = hexToFriendly(verkey)

        node_txn = Steward.node_txn(node_defs[node_num].steward_nym, node_defs[node_num].name, node_nym,
                                        node_defs[node_num].ip, node_defs[node_num].port, node_defs[node_num].client_port, blskey=blskey,
                                        bls_key_proof=key_proof,
                                        seq_no=seq_no,
                                        protocol_version=genesis_protocol_version)
        seq_no += 1
        poolLedger.add(node_txn)

    poolLedger.stop()
    domainLedger.stop()
    def bootstrap_real_nodes_core(cls,
                                  config,
                                  network,
                                  appendToLedgers,
                                  domainTxnFieldOrder,
                                  trustee_def,
                                  steward_defs,
                                  node_defs,
                                  node_params_file_name,
                                  config_helper_class=PConfigHelper,
                                  node_config_helper_class=PNodeConfigHelper,
                                  chroot: str = None):

        # if not local_nodes:
        #     local_nodes = {}
        # try:
        #     if isinstance(local_nodes, int):
        #         _local_nodes = {local_nodes}
        #     else:
        #         _local_nodes = {int(_) for _ in local_nodes}
        # except BaseException as exc:
        #     raise RuntimeError('nodeNum must be an int or set of ints') from exc

        config.NETWORK_NAME = network

        config_helper = config_helper_class(config, chroot=chroot)
        os.makedirs(config_helper.genesis_dir, exist_ok=True)
        genesis_dir = config_helper.genesis_dir
        keys_dir = config_helper.keys_dir

        poolLedger = cls.init_pool_ledger(appendToLedgers, genesis_dir, config)
        domainLedger = cls.init_domain_ledger(appendToLedgers, genesis_dir,
                                              config, domainTxnFieldOrder)

        # TODO: make it parameter for generate genesis txns script
        genesis_protocol_version = None

        # 1. INIT DOMAIN LEDGER GENESIS FILE
        seq_no = 1
        trustee_txn = Member.nym_txn(trustee_def.nym,
                                     verkey=trustee_def.verkey,
                                     role=TRUSTEE,
                                     seq_no=seq_no,
                                     protocol_version=genesis_protocol_version)
        seq_no += 1
        domainLedger.add(trustee_txn)

        for sd in steward_defs:
            nym_txn = Member.nym_txn(sd.nym,
                                     verkey=sd.verkey,
                                     role=STEWARD,
                                     creator=trustee_def.nym,
                                     seq_no=seq_no,
                                     protocol_version=genesis_protocol_version)
            seq_no += 1
            domainLedger.add(nym_txn)

        # 2. INIT KEYS AND POOL LEDGER GENESIS FILE
        seq_no = 1
        for nd in node_defs:
            print(
                "------------------------------------------------------------------------------------------------------"
            )
            print("Node name:", nd.name)
            # if nd.idx in _local_nodes:
            _, verkey, blskey, key_proof = initNodeKeysForBothStacks(
                nd.name, keys_dir, nd.sigseed, override=True)
            verkey = verkey.encode()
            assert verkey == nd.verkey

            # if nd.ip != '127.0.0.1':
            #     paramsFilePath = os.path.join(config.GENERAL_CONFIG_DIR, node_params_file_name)
            #     print('Nodes will not run locally, so writing {}'.format(paramsFilePath))
            #     RealNetworkSetup.writeNodeParamsFile(paramsFilePath, nd.name,
            #                                          "0.0.0.0", nd.port,
            #                                          "0.0.0.0", nd.client_port)

            print(
                "This node with name {} will use ports {} and {} for nodestack and clientstack respectively"
                .format(nd.name, nd.port, nd.client_port))
            # else:
            #     verkey = nd.verkey
            #     blskey, key_proof = init_bls_keys(keys_dir, nd.name, nd.sigseed)
            node_nym = cls.get_nym_from_verkey(verkey)

            node_txn = Steward.node_txn(
                nd.steward_nym,
                nd.name,
                node_nym,
                nd.ip,
                nd.port,
                nd.client_port,
                blskey=blskey,
                bls_key_proof=key_proof,
                seq_no=seq_no,
                protocol_version=genesis_protocol_version)
            seq_no += 1
            poolLedger.add(node_txn)
            print(
                "------------------------------------------------------------------------------------------------------\n"
            )

        poolLedger.stop()
        domainLedger.stop()
示例#15
0
def poolTxnData(request):
    nodeCount = getValueFromModule(request, "nodeCount", 4)
    nodes_with_bls = getValueFromModule(request, "nodes_wth_bls", nodeCount)
    data = {'txns': [], 'seeds': {}, 'nodesWithBls': {}}
    for i, node_name in zip(range(1, nodeCount + 1), genNodeNames(nodeCount)):
        data['seeds'][node_name] = node_name + '0' * (32 - len(node_name))
        steward_name = 'Steward' + str(i)
        data['seeds'][steward_name] = steward_name + \
                                      '0' * (32 - len(steward_name))

        n_idr = SimpleSigner(seed=data['seeds'][node_name].encode()).identifier
        s_idr = DidSigner(seed=data['seeds'][steward_name].encode())

        data['txns'].append(
                Member.nym_txn(nym=s_idr.identifier,
                               verkey=s_idr.verkey,
                               role=STEWARD,
                               name=steward_name,
                               seq_no=i)
        )

        node_txn = Steward.node_txn(steward_nym=s_idr.identifier,
                                    node_name=node_name,
                                    nym=n_idr,
                                    ip='127.0.0.1',
                                    node_port=genHa()[1],
                                    client_port=genHa()[1],
                                    client_ip='127.0.0.1',
                                    services=[VALIDATOR],
                                    seq_no=i)

        if i <= nodes_with_bls:
            _, bls_key, bls_key_proof = create_default_bls_crypto_factory().generate_bls_keys(
                seed=data['seeds'][node_name])
            get_payload_data(node_txn)[DATA][BLS_KEY] = bls_key
            get_payload_data(node_txn)[DATA][BLS_KEY_PROOF] = bls_key_proof
            data['nodesWithBls'][node_name] = True

        data['txns'].append(node_txn)

    # Add 4 Trustees
    for i in range(4):
        trustee_name = 'Trs' + str(i)
        data['seeds'][trustee_name] = trustee_name + '0' * (
                32 - len(trustee_name))
        t_sgnr = DidSigner(seed=data['seeds'][trustee_name].encode())
        data['txns'].append(
            Member.nym_txn(nym=t_sgnr.identifier,
                           verkey=t_sgnr.verkey,
                           role=TRUSTEE,
                           name=trustee_name)
        )

    more_data_seeds = \
        {
            "Alice": "99999999999999999999999999999999",
            "Jason": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
            "John": "dddddddddddddddddddddddddddddddd",
            "Les": "ffffffffffffffffffffffffffffffff"
        }
    more_data_users = []
    for more_name, more_seed in more_data_seeds.items():
        signer = DidSigner(seed=more_seed.encode())
        more_data_users.append(
            Member.nym_txn(nym=signer.identifier,
                           verkey=signer.verkey,
                           name=more_name,
                           creator="5rArie7XKukPCaEwq5XGQJnM9Fc5aZE3M9HAPVfMU2xC")
        )

    data['txns'].extend(more_data_users)
    data['seeds'].update(more_data_seeds)
    return data
示例#16
0
    def bootstrapTestNodesCore(
            cls,
            config,
            network,
            appendToLedgers,
            domainTxnFieldOrder,
            trustee_def,
            steward_defs,
            node_defs,
            client_defs,
            localNodes,
            nodeParamsFileName,
            config_helper_class=PConfigHelper,
            node_config_helper_class=PNodeConfigHelper,
            chroot: str=None):

        if not localNodes:
            localNodes = {}
        try:
            if isinstance(localNodes, int):
                _localNodes = {localNodes}
            else:
                _localNodes = {int(_) for _ in localNodes}
        except BaseException as exc:
            raise RuntimeError('nodeNum must be an int or set of ints') from exc

        config.NETWORK_NAME = network

        if _localNodes:
            config_helper = config_helper_class(config, chroot=chroot)
            os.makedirs(config_helper.genesis_dir, exist_ok=True)
            genesis_dir = config_helper.genesis_dir
            keys_dir = config_helper.keys_dir
        else:
            genesis_dir = cls.setup_clibase_dir(config, network)
            keys_dir = os.path.join(genesis_dir, "keys")

        poolLedger = cls.init_pool_ledger(appendToLedgers, genesis_dir, config)
        domainLedger = cls.init_domain_ledger(appendToLedgers, genesis_dir,
                                              config, domainTxnFieldOrder)

        # 1. INIT DOMAIN LEDGER GENESIS FILE
        seq_no = 1
        trustee_txn = Member.nym_txn(trustee_def.nym, verkey=trustee_def.verkey, role=TRUSTEE,
                                     seq_no=seq_no)
        seq_no += 1
        domainLedger.add(trustee_txn)

        for sd in steward_defs:
            nym_txn = Member.nym_txn(sd.nym, verkey=sd.verkey, role=STEWARD, creator=trustee_def.nym,
                                     seq_no=seq_no)
            seq_no += 1
            domainLedger.add(nym_txn)

        for cd in client_defs:
            txn = Member.nym_txn(cd.nym, verkey=cd.verkey, creator=trustee_def.nym,
                                 seq_no=seq_no)
            seq_no += 1
            domainLedger.add(txn)

        # 2. INIT KEYS AND POOL LEDGER GENESIS FILE
        seq_no = 1
        for nd in node_defs:
            if nd.idx in _localNodes:
                _, verkey, blskey = initNodeKeysForBothStacks(nd.name, keys_dir, nd.sigseed, override=True)
                verkey = verkey.encode()
                assert verkey == nd.verkey

                if nd.ip != '127.0.0.1':
                    paramsFilePath = os.path.join(config.GENERAL_CONFIG_DIR, nodeParamsFileName)
                    print('Nodes will not run locally, so writing {}'.format(paramsFilePath))
                    TestNetworkSetup.writeNodeParamsFile(paramsFilePath, nd.name,
                                                         "0.0.0.0", nd.port,
                                                         "0.0.0.0", nd.client_port)

                print("This node with name {} will use ports {} and {} for nodestack and clientstack respectively"
                      .format(nd.name, nd.port, nd.client_port))
            else:
                verkey = nd.verkey
                blskey = init_bls_keys(keys_dir, nd.name, nd.sigseed)
            node_nym = cls.getNymFromVerkey(verkey)

            node_txn = Steward.node_txn(nd.steward_nym, nd.name, node_nym,
                                        nd.ip, nd.port, nd.client_port, blskey=blskey,
                                        seq_no=seq_no)
            seq_no += 1
            poolLedger.add(node_txn)

        poolLedger.stop()
        domainLedger.stop()
                    config_helper.keys_dir + '/' + nd.name + '/bls_keys' +
                    '/bls_pk', 'w+') as f:
                f.write(d.bls_key)
        else:
            if nd.node_ip != '127.0.0.1':
                paramsFilePath = os.path.join(getConfig().GENERAL_CONFIG_DIR,
                                              nodeParamsFileName)
                print('Nodes will not run locally, so writing {}'.format(
                    paramsFilePath))
                TestNetworkSetup.writeNodeParamsFile(paramsFilePath, nd.name,
                                                     "0.0.0.0", nd.port,
                                                     "0.0.0.0", nd.client_port)

        node_txn = Steward.node_txn(nd.fromnym,
                                    nd.name,
                                    nd.dest,
                                    nd.node_ip,
                                    int(nd.node_port),
                                    int(nd.client_port),
                                    blskey=nd.bls_key,
                                    bls_key_proof=nd.bls_pop,
                                    seq_no=seq_no,
                                    protocol_version=genesis_protocol_version)

        seq_no += 1
        poolLedger.add(node_txn)
        poolLedger1.add(node_txn)

poolLedger.stop()
poolLedger1.stop()