Skip to content

Commit 53e49bc

Browse files
committed
[FAB-6848] add channel ID to chaincode message
Chaincodes need the channel ID in the transaction context. This CR follows the work in https://gerrit.hyperledger.org/r/#/c/14919. Change-Id: I0cc33e0b8c3279e069771b2925fc1f33ab912cd4 Signed-off-by: Srinivasan Muralidharan <srinivasan.muralidharan99@gmail.com>
1 parent 92ca115 commit 53e49bc

File tree

4 files changed

+111
-84
lines changed

4 files changed

+111
-84
lines changed

core/chaincode/shim/java/src/main/java/org/hyperledger/fabric/shim/ChaincodeStub.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public interface ChaincodeStub {
7777
*/
7878
String getTxId();
7979

80+
/**
81+
* Returns the channel id
82+
*
83+
* @return the channel id
84+
*/
85+
String getChannelId();
86+
8087
/**
8188
* Invoke another chaincode using the same transaction context.
8289
*

core/chaincode/shim/java/src/main/java/org/hyperledger/fabric/shim/impl/ChaincodeStubImpl.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@
3939

4040
class ChaincodeStubImpl implements ChaincodeStub {
4141

42+
private final String channelId;
4243
private final String txId;
4344
private final Handler handler;
4445
private final List<ByteString> args;
4546
private ChaincodeEvent event;
4647

47-
ChaincodeStubImpl(String txId, Handler handler, List<ByteString> args) {
48+
ChaincodeStubImpl(String channelId, String txId, Handler handler, List<ByteString> args) {
49+
this.channelId = channelId;
4850
this.txId = txId;
4951
this.handler = handler;
5052
this.args = Collections.unmodifiableList(args);
@@ -90,30 +92,35 @@ public ChaincodeEvent getEvent() {
9092
return event;
9193
}
9294

95+
@Override
96+
public String getChannelId() {
97+
return channelId;
98+
}
99+
93100
@Override
94101
public String getTxId() {
95102
return txId;
96103
}
97104

98105
@Override
99106
public byte[] getState(String key) {
100-
return handler.getState(txId, key).toByteArray();
107+
return handler.getState(channelId, txId, key).toByteArray();
101108
}
102109

103110
@Override
104111
public void putState(String key, byte[] value) {
105-
handler.putState(txId, key, ByteString.copyFrom(value));
112+
handler.putState(channelId, txId, key, ByteString.copyFrom(value));
106113
}
107114

108115
@Override
109116
public void delState(String key) {
110-
handler.deleteState(txId, key);
117+
handler.deleteState(channelId, txId, key);
111118
}
112119

113120
@Override
114121
public QueryResultsIterator<KeyValue> getStateByRange(String startKey, String endKey) {
115-
return new QueryResultsIteratorImpl<KeyValue>(this.handler, getTxId(),
116-
handler.getStateByRange(getTxId(), startKey, endKey),
122+
return new QueryResultsIteratorImpl<KeyValue>(this.handler, getChannelId(), getTxId(),
123+
handler.getStateByRange(getChannelId(), getTxId(), startKey, endKey),
117124
queryResultBytesToKv.andThen(KeyValueImpl::new)
118125
);
119126
}
@@ -145,16 +152,16 @@ public CompositeKey splitCompositeKey(String compositeKey) {
145152

146153
@Override
147154
public QueryResultsIterator<KeyValue> getQueryResult(String query) {
148-
return new QueryResultsIteratorImpl<KeyValue>(this.handler, getTxId(),
149-
handler.getQueryResult(getTxId(), query),
155+
return new QueryResultsIteratorImpl<KeyValue>(this.handler, getChannelId(), getTxId(),
156+
handler.getQueryResult(getChannelId(), getTxId(), query),
150157
queryResultBytesToKv.andThen(KeyValueImpl::new)
151158
);
152159
}
153160

154161
@Override
155162
public QueryResultsIterator<KeyModification> getHistoryForKey(String key) {
156-
return new QueryResultsIteratorImpl<KeyModification>(this.handler, getTxId(),
157-
handler.getHistoryForKey(getTxId(), key),
163+
return new QueryResultsIteratorImpl<KeyModification>(this.handler, getChannelId(), getTxId(),
164+
handler.getHistoryForKey(getChannelId(), getTxId(), key),
158165
queryResultBytesToKeyModification.andThen(KeyModificationImpl::new)
159166
);
160167
}
@@ -178,7 +185,7 @@ public Response invokeChaincode(final String chaincodeName, final List<byte[]> a
178185
} else {
179186
compositeName = chaincodeName;
180187
}
181-
return handler.invokeChaincode(this.txId, compositeName, args);
188+
return handler.invokeChaincode(this.channelId, this.txId, compositeName, args);
182189
}
183190

184191
}

0 commit comments

Comments
 (0)