org.hyperledger.fabric.sdk.InstallProposalRequest Java Examples
The following examples show how to use
org.hyperledger.fabric.sdk.InstallProposalRequest.
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: FabricClient.java From blockchain-application-using-fabric-java-sdk with Apache License 2.0 | 6 votes |
/** * Deploy chain code. * * @param chainCodeName * @param chaincodePath * @param codepath * @param language * @param version * @param peers * @return * @throws InvalidArgumentException * @throws IOException * @throws ProposalException */ public Collection<ProposalResponse> deployChainCode(String chainCodeName, String chaincodePath, String codepath, String language, String version, Collection<Peer> peers) throws InvalidArgumentException, IOException, ProposalException { InstallProposalRequest request = instance.newInstallProposalRequest(); ChaincodeID.Builder chaincodeIDBuilder = ChaincodeID.newBuilder().setName(chainCodeName).setVersion(version) .setPath(chaincodePath); ChaincodeID chaincodeID = chaincodeIDBuilder.build(); Logger.getLogger(FabricClient.class.getName()).log(Level.INFO, "Deploying chaincode " + chainCodeName + " using Fabric client " + instance.getUserContext().getMspId() + " " + instance.getUserContext().getName()); request.setChaincodeID(chaincodeID); request.setUserContext(instance.getUserContext()); request.setChaincodeSourceLocation(new File(codepath)); request.setChaincodeVersion(version); Collection<ProposalResponse> responses = instance.sendInstallProposal(request, peers); return responses; }
Example #2
Source File: FabricSDKWrapper.java From WeEvent with Apache License 2.0 | 5 votes |
public static Collection<ProposalResponse> installProposal(HFClient client, Channel channel, ChaincodeID chaincodeID, TransactionRequest.Type chaincodeLang, // Type.GO_LANG String chaincodeVer, // "v1" String chaincodeSourceLoc, // "/opt/gopath" String chaincodePath // "github.com/hyperledger/fabric/peer/chaincode/go/chaincode_example02 ) throws InvalidArgumentException, ProposalException { InstallProposalRequest installProposalRequest = client.newInstallProposalRequest(); installProposalRequest.setChaincodeID(chaincodeID); installProposalRequest.setChaincodeVersion(chaincodeVer); installProposalRequest.setChaincodeLanguage(chaincodeLang); installProposalRequest.setChaincodeSourceLocation(new File(chaincodeSourceLoc)); installProposalRequest.setChaincodePath(chaincodePath); return client.sendInstallProposal(installProposalRequest, channel.getPeers()); }
Example #3
Source File: QueryBlock.java From fabric-jdbc-connector with Apache License 2.0 | 5 votes |
private InstallProposalRequest getInstallProposalRequest(String chaincodeName, String version, String goPath, String chainCodePath, Org sampleOrg) throws InvalidArgumentException { ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(chaincodeName).setVersion(version) .setPath(chainCodePath).build(); final String channelName = channel.getName(); logger.info(String.format("Running channel %s", channelName)); client.setUserContext(sampleOrg.getPeerAdmin()); logger.info("Creating install proposal"); InstallProposalRequest installProposalRequest = client.newInstallProposalRequest(); installProposalRequest.setChaincodeID(chaincodeID); installProposalRequest.setChaincodeSourceLocation(new File(goPath)); installProposalRequest.setChaincodeVersion(version); return installProposalRequest; }
Example #4
Source File: QueryBlockTest.java From fabric-jdbc-connector with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testInstallChainCode() throws ClassNotFoundException, SQLException, InvalidArgumentException{ PowerMockito.mockStatic(SDKUtils.class); PowerMockito.mockStatic(HFClient.class); when(HFClient.createNewInstance()).thenReturn(mockClient); Channel mockChannel = mock(Channel.class); when(mockClient.newChannel(anyString())).thenReturn(mockChannel); InstallProposalRequest mockInstallProposalRequest = mock(InstallProposalRequest.class); when(mockClient.newInstallProposalRequest()).thenReturn(mockInstallProposalRequest); String configPath = "src/test/resources/blockchain-query"; Class.forName("com.impetus.fabric.jdbc.FabricDriver"); QueryBlock qb = new QueryBlock(configPath,"mychannel", null, null); qb.setChannel(); String chaincodeName ="chncodefunc"; String version = "1.0"; String chaincodePath = "hyperledger/fabric/examples/chaincode/go/chaincode_example02"; when(SDKUtils.getProposalConsistencySets(anyCollection())).thenReturn(new ArrayList<>()); String result = qb.installChaincode(chaincodeName, version, qb.getConf().getConfigPath(), chaincodePath); assert(result.equals("Chaincode installed successfully")); }
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"; } }