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

Commit a239686

Browse files
FABJ-544 Add ability to check if a transaction is the init transaction (#106) (#108)
Signed-off-by: Danilo Faria <danilo@digitalasset.com> Co-authored-by: Danilo Faria <danilo@digitalasset.com>
1 parent 5f08e57 commit a239686

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,24 @@ public byte[] getChaincodeInputArgs(int index) {
465465
return input.getArgs(index).toByteArray();
466466
}
467467

468+
/**
469+
* Checks if this transaction is an init transaction.
470+
* The init transaction is the one called to initialize a chaincode that requires the invocation of a
471+
* function with an init flag set to true by calling either {@link TransactionRequest#setInit(boolean)}
472+
* or passing --isInit if using the cli.
473+
* @return boolean value indicating whether this is an init transaction
474+
*/
475+
public boolean getChaincodeInputIsInit() {
476+
if (isFiltered()) {
477+
return false;
478+
}
479+
480+
ChaincodeInput input = transactionAction.getPayload().getChaincodeProposalPayload().
481+
getChaincodeInvocationSpec().getChaincodeInput().getChaincodeInput();
482+
483+
return input.getIsInit();
484+
}
485+
468486
int getEndorsementsCount = -1;
469487

470488
public int getEndorsementsCount() {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ void runChannel(HFClient org1Client, Channel org1Channel, SampleOrg org1, Collec
473473
chaincodeName, chaincodeType, "a,", "100", "b", "300").get(testConfig.getTransactionWaitTime(), TimeUnit.SECONDS);
474474
assertTrue(transactionEvent.isValid());
475475

476+
if (initRequired) {
477+
assertTrue(transactionEvent.getTransactionActionInfo(0).getChaincodeInputIsInit());
478+
}
479+
476480
transactionEvent = executeChaincode(org2Client, org2.getPeerAdmin(), org2Channel, "move",
477481
false, // doInit
478482
chaincodeName, chaincodeType, "a,", "b", "10").get(testConfig.getTransactionWaitTime(), TimeUnit.SECONDS);

0 commit comments

Comments
 (0)