Search in sources :

Example 1 with ChaincodeID

use of org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeID in project fabric-sdk-java by hyperledger.

the class ProtoUtils method createDeploymentSpec.

public static ChaincodeDeploymentSpec createDeploymentSpec(Type ccType, String name, String chaincodePath, String chaincodeVersion, List<String> args, byte[] codePackage) {
    ChaincodeID.Builder chaincodeIDBuilder = ChaincodeID.newBuilder().setName(name).setVersion(chaincodeVersion);
    if (chaincodePath != null) {
        chaincodeIDBuilder = chaincodeIDBuilder.setPath(chaincodePath);
    }
    ChaincodeID chaincodeID = chaincodeIDBuilder.build();
    // build chaincodeInput
    List<ByteString> argList = new ArrayList<>(args == null ? 0 : args.size());
    if (args != null && args.size() != 0) {
        for (String arg : args) {
            argList.add(ByteString.copyFrom(arg.getBytes(UTF_8)));
        }
    }
    ChaincodeInput chaincodeInput = ChaincodeInput.newBuilder().addAllArgs(argList).build();
    // Construct the ChaincodeSpec
    ChaincodeSpec chaincodeSpec = ChaincodeSpec.newBuilder().setType(ccType).setChaincodeId(chaincodeID).setInput(chaincodeInput).build();
    if (isDebugLevel) {
        StringBuilder sb = new StringBuilder(1000);
        sb.append("ChaincodeDeploymentSpec chaincode cctype: ").append(ccType.name()).append(", name:").append(chaincodeID.getName()).append(", path: ").append(chaincodeID.getPath()).append(", version: ").append(chaincodeID.getVersion());
        String sep = "";
        sb.append(" args(");
        for (ByteString x : argList) {
            sb.append(sep).append("\"").append(logString(new String(x.toByteArray(), UTF_8))).append("\"");
            sep = ", ";
        }
        sb.append(")");
        logger.debug(sb.toString());
    }
    ChaincodeDeploymentSpec.Builder chaincodeDeploymentSpecBuilder = ChaincodeDeploymentSpec.newBuilder().setChaincodeSpec(// .setEffectiveDate(context.getFabricTimestamp())
    chaincodeSpec).setExecEnv(ChaincodeDeploymentSpec.ExecutionEnvironment.DOCKER);
    if (codePackage != null) {
        chaincodeDeploymentSpecBuilder.setCodePackage(ByteString.copyFrom(codePackage));
    }
    return chaincodeDeploymentSpecBuilder.build();
}
Also used : ChaincodeInput(org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInput) ChaincodeSpec(org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeSpec) ChaincodeDeploymentSpec(org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeDeploymentSpec) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ChaincodeID(org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeID) ByteString(com.google.protobuf.ByteString) Utils.logString(org.hyperledger.fabric.sdk.helper.Utils.logString) Utils.toHexString(org.hyperledger.fabric.sdk.helper.Utils.toHexString)

Aggregations

ByteString (com.google.protobuf.ByteString)1 ArrayList (java.util.ArrayList)1 ChaincodeDeploymentSpec (org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeDeploymentSpec)1 ChaincodeID (org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeID)1 ChaincodeInput (org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInput)1 ChaincodeSpec (org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeSpec)1 Utils.logString (org.hyperledger.fabric.sdk.helper.Utils.logString)1 Utils.toHexString (org.hyperledger.fabric.sdk.helper.Utils.toHexString)1