org.hyperledger.fabric.sdk.ChaincodeEndorsementPolicy Java Examples

The following examples show how to use org.hyperledger.fabric.sdk.ChaincodeEndorsementPolicy. 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 6 votes vote down vote up
private InstantiateProposalRequest getInstantiateProposalRequest(String chaincodeName, String chainCodeVersion,
        String chainCodePath, String chaincodeFunction, String[] chaincodeArgs, Endorsers endorsers) throws InvalidArgumentException {
    client.setUserContext(userOrg.getPeerAdmin());
    ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(chaincodeName).setVersion(chainCodeVersion)
            .setPath(chainCodePath).build();
    InstantiateProposalRequest instantiateProposalRequest = client.newInstantiationProposalRequest();
    instantiateProposalRequest.setProposalWaitTime(conf.getProposalWaitTime());
    instantiateProposalRequest.setChaincodeID(chaincodeID);
    instantiateProposalRequest.setFcn(chaincodeFunction);
    instantiateProposalRequest.setArgs(chaincodeArgs);
    if(endorsers != null) {
        ChaincodeEndorsementPolicy policy = getChaincodeEndorsementPolicy(endorsers);
        instantiateProposalRequest.setChaincodeEndorsementPolicy(policy);
    }
    return instantiateProposalRequest;
}
 
Example #2
Source File: QueryBlock.java    From fabric-jdbc-connector with Apache License 2.0 6 votes vote down vote up
private UpgradeProposalRequest getUpgradeProposalRequest(String chaincodeName, String chainCodeVersion,
        String chainCodePath, String chaincodeFunction, String[] chaincodeArgs, Endorsers endorsers) throws InvalidArgumentException {
    client.setUserContext(userOrg.getPeerAdmin());
    ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName(chaincodeName).setVersion(chainCodeVersion)
            .setPath(chainCodePath).build();
    UpgradeProposalRequest upgradeProposalRequest = client.newUpgradeProposalRequest();
    upgradeProposalRequest.setProposalWaitTime(conf.getProposalWaitTime());
    upgradeProposalRequest.setChaincodeID(chaincodeID);
    upgradeProposalRequest.setFcn(chaincodeFunction);
    upgradeProposalRequest.setArgs(chaincodeArgs);
    if(endorsers != null) {
        ChaincodeEndorsementPolicy policy = getChaincodeEndorsementPolicy(endorsers);
        upgradeProposalRequest.setChaincodeEndorsementPolicy(policy);
    }
    return upgradeProposalRequest;
}
 
Example #3
Source File: QueryBlock.java    From fabric-jdbc-connector with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: ChannelClient.java    From blockchain-application-using-fabric-java-sdk with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * 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;
}
 
Example #5
Source File: InstantiateProposalBuilder.java    From fabric-sdk-java with Apache License 2.0 4 votes vote down vote up
public void chaincodEndorsementPolicy(ChaincodeEndorsementPolicy policy) {
    if (policy != null) {
        this.chaincodePolicy = policy.getChaincodeEndorsementPolicyAsBytes();
    }
}