Skip to content

Commit

Permalink
Merge "[FAB-6848] add channel ID to chaincode message"
Browse files Browse the repository at this point in the history
  • Loading branch information
jimthematrix authored and Gerrit Code Review committed Nov 14, 2017
2 parents 6778439 + 53e49bc commit decb95f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public interface ChaincodeStub {
*/
String getTxId();

/**
* Returns the channel id
*
* @return the channel id
*/
String getChannelId();

/**
* Invoke another chaincode using the same transaction context.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@

class ChaincodeStubImpl implements ChaincodeStub {

private final String channelId;
private final String txId;
private final Handler handler;
private final List<ByteString> args;
private ChaincodeEvent event;

ChaincodeStubImpl(String txId, Handler handler, List<ByteString> args) {
ChaincodeStubImpl(String channelId, String txId, Handler handler, List<ByteString> args) {
this.channelId = channelId;
this.txId = txId;
this.handler = handler;
this.args = Collections.unmodifiableList(args);
Expand Down Expand Up @@ -90,30 +92,35 @@ public ChaincodeEvent getEvent() {
return event;
}

@Override
public String getChannelId() {
return channelId;
}

@Override
public String getTxId() {
return txId;
}

@Override
public byte[] getState(String key) {
return handler.getState(txId, key).toByteArray();
return handler.getState(channelId, txId, key).toByteArray();
}

@Override
public void putState(String key, byte[] value) {
handler.putState(txId, key, ByteString.copyFrom(value));
handler.putState(channelId, txId, key, ByteString.copyFrom(value));
}

@Override
public void delState(String key) {
handler.deleteState(txId, key);
handler.deleteState(channelId, txId, key);
}

@Override
public QueryResultsIterator<KeyValue> getStateByRange(String startKey, String endKey) {
return new QueryResultsIteratorImpl<KeyValue>(this.handler, getTxId(),
handler.getStateByRange(getTxId(), startKey, endKey),
return new QueryResultsIteratorImpl<KeyValue>(this.handler, getChannelId(), getTxId(),
handler.getStateByRange(getChannelId(), getTxId(), startKey, endKey),
queryResultBytesToKv.andThen(KeyValueImpl::new)
);
}
Expand Down Expand Up @@ -145,16 +152,16 @@ public CompositeKey splitCompositeKey(String compositeKey) {

@Override
public QueryResultsIterator<KeyValue> getQueryResult(String query) {
return new QueryResultsIteratorImpl<KeyValue>(this.handler, getTxId(),
handler.getQueryResult(getTxId(), query),
return new QueryResultsIteratorImpl<KeyValue>(this.handler, getChannelId(), getTxId(),
handler.getQueryResult(getChannelId(), getTxId(), query),
queryResultBytesToKv.andThen(KeyValueImpl::new)
);
}

@Override
public QueryResultsIterator<KeyModification> getHistoryForKey(String key) {
return new QueryResultsIteratorImpl<KeyModification>(this.handler, getTxId(),
handler.getHistoryForKey(getTxId(), key),
return new QueryResultsIteratorImpl<KeyModification>(this.handler, getChannelId(), getTxId(),
handler.getHistoryForKey(getChannelId(), getTxId(), key),
queryResultBytesToKeyModification.andThen(KeyModificationImpl::new)
);
}
Expand All @@ -178,7 +185,7 @@ public Response invokeChaincode(final String chaincodeName, final List<byte[]> a
} else {
compositeName = chaincodeName;
}
return handler.invokeChaincode(this.txId, compositeName, args);
return handler.invokeChaincode(this.channelId, this.txId, compositeName, args);
}

}
Loading

0 comments on commit decb95f

Please sign in to comment.