Skip to content

Commit 35eabb0

Browse files
committed
PurgePrivateData
Signed-off-by: fraVlaca <[email protected]>
1 parent add296a commit 35eabb0

File tree

8 files changed

+84
-2
lines changed

8 files changed

+84
-2
lines changed

fabric-chaincode-integration-test/src/test/java/org/hyperleder/fabric/shim/integration/contractinstall/ContractInstallTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
SPDX-License-Identifier: Apache-2.0
55
*/
6-
package org.hyperleder.fabric.shim.integration.ledgertests;
6+
package org.hyperleder.fabric.shim.integration.contractinstall;
77
import static org.hamcrest.core.StringContains.containsString;
88
import static org.junit.Assert.assertThat;
99

fabric-chaincode-shim/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
mavenCentral()
99
}
1010
dependencies {
11-
classpath 'org.owasp:dependency-check-gradle:5.3.2'
11+
classpath 'org.owasp:dependency-check-gradle:7.1.0.1'
1212
}
1313
}
1414

@@ -71,6 +71,9 @@ dependencyCheck {
7171
format='ALL'
7272
analyzers {
7373
assemblyEnabled=false
74+
ossIndex {
75+
enabled=false
76+
}
7477
}
7578
}
7679

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,25 @@ public interface ChaincodeStub {
452452
*/
453453
void delPrivateData(String collection, String key);
454454

455+
/**
456+
* Reqauests purging of the specified <code>key</code> to be from
457+
* the private data stores.
458+
* <p>
459+
* Note that only hash of the private writeset goes into the transaction
460+
* proposal response (which is sent to the client who issued the transaction)
461+
* and the actual private writeset gets temporarily stored in a transient store.
462+
* The <code>key</code> and its value will be purged from the collection. This is an
463+
* asynchronous activity.
464+
* <p>
465+
* Purge is a complete removal of the history of the key. There is existing purge
466+
* possible mased on block height. This API allows the contract to be pro-active in
467+
* requesting data be purged. This can contribute towards meeting privacy requirements.
468+
*
469+
* @param collection name of the collection
470+
* @param key name of the value to be deleted
471+
*/
472+
void purgePrivateData(String collection, String key);
473+
455474
/**
456475
* Returns all existing keys, and their values, that are lexicographically
457476
* between <code>startkey</code> (inclusive) and the <code>endKey</code>

fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl/ChaincodeMessageFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ protected static ChaincodeMessage newDeleteStateEventMessage(final String channe
6767
return newEventMessage(DEL_STATE, channelId, txId, DelState.newBuilder().setCollection(collection).setKey(key).build().toByteString());
6868
}
6969

70+
protected static ChaincodeMessage newPurgeStateEventMessage(final String channelId, final String txId, final String collection, final String key) {
71+
return newEventMessage(Type.PURGE_PRIVATE_DATA, channelId, txId, DelState.newBuilder().setCollection(collection).setKey(key).build().toByteString());
72+
}
73+
7074
protected static ChaincodeMessage newErrorEventMessage(final String channelId, final String txId, final Throwable throwable) {
7175
return newErrorEventMessage(channelId, txId, printStackTrace(throwable));
7276
}

fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl/InvocationStubImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,14 @@ public void delPrivateData(final String collection, final String key) {
511511
this.handler.invoke(msg);
512512
}
513513

514+
@Override
515+
public void purgePrivateData(final String collection, final String key) {
516+
validateCollection(collection);
517+
final ChaincodeMessage msg = ChaincodeMessageFactory.newPurgeStateEventMessage(channelId, txId, collection,
518+
key);
519+
this.handler.invoke(msg);
520+
}
521+
514522
@Override
515523
public QueryResultsIterator<KeyValue> getPrivateDataByRange(final String collection, final String startKey,
516524
final String endKey) {

fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/contract/ChaincodeStubNaiveImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ public void delPrivateData(final String collection, final String key) {
210210

211211
}
212212

213+
@Override
214+
public void purgePrivateData(final String collection, final String key) {
215+
216+
}
217+
213218
@Override
214219
public QueryResultsIterator<KeyValue> getPrivateDataByRange(final String collection, final String startKey, final String endKey) {
215220
return null;

fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/shim/ChaincodeStubTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ public void delPrivateData(final String collection, final String key) {
198198

199199
}
200200

201+
@Override
202+
public void purgePrivateData(final String collection, final String key) {
203+
// TODO Auto-generated method stub
204+
205+
}
206+
201207
@Override
202208
public QueryResultsIterator<KeyValue> getPrivateDataByRange(final String collection, final String startKey, final String endKey) {
203209
// TODO Auto-generated method stub
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2019 IBM All Rights Reserved.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
package org.hyperledger.fabric.shim.mock.peer;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
import org.hyperledger.fabric.protos.peer.ChaincodeMessage;
12+
13+
/**
14+
* Simulates purgePrivateData() invocation in chaincode Waits for PURGE_PRIVATE_DATA message from
15+
* chaincode and sends back response with empty payload
16+
*/
17+
public final class PurgeValueStep implements ScenarioStep {
18+
19+
private ChaincodeMessage orgMsg;
20+
21+
@Override
22+
public boolean expected(final ChaincodeMessage msg) {
23+
orgMsg = msg;
24+
return msg.getType() == ChaincodeMessage.Type.PURGE_PRIVATE_DATA;
25+
}
26+
27+
@Override
28+
public List<ChaincodeMessage> next() {
29+
final List<ChaincodeMessage> list = new ArrayList<>();
30+
list.add(ChaincodeMessage.newBuilder()
31+
.setType(ChaincodeMessage.Type.RESPONSE)
32+
.setChannelId(orgMsg.getChannelId())
33+
.setTxid(orgMsg.getTxid())
34+
.build());
35+
return list;
36+
}
37+
}

0 commit comments

Comments
 (0)