use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.
the class ProposalResponse method getChaincodeActionResponsePayload.
/**
* ChaincodeActionResponsePayload is the result of the executing chaincode.
*
* @return the result of the executing chaincode.
* @throws InvalidArgumentException
*/
public byte[] getChaincodeActionResponsePayload() throws InvalidArgumentException {
if (isInvalid()) {
throw new InvalidArgumentException("Proposal response is invalid.");
}
try {
final ProposalResponsePayloadDeserializer proposalResponsePayloadDeserializer = getProposalResponsePayloadDeserializer();
ByteString ret = proposalResponsePayloadDeserializer.getExtension().getChaincodeAction().getResponse().getPayload();
if (null == ret) {
return null;
}
return ret.toByteArray();
} catch (InvalidArgumentException e) {
throw e;
} catch (Exception e) {
throw new InvalidArgumentException(e);
}
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.
the class ChaincodeActionDeserializer method getEvent.
ChaincodeEvent getEvent() {
ChaincodeAction ca = getChaincodeAction();
ByteString eventsBytes = ca.getEvents();
if (eventsBytes == null || eventsBytes.isEmpty()) {
return null;
}
return new ChaincodeEvent(eventsBytes);
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.
the class ChannelTest method testProposalBuilderWithOutMetaInf.
@Test
public void testProposalBuilderWithOutMetaInf() throws Exception {
InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
installProposalBuilder.chaincodePath("github.com/example_cc");
installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
installProposalBuilder.chaincodeName("example_cc.go");
installProposalBuilder.chaincodeVersion("1");
Channel channel = hfclient.newChannel("testProposalBuilderWithOutMetaInf");
TransactionContext transactionContext = new TransactionContext(channel, getMockUser("rick", "rickORG"), CryptoSuite.Factory.getCryptoSuite());
installProposalBuilder.context(transactionContext);
// Build it get the proposal. Then unpack it to see if it's what we expect.
FabricProposal.Proposal proposal = installProposalBuilder.build();
FabricProposal.ChaincodeProposalPayload chaincodeProposalPayload = FabricProposal.ChaincodeProposalPayload.parseFrom(proposal.getPayload());
Chaincode.ChaincodeInvocationSpec chaincodeInvocationSpec = Chaincode.ChaincodeInvocationSpec.parseFrom(chaincodeProposalPayload.getInput());
Chaincode.ChaincodeSpec chaincodeSpec = chaincodeInvocationSpec.getChaincodeSpec();
Chaincode.ChaincodeInput input = chaincodeSpec.getInput();
Chaincode.ChaincodeDeploymentSpec chaincodeDeploymentSpec = Chaincode.ChaincodeDeploymentSpec.parseFrom(input.getArgs(1));
ByteString codePackage = chaincodeDeploymentSpec.getCodePackage();
ArrayList tarBytesToEntryArrayList = tarBytesToEntryArrayList(codePackage.toByteArray());
ArrayList<String> expect = new ArrayList(Arrays.asList(new String[] { "src/github.com/example_cc/example_cc.go" }));
assertArrayListEquals("Tar in Install Proposal's codePackage does not have expected entries. ", expect, tarBytesToEntryArrayList);
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString in project fabric-sdk-java by hyperledger.
the class ChannelTest method testProposalBuilderWithMetaInf.
@Test
public void testProposalBuilderWithMetaInf() throws Exception {
InstallProposalBuilder installProposalBuilder = InstallProposalBuilder.newBuilder();
installProposalBuilder.setChaincodeLanguage(TransactionRequest.Type.GO_LANG);
installProposalBuilder.chaincodePath("github.com/example_cc");
installProposalBuilder.setChaincodeSource(new File(SAMPLE_GO_CC));
installProposalBuilder.chaincodeName("example_cc.go");
installProposalBuilder.setChaincodeMetaInfLocation(new File("src/test/fixture/meta-infs/test1"));
installProposalBuilder.chaincodeVersion("1");
Channel channel = hfclient.newChannel("testProposalBuilderWithMetaInf");
TestUtils.MockUser mockUser = getMockUser("rick", "rickORG");
TransactionContext transactionContext = new TransactionContext(channel, mockUser, CryptoSuite.Factory.getCryptoSuite());
installProposalBuilder.context(transactionContext);
// Build it get the proposal. Then unpack it to see if it's what we expect.
FabricProposal.Proposal proposal = installProposalBuilder.build();
FabricProposal.ChaincodeProposalPayload chaincodeProposalPayload = FabricProposal.ChaincodeProposalPayload.parseFrom(proposal.getPayload());
Chaincode.ChaincodeInvocationSpec chaincodeInvocationSpec = Chaincode.ChaincodeInvocationSpec.parseFrom(chaincodeProposalPayload.getInput());
Chaincode.ChaincodeSpec chaincodeSpec = chaincodeInvocationSpec.getChaincodeSpec();
Chaincode.ChaincodeInput input = chaincodeSpec.getInput();
Chaincode.ChaincodeDeploymentSpec chaincodeDeploymentSpec = Chaincode.ChaincodeDeploymentSpec.parseFrom(input.getArgs(1));
ByteString codePackage = chaincodeDeploymentSpec.getCodePackage();
ArrayList tarBytesToEntryArrayList = tarBytesToEntryArrayList(codePackage.toByteArray());
ArrayList<String> expect = new ArrayList(Arrays.asList(new String[] { "META-INF/statedb/couchdb/indexes/MockFakeIndex.json", "src/github.com/example_cc/example_cc.go" }));
assertArrayListEquals("Tar in Install Proposal's codePackage does not have expected entries. ", expect, tarBytesToEntryArrayList);
}
use of org.apache.beam.vendor.grpc.v1p26p0.com.google.protobuf.ByteString 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();
}
Aggregations