use of org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInput in project fabric-sdk-java by hyperledger.
the class ProposalBuilder method createChaincodeInvocationSpec.
private ChaincodeInvocationSpec createChaincodeInvocationSpec(Chaincode.ChaincodeID chaincodeID, ChaincodeSpec.Type langType) {
List<ByteString> allArgs = new ArrayList<>();
if (argList != null && argList.size() > 0) {
// If we already have an argList then the Builder subclasses have already set the arguments
// for chaincodeInput. Accept the list and pass it on to the chaincodeInput builder
// TODO need to clean this logic up so that common protobuf struct builds are in one place
allArgs = argList;
} else if (request != null) {
// if argList is empty and we have a Request, build the chaincodeInput args array from the Request args and argbytes lists
allArgs.add(ByteString.copyFrom(request.getFcn(), UTF_8));
List<String> args = request.getArgs();
if (args != null && args.size() > 0) {
for (String arg : args) {
allArgs.add(ByteString.copyFrom(arg.getBytes(UTF_8)));
}
}
// TODO currently assume that chaincodeInput args are strings followed by byte[].
// Either agree with Fabric folks that this will always be the case or modify all Builders to expect
// a List of Objects and determine if each list item is a string or a byte array
List<byte[]> argBytes = request.getArgBytes();
if (argBytes != null && argBytes.size() > 0) {
for (byte[] arg : argBytes) {
allArgs.add(ByteString.copyFrom(arg));
}
}
}
if (IS_DEBUG_LEVEL) {
StringBuilder logout = new StringBuilder(1000);
logout.append(format("ChaincodeInvocationSpec type: %s, chaincode name: %s, chaincode path: %s, chaincode version: %s", langType.name(), chaincodeID.getName(), chaincodeID.getPath(), chaincodeID.getVersion()));
String sep = "";
logout.append(" args(");
for (ByteString x : allArgs) {
logout.append(sep).append("\"").append(logString(new String(x.toByteArray(), UTF_8))).append("\"");
sep = ", ";
}
logout.append(")");
logger.debug(logout.toString());
}
ChaincodeInput chaincodeInput = ChaincodeInput.newBuilder().addAllArgs(allArgs).build();
ChaincodeSpec chaincodeSpec = ChaincodeSpec.newBuilder().setType(langType).setChaincodeId(chaincodeID).setInput(chaincodeInput).build();
return ChaincodeInvocationSpec.newBuilder().setChaincodeSpec(chaincodeSpec).build();
}
use of org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInput 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