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();
}
Aggregations