Skip to content

Add ParseCollectionConfig helper to build CollectionConfigPackage from a JSON string - #252

Open
Ishaan-Gpt wants to merge 1 commit into
hyperledger:mainfrom
Ishaan-Gpt:collection-config-from-string
Open

Ishaan-Gpt wants to merge 1 commit into
hyperledger:mainfrom
Ishaan-Gpt:collection-config-from-string

Conversation

@Ishaan-Gpt

Copy link
Copy Markdown

Defining private data collections with the SDK currently requires building peer.CollectionConfigPackage by hand, which is cumbersome and error prone. This adds a ParseCollectionConfig function in pkg/chaincode that takes a collection configuration string in the same JSON format as the Fabric peer CLI collections configuration file, and converts it into a peer.CollectionConfigPackage ready for ChaincodeDefinition.Collections.

Member orgs policies reuse the existing signature policy parsing, so policy strings like OR('Org1MSP.member', 'Org2MSP.member') work as expected. Required and max peer counts default to 0 and 1 when omitted, matching the Fabric peer CLI behavior. An optional endorsement policy can be given as a signature policy string or a channel config policy reference.

Tests: new unit tests in pkg/chaincode/collectionconfig_test.go cover a full config, multiple collections, peer count defaults, an endorsement policy, invalid JSON, and an invalid policy. go build, go vet and go test on the chaincode package all pass locally.

Fixes #199.

Defining private data collections currently requires building the
peer.CollectionConfigPackage structure by hand, which is cumbersome and
error prone. This adds a ParseCollectionConfig function in pkg/chaincode
that accepts a collection configuration string in the same JSON format as
the Fabric peer CLI collections configuration file and converts it into
a peer.CollectionConfigPackage ready for ChaincodeDefinition.Collections.

Member orgs policies reuse the existing signature policy parsing, and the
required and maximum peer counts fall back to 0 and 1 when omitted, the
same defaults the Fabric peer CLI uses. An optional endorsement policy can
be given as a signature policy string or a channel config policy reference.

Signed-off-by: Ishaan-Gpt <ishaangupta011205@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request for High-Level API Function to Convert CollectionConfig String

1 participant