Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit edd54f8

Browse files
committed
FAB-10075 Missing chaincodeID info in BlockInfo
Change-Id: I36b7c9dd174f0a3f965a6b54e2ca4603759ea5a4 Signed-off-by: rickr <cr22rc@gmail.com>
1 parent cb741fb commit edd54f8

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

src/main/java/org/hyperledger/fabric/sdk/BlockInfo.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.hyperledger.fabric.protos.common.Common.Block;
2525
import org.hyperledger.fabric.protos.ledger.rwset.Rwset.TxReadWriteSet;
2626
import org.hyperledger.fabric.protos.msp.Identities;
27+
import org.hyperledger.fabric.protos.peer.Chaincode;
2728
import org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeInput;
2829
import org.hyperledger.fabric.protos.peer.FabricTransaction;
2930
import org.hyperledger.fabric.protos.peer.PeerEvents;
@@ -581,6 +582,73 @@ public int getProposalResponseStatus() {
581582

582583
}
583584

585+
/**
586+
* get name of chaincode with this transaction action
587+
*
588+
* @return name of chaincode. Maybe null if no chaincode or if block is filtered.
589+
*/
590+
public String getChaincodeIDName() {
591+
if (isFiltered()) {
592+
return null;
593+
}
594+
String name = null;
595+
596+
Chaincode.ChaincodeID ccid = transactionAction.getPayload().getAction().getProposalResponsePayload().
597+
getExtension().getChaincodeID();
598+
599+
if (ccid != null) {
600+
name = ccid.getName();
601+
}
602+
603+
return name;
604+
605+
}
606+
607+
/**
608+
* get path of chaincode with this transaction action
609+
*
610+
* @return path of chaincode. Maybe null if no chaincode or if block is filtered.
611+
*/
612+
public String getChaincodeIDPath() {
613+
if (isFiltered()) {
614+
return null;
615+
}
616+
String path = null;
617+
618+
Chaincode.ChaincodeID ccid = transactionAction.getPayload().getAction().getProposalResponsePayload().
619+
getExtension().getChaincodeID();
620+
621+
if (ccid != null) {
622+
path = ccid.getPath();
623+
}
624+
625+
return path;
626+
627+
}
628+
629+
/**
630+
* get version of chaincode with this transaction action
631+
*
632+
* @return version of chaincode. Maybe null if no chaincode or if block is filtered.
633+
*/
634+
635+
public String getChaincodeIDVersion() {
636+
if (isFiltered()) {
637+
return null;
638+
}
639+
String version = null;
640+
641+
Chaincode.ChaincodeID ccid = transactionAction.getPayload().getAction().getProposalResponsePayload().
642+
getExtension().getChaincodeID();
643+
644+
if (ccid != null) {
645+
version = ccid.getVersion();
646+
}
647+
648+
return version;
649+
650+
}
651+
584652
/**
585653
* Get read write set for this transaction. Will return null on for Eventhub events.
586654
* For eventhub events find the block by block number to get read write set if needed.

src/main/java/org/hyperledger/fabric/sdk/ChaincodeActionDeserializer.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.protobuf.ByteString;
2222
import com.google.protobuf.InvalidProtocolBufferException;
2323
import org.hyperledger.fabric.protos.ledger.rwset.Rwset.TxReadWriteSet;
24+
import org.hyperledger.fabric.protos.peer.Chaincode;
2425
import org.hyperledger.fabric.sdk.exception.InvalidProtocolBufferRuntimeException;
2526

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

5758
}
5859

60+
Chaincode.ChaincodeID getChaincodeID() {
61+
Chaincode.ChaincodeID ret = null;
62+
63+
ChaincodeAction chaincodeAction = getChaincodeAction();
64+
if (chaincodeAction.hasChaincodeId()) {
65+
ret = chaincodeAction.getChaincodeId();
66+
}
67+
return ret;
68+
69+
}
70+
5971
ChaincodeEvent getEvent() {
6072

6173
ChaincodeAction ca = getChaincodeAction();

src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,12 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
956956
out(" Transaction action %d proposal response payload: %s", j,
957957
printableString(new String(transactionActionInfo.getProposalResponsePayload())));
958958

959+
String chaincodeIDName = transactionActionInfo.getChaincodeIDName();
960+
String chaincodeIDVersion = transactionActionInfo.getChaincodeIDVersion();
961+
String chaincodeIDPath = transactionActionInfo.getChaincodeIDPath();
962+
out(" Transaction action %d proposal chaincodeIDName: %s, chaincodeIDVersion: %s, chaincodeIDPath: %s ", j,
963+
chaincodeIDName, chaincodeIDVersion, chaincodeIDPath);
964+
959965
// Check to see if we have our expected event.
960966
if (blockNumber == 2) {
961967
ChaincodeEvent chaincodeEvent = transactionActionInfo.getEvent();
@@ -965,6 +971,9 @@ void blockWalker(HFClient client, Channel channel) throws InvalidArgumentExcepti
965971
assertEquals(testTxID, chaincodeEvent.getTxId());
966972
assertEquals(CHAIN_CODE_NAME, chaincodeEvent.getChaincodeId());
967973
assertEquals(EXPECTED_EVENT_NAME, chaincodeEvent.getEventName());
974+
assertEquals(CHAIN_CODE_NAME, chaincodeIDName);
975+
assertEquals("github.com/example_cc", chaincodeIDPath);
976+
assertEquals("1", chaincodeIDVersion);
968977

969978
}
970979

0 commit comments

Comments
 (0)