Skip to content

Commit

Permalink
FAB-10075 Missing chaincodeID info in BlockInfo
Browse files Browse the repository at this point in the history
Change-Id: I36b7c9dd174f0a3f965a6b54e2ca4603759ea5a4
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed May 31, 2018
1 parent cb741fb commit edd54f8
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.hyperledger.fabric.protos.common.Common.Block;
import org.hyperledger.fabric.protos.ledger.rwset.Rwset.TxReadWriteSet;
import org.hyperledger.fabric.protos.msp.Identities;
import org.hyperledger.fabric.protos.peer.Chaincode;
import org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInput;
import org.hyperledger.fabric.protos.peer.FabricTransaction;
import org.hyperledger.fabric.protos.peer.PeerEvents;
Expand Down Expand Up @@ -581,6 +582,73 @@ public int getProposalResponseStatus() {

}

/**
* get name of chaincode with this transaction action
*
* @return name of chaincode. Maybe null if no chaincode or if block is filtered.
*/
public String getChaincodeIDName() {
if (isFiltered()) {
return null;
}
String name = null;

Chaincode.ChaincodeID ccid = transactionAction.getPayload().getAction().getProposalResponsePayload().
getExtension().getChaincodeID();

if (ccid != null) {
name = ccid.getName();
}

return name;

}

/**
* get path of chaincode with this transaction action
*
* @return path of chaincode. Maybe null if no chaincode or if block is filtered.
*/
public String getChaincodeIDPath() {
if (isFiltered()) {
return null;
}
String path = null;

Chaincode.ChaincodeID ccid = transactionAction.getPayload().getAction().getProposalResponsePayload().
getExtension().getChaincodeID();

if (ccid != null) {
path = ccid.getPath();
}

return path;

}

/**
* get version of chaincode with this transaction action
*
* @return version of chaincode. Maybe null if no chaincode or if block is filtered.
*/

public String getChaincodeIDVersion() {
if (isFiltered()) {
return null;
}
String version = null;

Chaincode.ChaincodeID ccid = transactionAction.getPayload().getAction().getProposalResponsePayload().
getExtension().getChaincodeID();

if (ccid != null) {
version = ccid.getVersion();
}

return version;

}

/**
* Get read write set for this transaction. Will return null on for Eventhub events.
* For eventhub events find the block by block number to get read write set if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import org.hyperledger.fabric.protos.ledger.rwset.Rwset.TxReadWriteSet;
import org.hyperledger.fabric.protos.peer.Chaincode;
import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException;

import static org.hyperledger.fabric.protos.peer.FabricProposal.ChaincodeAction;
Expand Down Expand Up @@ -56,6 +57,17 @@ ChaincodeAction getChaincodeAction() {

}

Chaincode.ChaincodeID getChaincodeID() {
Chaincode.ChaincodeID ret = null;

ChaincodeAction chaincodeAction = getChaincodeAction();
if (chaincodeAction.hasChaincodeId()) {
ret = chaincodeAction.getChaincodeId();
}
return ret;

}

ChaincodeEvent getEvent() {

ChaincodeAction ca = getChaincodeAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,12 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
out(" Transaction action %d proposal response payload: %s", j,
printableString(new String(transactionActionInfo.getProposalResponsePayload())));

String chaincodeIDName = transactionActionInfo.getChaincodeIDName();
String chaincodeIDVersion = transactionActionInfo.getChaincodeIDVersion();
String chaincodeIDPath = transactionActionInfo.getChaincodeIDPath();
out(" Transaction action %d proposal chaincodeIDName: %s, chaincodeIDVersion: %s, chaincodeIDPath: %s ", j,
chaincodeIDName, chaincodeIDVersion, chaincodeIDPath);

// Check to see if we have our expected event.
if (blockNumber == 2) {
ChaincodeEvent chaincodeEvent = transactionActionInfo.getEvent();
Expand All @@ -965,6 +971,9 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
assertEquals(testTxID, chaincodeEvent.getTxId());
assertEquals(CHAIN_CODE_NAME, chaincodeEvent.getChaincodeId());
assertEquals(EXPECTED_EVENT_NAME, chaincodeEvent.getEventName());
assertEquals(CHAIN_CODE_NAME, chaincodeIDName);
assertEquals("github.com/example_cc", chaincodeIDPath);
assertEquals("1", chaincodeIDVersion);

}

Expand Down

0 comments on commit edd54f8

Please sign in to comment.