Java Code Examples for org.hyperledger.fabric.sdk.HFClient#setCryptoSuite()

The following examples show how to use org.hyperledger.fabric.sdk.HFClient#setCryptoSuite() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FabricUtils.java    From fabric-java-block with GNU General Public License v3.0 5 votes vote down vote up
public static Channel initChannel(HFClient client, BlockChainOrgUserDTO userDTO, BlockChainOrgDTO currentOrgDTO,
                                  BlockChainChannelDTO channelDTO, BaasRouteDTO routeDTO, List<BlockChainOrdererDTO> ordererList) throws Exception {
    client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());

    // 实例化用户需要先在控制台-证书管理中申请客户端证书,申请的企业名称需要与当前登录账户实名认证的企业名称相同
    FabricUser user = new FabricUser(userDTO.getOrgUserName(), new FabricEnrollment(userDTO.getOrgUserKey(), userDTO.getOrgUserCert()),
            currentOrgDTO.getMspId());

    client.setUserContext(user);

    Channel chain = client.newChannel(channelDTO.getChannelKey());

    for(BlockChainOrdererDTO ordererDTO: ordererList) {
        chain.addOrderer(client.newOrderer(ordererDTO.getOrdererKey(), routeDTO.getEndPoint(),
                FabricConfig.getOrderProperties(routeDTO.getSecretId(),routeDTO.getSecretKey(),ordererDTO.getOrdererKey())));
    }

    for(BlockChainOrgNodeDTO nodeDTO : currentOrgDTO.getNodeList()){
        chain.addPeer(client.newPeer(nodeDTO.getNodeKey(), routeDTO.getEndPoint(), FabricConfig.getPeerProperties(routeDTO.getSecretId(),
                routeDTO.getSecretKey(),nodeDTO.getNodeKey())),
                createPeerOptions().setPeerRoles(EnumSet.of(Peer.PeerRole.ENDORSING_PEER,
                        Peer.PeerRole.LEDGER_QUERY, Peer.PeerRole.CHAINCODE_QUERY, Peer.PeerRole.EVENT_SOURCE)));
        //registerEventsForFilteredBlocks()
    }


    chain.initialize();

    return chain;
}
 
Example 2
Source File: PrivateDataIT.java    From fabric-sdk-java with Apache License 2.0 5 votes vote down vote up
public void runFabricTest(final SampleStore sampleStore) throws Exception {
    ////////////////////////////
    // Setup client

    //Create instance of client.
    HFClient client = HFClient.createNewInstance();

    client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
    client.setUserContext(sampleStore.getMember(TEST_ADMIN_NAME, "peerOrg2"));

    SampleOrg sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg2");

    Channel barChannel = sampleStore.getChannel(client, BAR_CHANNEL_NAME);

    barChannel.initialize();
    runChannel(client, barChannel, sampleOrg, 10);
    assertFalse(barChannel.isShutdown());
    assertTrue(barChannel.isInitialized());

    if (testConfig.isFabricVersionAtOrAfter("1.3")) {
        Set<String> expect = new HashSet<>(Arrays.asList("COLLECTION_FOR_A", "COLLECTION_FOR_B"));
        Set<String> got = new HashSet<>();

        CollectionConfigPackage queryCollectionsConfig = barChannel.queryCollectionsConfig(CHAIN_CODE_NAME, barChannel.getPeers().iterator().next(), sampleOrg.getPeerAdmin());
        for (CollectionConfigPackage.CollectionConfig collectionConfig : queryCollectionsConfig.getCollectionConfigs()) {
            got.add(collectionConfig.getName());

        }
        assertEquals(expect, got);
    }

    out("That's all folks!");
}
 
Example 3
Source File: FabricSDKWrapper.java    From WeEvent with Apache License 2.0 4 votes vote down vote up
public static HFClient initializeClient(FabricConfig fabricConfig) throws InvalidArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException, CryptoException, ClassNotFoundException {
    HFClient hfClient = HFClient.createNewInstance();
    hfClient.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
    hfClient.setUserContext(new FabricUser(fabricConfig));
    return hfClient;
}
 
Example 4
Source File: IntermediateOrg.java    From fabric-net-server with Apache License 2.0 4 votes vote down vote up
void setClient(HFClient client) throws CryptoException, InvalidArgumentException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
    this.client = client;
    log.info("Create instance of HFClient");
    client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());
    log.info("Set Crypto Suite of HFClient");
}
 
