Java Code Examples for org.hyperledger.fabric.sdk.ChaincodeEndorsementPolicy#fromYamlFile()
The following examples show how to use
org.hyperledger.fabric.sdk.ChaincodeEndorsementPolicy#fromYamlFile() .
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: QueryBlock.java From fabric-jdbc-connector with Apache License 2.0 | 5 votes |
private ChaincodeEndorsementPolicy getChaincodeEndorsementPolicy(Endorsers endorsers) { ChaincodeEndorsementPolicy policy = new ChaincodeEndorsementPolicy(); PolicyFile policyFile = endorsers.getChildType(PolicyFile.class, 0); String fileLoc = policyFile.getFileLocation().replace("'", "").replace("\"", ""); try { policy.fromYamlFile(new File(fileLoc)); } catch (ChaincodeEndorsementPolicyParseException | IOException e) { String errMsg = "QueryBlock | getChaincodeEndorsementPolicy |" + e; logger.error(errMsg); throw new BlkchnException(errMsg, e); } return policy; }
Example 2
Source File: ChannelClient.java From blockchain-application-using-fabric-java-sdk with Apache License 2.0 | 4 votes |
/** * * Instantiate chaincode. * * @param chaincodeName * @param version * @param chaincodePath * @param language * @param functionName * @param functionArgs * @param policyPath * @return * @throws InvalidArgumentException * @throws ProposalException * @throws ChaincodeEndorsementPolicyParseException * @throws IOException */ public Collection<ProposalResponse> instantiateChainCode(String chaincodeName, String version, String chaincodePath, String language, String functionName, String[] functionArgs, String policyPath) throws InvalidArgumentException, ProposalException, ChaincodeEndorsementPolicyParseException, IOException { Logger.getLogger(ChannelClient.class.getName()).log(Level.INFO, "Instantiate proposal request " + chaincodeName + " on channel " + channel.getName() + " with Fabric client " + fabClient.getInstance().getUserContext().getMspId() + " " + fabClient.getInstance().getUserContext().getName()); InstantiateProposalRequest instantiateProposalRequest = fabClient.getInstance() .newInstantiationProposalRequest(); instantiateProposalRequest.setProposalWaitTime(180000); ChaincodeID.Builder chaincodeIDBuilder = ChaincodeID.newBuilder().setName(chaincodeName).setVersion(version) .setPath(chaincodePath); ChaincodeID ccid = chaincodeIDBuilder.build(); Logger.getLogger(ChannelClient.class.getName()).log(Level.INFO, "Instantiating Chaincode ID " + chaincodeName + " on channel " + channel.getName()); instantiateProposalRequest.setChaincodeID(ccid); if (language.equals(Type.GO_LANG.toString())) instantiateProposalRequest.setChaincodeLanguage(Type.GO_LANG); else instantiateProposalRequest.setChaincodeLanguage(Type.JAVA); instantiateProposalRequest.setFcn(functionName); instantiateProposalRequest.setArgs(functionArgs); Map<String, byte[]> tm = new HashMap<>(); tm.put("HyperLedgerFabric", "InstantiateProposalRequest:JavaSDK".getBytes(UTF_8)); tm.put("method", "InstantiateProposalRequest".getBytes(UTF_8)); instantiateProposalRequest.setTransientMap(tm); if (policyPath != null) { ChaincodeEndorsementPolicy chaincodeEndorsementPolicy = new ChaincodeEndorsementPolicy(); chaincodeEndorsementPolicy.fromYamlFile(new File(policyPath)); instantiateProposalRequest.setChaincodeEndorsementPolicy(chaincodeEndorsementPolicy); } Collection<ProposalResponse> responses = channel.sendInstantiationProposal(instantiateProposalRequest); CompletableFuture<TransactionEvent> cf = channel.sendTransaction(responses); Logger.getLogger(ChannelClient.class.getName()).log(Level.INFO, "Chaincode " + chaincodeName + " on channel " + channel.getName() + " instantiation " + cf); return responses; }