Java Code Examples for org.hyperledger.fabric.sdk.ChaincodeResponse.Status#SUCCESS
The following examples show how to use
org.hyperledger.fabric.sdk.ChaincodeResponse.Status#SUCCESS .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FabricQueryResponse.java From spring-fabric-gateway with MIT License | 6 votes |
public static <T> FabricQueryResponse<T> create(ProposalResponse res, Class<T> type) { Status status = res.getStatus(); if (status != Status.SUCCESS) { return failure(res.getMessage()); } else { if (type != null) { try { int chaincodeStatus = res.getChaincodeActionResponseStatus(); if (chaincodeStatus != -1) { byte[] payload = res.getChaincodeActionResponsePayload(); return create(payload, type); } else { return failure("Chaincode executed failure."); } } catch (InvalidArgumentException e) { return failure("Chaincode error: " + e.getMessage()); } } else { return success(null); } } }
Example 2
Source File: FabricQueryResponse.java From spring-fabric-gateway with MIT License | 6 votes |
public static <T> FabricQueryResponse<List<T>> many(ProposalResponse res, Class<T> type) { Status status = res.getStatus(); if (status != Status.SUCCESS) { return failure(res.getMessage()); } else { if (type != null) { try { int chaincodeStatus = res.getChaincodeActionResponseStatus(); if (chaincodeStatus != -1) { byte[] payload = res.getChaincodeActionResponsePayload(); return parsePayloadMany(new String(payload, Charset.forName("utf-8")), type); } else { return failure("Chaincode executed failure."); } } catch (InvalidArgumentException e) { return failure("Chaincode error: " + e.getMessage()); } } else { return success(null); } } }
Example 3
Source File: TestMain.java From fabric_sdk_java_study with Apache License 2.0 | 5 votes |
private static CompletableFuture<BlockEvent.TransactionEvent> sendTranstion(HFClient client, Channel channel, ChaincodeID chaincodeID, User user) { try { //ChaincodeID chaincodeID = ChaincodeID.newBuilder().setName("sampledemo5_9").build(); Collection<ProposalResponse> successful = new LinkedList<>(); TransactionProposalRequest transactionProposalRequest = client.newTransactionProposalRequest(); transactionProposalRequest.setChaincodeID(chaincodeID); transactionProposalRequest.setFcn("invoke"); transactionProposalRequest.setArgs(new String[] {"a","b","1"}); transactionProposalRequest.setProposalWaitTime(300000); transactionProposalRequest.setUserContext(user); Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(transactionProposalRequest); for (ProposalResponse response : invokePropResp) { if (response.getStatus() == Status.SUCCESS) { out("Successful transaction proposal response Txid: %s from peer %s", response.getTransactionID(), response.getPeer().getName()); successful.add(response); } else { out("fiale %s ", "dddd"); } } return channel.sendTransaction(successful,user); } catch (Exception e) { throw new CompletionException(e); } }
Example 4
Source File: End2endAndBackAgainIT.java From fabric_sdk_java_study with Apache License 2.0 | 5 votes |
private void queryChaincodeForExpectedValue(HFClient client, Channel channel, final String expect, ChaincodeID chaincodeID) { out("Now query chaincode on channel %s for the value of b expecting to see: %s", channel.getName(), expect); QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest(); queryByChaincodeRequest.setArgs(new String[] {"query", "b"}); queryByChaincodeRequest.setFcn("invoke"); queryByChaincodeRequest.setChaincodeID(chaincodeID); Collection<ProposalResponse> queryProposals; try { queryProposals = channel.queryByChaincode(queryByChaincodeRequest); } catch (Exception e) { throw new CompletionException(e); } for (ProposalResponse proposalResponse : queryProposals) { if (!proposalResponse.isVerified() || proposalResponse.getStatus() != Status.SUCCESS) { fail("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: " + proposalResponse.getStatus() + ". Messages: " + proposalResponse.getMessage() + ". Was verified : " + proposalResponse.isVerified()); } else { String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8(); out("Query payload of b from peer %s returned %s", proposalResponse.getPeer().getName(), payload); assertEquals(payload, expect); } } }
Example 5
Source File: PrivateDataIT.java From fabric-sdk-java with Apache License 2.0 | 5 votes |
private void queryChaincodeForExpectedValue(HFClient client, Channel channel, final String expect, ChaincodeID chaincodeID) { out("Now query chaincode %s on channel %s for the value of b expecting to see: %s", chaincodeID, channel.getName(), expect); Collection<ProposalResponse> queryProposals; try { QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest(); queryByChaincodeRequest.setFcn("query"); queryByChaincodeRequest.setChaincodeID(chaincodeID); Map<String, byte[]> tmap = new HashMap<>(); tmap.put("B", "b".getBytes(UTF_8)); // test using bytes as args. End2end uses Strings. queryByChaincodeRequest.setTransientMap(tmap); queryProposals = channel.queryByChaincode(queryByChaincodeRequest); } catch (Exception e) { throw new CompletionException(e); } for (ProposalResponse proposalResponse : queryProposals) { if (!proposalResponse.isVerified() || proposalResponse.getStatus() != Status.SUCCESS) { fail("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: " + proposalResponse.getStatus() + ". Messages: " + proposalResponse.getMessage() + ". Was verified : " + proposalResponse.isVerified()); } else { String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8(); out("Query payload of b from peer %s returned %s", proposalResponse.getPeer().getName(), payload); assertEquals(format("Failed compare on channel %s chaincode id %s expected value:'%s', but got:'%s'", channel.getName(), chaincodeID, expect, payload), expect, payload); } } }
Example 6
Source File: NetworkConfigIT.java From fabric-sdk-java with Apache License 2.0 | 5 votes |
private static String queryChaincodeForCurrentValue(HFClient client, Channel channel, ChaincodeID chaincodeID) { out("Now query chaincode on channel %s for the current value of b", channel.getName()); QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest(); queryByChaincodeRequest.setArgs("b"); queryByChaincodeRequest.setFcn("query"); queryByChaincodeRequest.setChaincodeID(chaincodeID); Collection<ProposalResponse> queryProposals; try { queryProposals = channel.queryByChaincode(queryByChaincodeRequest); } catch (Exception e) { throw new CompletionException(e); } String expect = null; for (ProposalResponse proposalResponse : queryProposals) { if (!proposalResponse.isVerified() || proposalResponse.getStatus() != Status.SUCCESS) { fail("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: " + proposalResponse.getStatus() + ". Messages: " + proposalResponse.getMessage() + ". Was verified : " + proposalResponse.isVerified()); } else { String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8(); out("Query payload of b from peer %s returned %s", proposalResponse.getPeer().getName(), payload); if (expect != null) { assertEquals(expect, payload); } else { expect = payload; } } } return expect; }
Example 7
Source File: End2endAndBackAgainIT.java From fabric-sdk-java with Apache License 2.0 | 5 votes |
private void queryChaincodeForExpectedValue(HFClient client, Channel channel, final String expect, ChaincodeID chaincodeID) { out("Now query chaincode %s on channel %s for the value of b expecting to see: %s", chaincodeID, channel.getName(), expect); QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest(); queryByChaincodeRequest.setArgs("b".getBytes(UTF_8)); // test using bytes as args. End2end uses Strings. queryByChaincodeRequest.setFcn("query"); queryByChaincodeRequest.setChaincodeID(chaincodeID); Collection<ProposalResponse> queryProposals; try { queryProposals = channel.queryByChaincode(queryByChaincodeRequest); } catch (Exception e) { throw new CompletionException(e); } for (ProposalResponse proposalResponse : queryProposals) { if (!proposalResponse.isVerified() || proposalResponse.getStatus() != Status.SUCCESS) { fail("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: " + proposalResponse.getStatus() + ". Messages: " + proposalResponse.getMessage() + ". Was verified : " + proposalResponse.isVerified()); } else { String payload = proposalResponse.getProposalResponse().getResponse().getPayload().toStringUtf8(); out("Query payload of b from peer %s returned %s", proposalResponse.getPeer().getName(), payload); assertEquals(format("Failed compare on channel %s chaincode id %s expected value:'%s', but got:'%s'", channel.getName(), chaincodeID, expect, payload), expect, payload); } } }
Example 8
Source File: PrivateDataIT.java From fabric-sdk-java with Apache License 2.0 | 4 votes |
CompletableFuture<BlockEvent.TransactionEvent> setAmount(HFClient client, Channel channel, ChaincodeID chaincodeID, int delta, User user) { try { Collection<ProposalResponse> successful = new LinkedList<>(); Collection<ProposalResponse> failed = new LinkedList<>(); /////////////// /// Send transaction proposal to all peers TransactionProposalRequest transactionProposalRequest = client.newTransactionProposalRequest(); transactionProposalRequest.setChaincodeID(chaincodeID); transactionProposalRequest.setFcn("set"); Map<String, byte[]> transientMap = new HashMap<>(); transientMap.put("A", "a".getBytes(UTF_8)); // test using bytes as args. End2end uses Strings. transientMap.put("AVal", "500".getBytes(UTF_8)); transientMap.put("B", "b".getBytes(UTF_8)); String arg3 = "" + (200 + delta); transientMap.put("BVal", arg3.getBytes(UTF_8)); transactionProposalRequest.setTransientMap(transientMap); transactionProposalRequest.setProposalWaitTime(testConfig.getProposalWaitTime()); if (user != null) { // specific user use that transactionProposalRequest.setUserContext(user); } Collection<ProposalResponse> invokePropResp = channel.sendTransactionProposal(transactionProposalRequest); for (ProposalResponse response : invokePropResp) { if (response.getStatus() == Status.SUCCESS) { out("Successful transaction proposal response Txid: %s from peer %s", response.getTransactionID(), response.getPeer().getName()); successful.add(response); } else { failed.add(response); } } out("Received %d transaction proposal responses for setAmount. Successful+verified: %d . Failed: %d", invokePropResp.size(), successful.size(), failed.size()); if (failed.size() > 0) { ProposalResponse firstTransactionProposalResponse = failed.iterator().next(); throw new ProposalException(format("Not enough endorsers for set(move a,b,%s):%d endorser error:%s. Was verified:%b", 0, firstTransactionProposalResponse.getStatus().getStatus(), firstTransactionProposalResponse.getMessage(), firstTransactionProposalResponse.isVerified())); } out("Successfully received transaction proposal responses for setAmount. Now sending to orderer."); //////////////////////////// // Send transaction to orderer if (user != null) { return channel.sendTransaction(successful, user); } return channel.sendTransaction(successful); } catch (Exception e) { throw new CompletionException(e); } }