Example 5
Source File: End2endIT.java    From fabric-sdk-java with Apache License 2.0 4 votes vote down vote up
public void runFabricTest(final SampleStore sampleStore) throws Exception {

        ////////////////////////////
        // Setup client

        //Create instance of client.
        HFClient client = HFClient.createNewInstance();

        client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());

        ////////////////////////////
        //Construct and run the channels
        SampleOrg sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg1");
        Channel fooChannel = constructChannel(FOO_CHANNEL_NAME, client, sampleOrg);
        sampleStore.saveChannel(fooChannel);
        runChannel(client, fooChannel, true, sampleOrg, 0);

        assertFalse(fooChannel.isShutdown());
        fooChannel.shutdown(true); // Force foo channel to shutdown clean up resources.
        assertTrue(fooChannel.isShutdown());

        assertNull(client.getChannel(FOO_CHANNEL_NAME));
        out("\n");

        sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg2");
        Channel barChannel = constructChannel(BAR_CHANNEL_NAME, client, sampleOrg);
        assertTrue(barChannel.isInitialized());
        /*
         * sampleStore.saveChannel uses {@link Channel#serializeChannel()}
         */
        sampleStore.saveChannel(barChannel);
        assertFalse(barChannel.isShutdown());
        runChannel(client, barChannel, true, sampleOrg, 100); //run a newly constructed bar channel with different b value!
        //let bar channel just shutdown so we have both scenarios.

        out("\nTraverse the blocks for chain %s ", barChannel.getName());

        blockWalker(client, barChannel);

        assertFalse(barChannel.isShutdown());
        assertTrue(barChannel.isInitialized());
        out("That's all folks!");
    }
 
Example 6
Source File: End2endAndBackAgainIT.java    From fabric-sdk-java with Apache License 2.0 4 votes vote down vote up
public void runFabricTest(final SampleStore sampleStore) throws Exception {
    ////////////////////////////
    // Setup client

    //Create instance of client.
    HFClient client = HFClient.createNewInstance();

    client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());

    ////////////////////////////
    //Reconstruct and run the channels
    SampleOrg sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg1");
    Channel fooChannel = reconstructChannel(FOO_CHANNEL_NAME, client, sampleOrg);
    runChannel(client, fooChannel, sampleOrg, 0);
    assertFalse(fooChannel.isShutdown());
    assertTrue(fooChannel.isInitialized());
    fooChannel.shutdown(true); //clean up resources no longer needed.
    assertTrue(fooChannel.isShutdown());
    out("\n");

    sampleOrg = testConfig.getIntegrationTestsSampleOrg("peerOrg2");
    Channel barChannel = reconstructChannel(BAR_CHANNEL_NAME, client, sampleOrg);
    runChannel(client, barChannel, sampleOrg, 100); //run a newly constructed foo channel with different b value!
    assertFalse(barChannel.isShutdown());
    assertTrue(barChannel.isInitialized());

    if (!testConfig.isRunningAgainstFabric10()) { //Peer eventing service support started with v1.1

        // Now test replay feature of V1.1 peer eventing services.
        byte[] replayChannelBytes = barChannel.serializeChannel();
        barChannel.shutdown(true);

        Channel replayChannel = client.deSerializeChannel(replayChannelBytes);

        out("doing testPeerServiceEventingReplay,0,-1,false");
        testPeerServiceEventingReplay(client, replayChannel, 0L, -1L, false);

        replayChannel = client.deSerializeChannel(replayChannelBytes);
        out("doing testPeerServiceEventingReplay,0,-1,true"); // block 0 is import to test
        testPeerServiceEventingReplay(client, replayChannel, 0L, -1L, true);

        //Now do it again starting at block 1
        replayChannel = client.deSerializeChannel(replayChannelBytes);
        out("doing testPeerServiceEventingReplay,1,-1,false");
        testPeerServiceEventingReplay(client, replayChannel, 1L, -1L, false);

        //Now do it again starting at block 2 to 3
        replayChannel = client.deSerializeChannel(replayChannelBytes);
        out("doing testPeerServiceEventingReplay,2,3,false");
        testPeerServiceEventingReplay(client, replayChannel, 2L, 3L, false);

    }

    out("That's all folks!");
}
 
Example 7
Source File: NetworkConfigIT.java    From fabric-sdk-java with Apache License 2.0 3 votes vote down vote up
private static HFClient getTheClient() throws Exception {

        HFClient client = HFClient.createNewInstance();
        client.setCryptoSuite(CryptoSuite.Factory.getCryptoSuite());

        User peerAdmin = getAdminUser(TEST_ORG);
        client.setUserContext(peerAdmin);

        return client;
    }