Search in sources :

Example 96 with ByteString

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);
    }
}
Also used : InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException)

Example 97 with ByteString

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);
}
Also used : ChaincodeAction(org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeAction) ByteString(com.google.protobuf.ByteString)

Example 98 with ByteString

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);
}
Also used : InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) ByteString(com.google.protobuf.ByteString) Chaincode(org.hyperledger.fabric.protos.peer.Chaincode) ArrayList(java.util.ArrayList) TestUtils.tarBytesToEntryArrayList(org.hyperledger.fabric.sdk.testutils.TestUtils.tarBytesToEntryArrayList) ByteString(com.google.protobuf.ByteString) FabricProposal(org.hyperledger.fabric.protos.peer.FabricProposal) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Example 99 with ByteString

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);
}
Also used : InstallProposalBuilder(org.hyperledger.fabric.sdk.transaction.InstallProposalBuilder) ByteString(com.google.protobuf.ByteString) Chaincode(org.hyperledger.fabric.protos.peer.Chaincode) ArrayList(java.util.ArrayList) TestUtils.tarBytesToEntryArrayList(org.hyperledger.fabric.sdk.testutils.TestUtils.tarBytesToEntryArrayList) ByteString(com.google.protobuf.ByteString) TestUtils(org.hyperledger.fabric.sdk.testutils.TestUtils) FabricProposal(org.hyperledger.fabric.protos.peer.FabricProposal) TransactionContext(org.hyperledger.fabric.sdk.transaction.TransactionContext) File(java.io.File) Test(org.junit.Test)

Example 100 with ByteString

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();
}
Also used : ChaincodeInput(org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInput) ChaincodeSpec(org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeSpec) ProtoUtils.getSignatureHeaderAsByteString(org.hyperledger.fabric.sdk.transaction.ProtoUtils.getSignatureHeaderAsByteString) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ProtoUtils.getSignatureHeaderAsByteString(org.hyperledger.fabric.sdk.transaction.ProtoUtils.getSignatureHeaderAsByteString) ByteString(com.google.protobuf.ByteString) Utils.logString(org.hyperledger.fabric.sdk.helper.Utils.logString)

Aggregations

ByteString (com.google.protobuf.ByteString)407 Test (org.junit.Test)143 ArrayList (java.util.ArrayList)65 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)63 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)40 HashMap (java.util.HashMap)40 IOException (java.io.IOException)38 List (java.util.List)34 Map (java.util.Map)33 ServerRequest (com.pokegoapi.main.ServerRequest)17 ExecutionException (java.util.concurrent.ExecutionException)16 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)15 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)15 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)15 Feature (com.google.cloud.vision.v1.Feature)15 Image (com.google.cloud.vision.v1.Image)15 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)15 ByteBuffer (java.nio.ByteBuffer)14 FileInputStream (java.io.FileInputStream)13 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)12