org.hyperledger.fabric.sdk.Orderer Java Examples
The following examples show how to use
org.hyperledger.fabric.sdk.Orderer.
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: FabricSDKWrapper.java From WeEvent with Apache License 2.0 | 5 votes |
public static Channel initializeChannel(HFClient client, String channelName, FabricConfig fabricConfig) throws InvalidArgumentException, TransactionException { Orderer orderer1 = getOrderer(client, fabricConfig); Peer peer0 = getPeer(client, fabricConfig); Channel channel = client.newChannel(channelName); channel.addOrderer(orderer1); channel.addPeer(peer0); channel.initialize(); return channel; }
Example #2
Source File: FabricSDKWrapper.java From WeEvent with Apache License 2.0 | 5 votes |
private static Orderer getOrderer(HFClient client, FabricConfig fabricConfig) throws InvalidArgumentException { Properties orderer1Prop = new Properties(); orderer1Prop.setProperty("pemFile", fabricConfig.getOrdererTlsCaFile()); orderer1Prop.setProperty("sslProvider", "openSSL"); orderer1Prop.setProperty("negotiationType", "TLS"); orderer1Prop.setProperty("ordererWaitTimeMilliSecs", "300000"); orderer1Prop.setProperty("hostnameOverride", "orderer"); orderer1Prop.setProperty("trustServerCertificate", "true"); orderer1Prop.setProperty("allowAllHostNames", "true"); return client.newOrderer("orderer", fabricConfig.getOrdererAddress(), orderer1Prop); }
Example #3
Source File: CreateChannel.java From blockchain-application-using-fabric-java-sdk with Apache License 2.0 | 4 votes |
public static void main(String[] args) { try { CryptoSuite.Factory.getCryptoSuite(); Util.cleanUp(); // Construct Channel UserContext org1Admin = new UserContext(); File pkFolder1 = new File(Config.ORG1_USR_ADMIN_PK); File[] pkFiles1 = pkFolder1.listFiles(); File certFolder1 = new File(Config.ORG1_USR_ADMIN_CERT); File[] certFiles1 = certFolder1.listFiles(); Enrollment enrollOrg1Admin = Util.getEnrollment(Config.ORG1_USR_ADMIN_PK, pkFiles1[0].getName(), Config.ORG1_USR_ADMIN_CERT, certFiles1[0].getName()); org1Admin.setEnrollment(enrollOrg1Admin); org1Admin.setMspId(Config.ORG1_MSP); org1Admin.setName(Config.ADMIN); UserContext org2Admin = new UserContext(); File pkFolder2 = new File(Config.ORG2_USR_ADMIN_PK); File[] pkFiles2 = pkFolder2.listFiles(); File certFolder2 = new File(Config.ORG2_USR_ADMIN_CERT); File[] certFiles2 = certFolder2.listFiles(); Enrollment enrollOrg2Admin = Util.getEnrollment(Config.ORG2_USR_ADMIN_PK, pkFiles2[0].getName(), Config.ORG2_USR_ADMIN_CERT, certFiles2[0].getName()); org2Admin.setEnrollment(enrollOrg2Admin); org2Admin.setMspId(Config.ORG2_MSP); org2Admin.setName(Config.ADMIN); FabricClient fabClient = new FabricClient(org1Admin); // Create a new channel Orderer orderer = fabClient.getInstance().newOrderer(Config.ORDERER_NAME, Config.ORDERER_URL); ChannelConfiguration channelConfiguration = new ChannelConfiguration(new File(Config.CHANNEL_CONFIG_PATH)); byte[] channelConfigurationSignatures = fabClient.getInstance() .getChannelConfigurationSignature(channelConfiguration, org1Admin); Channel mychannel = fabClient.getInstance().newChannel(Config.CHANNEL_NAME, orderer, channelConfiguration, channelConfigurationSignatures); Peer peer0_org1 = fabClient.getInstance().newPeer(Config.ORG1_PEER_0, Config.ORG1_PEER_0_URL); Peer peer1_org1 = fabClient.getInstance().newPeer(Config.ORG1_PEER_1, Config.ORG1_PEER_1_URL); Peer peer0_org2 = fabClient.getInstance().newPeer(Config.ORG2_PEER_0, Config.ORG2_PEER_0_URL); Peer peer1_org2 = fabClient.getInstance().newPeer(Config.ORG2_PEER_1, Config.ORG2_PEER_1_URL); mychannel.joinPeer(peer0_org1); mychannel.joinPeer(peer1_org1); mychannel.addOrderer(orderer); mychannel.initialize(); fabClient.getInstance().setUserContext(org2Admin); mychannel = fabClient.getInstance().getChannel("mychannel"); mychannel.joinPeer(peer0_org2); mychannel.joinPeer(peer1_org2); Logger.getLogger(CreateChannel.class.getName()).log(Level.INFO, "Channel created "+mychannel.getName()); Collection peers = mychannel.getPeers(); Iterator peerIter = peers.iterator(); while (peerIter.hasNext()) { Peer pr = (Peer) peerIter.next(); Logger.getLogger(CreateChannel.class.getName()).log(Level.INFO,pr.getName()+ " at " + pr.getUrl()); } } catch (Exception e) { e.printStackTrace(); } }
Example #4
Source File: InvokeChaincode.java From blockchain-application-using-fabric-java-sdk with Apache License 2.0 | 4 votes |
public static void main(String args[]) { try { Util.cleanUp(); String caUrl = Config.CA_ORG1_URL; CAClient caClient = new CAClient(caUrl, null); // Enroll Admin to Org1MSP UserContext adminUserContext = new UserContext(); adminUserContext.setName(Config.ADMIN); adminUserContext.setAffiliation(Config.ORG1); adminUserContext.setMspId(Config.ORG1_MSP); caClient.setAdminUserContext(adminUserContext); adminUserContext = caClient.enrollAdminUser(Config.ADMIN, Config.ADMIN_PASSWORD); FabricClient fabClient = new FabricClient(adminUserContext); ChannelClient channelClient = fabClient.createChannelClient(Config.CHANNEL_NAME); Channel channel = channelClient.getChannel(); Peer peer = fabClient.getInstance().newPeer(Config.ORG1_PEER_0, Config.ORG1_PEER_0_URL); EventHub eventHub = fabClient.getInstance().newEventHub("eventhub01", "grpc://localhost:7053"); Orderer orderer = fabClient.getInstance().newOrderer(Config.ORDERER_NAME, Config.ORDERER_URL); channel.addPeer(peer); channel.addEventHub(eventHub); channel.addOrderer(orderer); channel.initialize(); TransactionProposalRequest request = fabClient.getInstance().newTransactionProposalRequest(); ChaincodeID ccid = ChaincodeID.newBuilder().setName(Config.CHAINCODE_1_NAME).build(); request.setChaincodeID(ccid); request.setFcn("createCar"); String[] arguments = { "CAR1", "Chevy", "Volt", "Red", "Nick" }; request.setArgs(arguments); request.setProposalWaitTime(1000); Map<String, byte[]> tm2 = new HashMap<>(); tm2.put("HyperLedgerFabric", "TransactionProposalRequest:JavaSDK".getBytes(UTF_8)); tm2.put("method", "TransactionProposalRequest".getBytes(UTF_8)); tm2.put("result", ":)".getBytes(UTF_8)); tm2.put(EXPECTED_EVENT_NAME, EXPECTED_EVENT_DATA); request.setTransientMap(tm2); Collection<ProposalResponse> responses = channelClient.sendTransactionProposal(request); for (ProposalResponse res: responses) { Status status = res.getStatus(); Logger.getLogger(InvokeChaincode.class.getName()).log(Level.INFO,"Invoked createCar on "+Config.CHAINCODE_1_NAME + ". Status - " + status); } } catch (Exception e) { e.printStackTrace(); } }
Example #5
Source File: ChaincodeServiceImpl.java From balance-transfer-java with Apache License 2.0 | 4 votes |
/** * installs the chaincode takes as input chaincode name returns status as * string */ public String installChaincode(String chaincodeName) { try { checkConfig(); chaincodeID = getChaincodeId(chaincodeName); Org sampleOrg = Conf.getSampleOrg("peerOrg1"); Channel channel = reconstructChannel(); final String channelName = channel.getName(); boolean isFooChain = channelName.equals(channelName); logger.info("Running channel %s", channelName); Collection<Peer> channelPeers = channel.getPeers(); Collection<Orderer> orderers = channel.getOrderers(); client.setUserContext(sampleOrg.getPeerAdmin()); logger.info("Creating install proposal"); InstallProposalRequest installProposalRequest = client.newInstallProposalRequest(); installProposalRequest.setChaincodeID(chaincodeID); installProposalRequest.setChaincodeSourceLocation(new File(PATH + "/artifacts/")); installProposalRequest.setChaincodeVersion(chainCodeVersion); logger.info("Sending install proposal"); int numInstallProposal = 0; Set<Peer> peersFromOrg = sampleOrg.getPeers(); numInstallProposal = numInstallProposal + peersFromOrg.size(); responses = client.sendInstallProposal(installProposalRequest, peersFromOrg); for (ProposalResponse response : responses) { if (response.getStatus() == ProposalResponse.Status.SUCCESS) { out("Successful install proposal response Txid: %s from peer %s", response.getTransactionID(), response.getPeer().getName()); successful.add(response); } else { failed.add(response); } } SDKUtils.getProposalConsistencySets(responses); // } logger.info("Received %d install proposal responses. Successful+verified: %d . Failed: %d", numInstallProposal, successful.size(), failed.size()); if (failed.size() > 0) { ProposalResponse first = failed.iterator().next(); fail("Not enough endorsers for install :" + successful.size() + ". " + first.getMessage()); return "Not enough endorsers for install :" + successful.size() + ". " + first.getMessage(); } return "Chaincode installed successfully"; } catch (Exception e) { logger.error("ChaincodeServiceImpl | installChaincode | " +e.getMessage()); return "Chaincode installation failed"; } }