Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I have a private data collection with only two organizations (lets say Org1 and Org2) in its policy defined in the collections_config.json file.

The transaction function is written in a way that it will send out both the public and the associated private data based on which Org the calling peer belongs to. I am using a simple try/catch block to catch an exception while retrieving private data to decide whether to include or exclude the private data.

try {
    byte[] privateData = context.getStub().getPrivateData(collectionName, key);
    // format and include in the response
} catch (Exception e) {
    // failed, possibly not authorized to access private data
    // don't include in the response
}

This works fine, as an attempt to access private data by any other member of an organization (say Org3) which is not part of the collection configuration, will throw an exception. However, it always throws a RuntimeException - makes it impossible to differentiate whether it is really an endorsement error or or something else went wrong with the chaincode invocation.

My question: Is there a "cleaner" way other than a try/catch using which I can assert if the invoking peer can access the private data collection?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.