-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from hyperledger-labs/feature/collection-gener…
…ation Automatic collection generation
- Loading branch information
Showing
13 changed files
with
199 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
) | ||
|
||
type ArrayFlags []string | ||
|
||
func (i *ArrayFlags) String() string { | ||
return "my string representation" | ||
} | ||
|
||
func (i *ArrayFlags) Set(value string) error { | ||
*i = append(*i, value) | ||
return nil | ||
} | ||
|
||
type CollectionElem struct { | ||
Name string `json:"name"` | ||
RequiredPeerCount int `json:"requiredPeerCount"` | ||
MaxPeerCount int `json:"maxPeerCount"` | ||
BlockToLive int `json:"blockToLive"` | ||
MemberOnlyRead bool `json:"memberOnlyRead"` | ||
Policy string `json:"policy"` | ||
} | ||
|
||
func generateCollection(orgs ArrayFlags) { | ||
collection := []CollectionElem{} | ||
|
||
for _, a := range assetTypeList { | ||
if len(a.Readers) > 0 { | ||
elem := CollectionElem{ | ||
Name: a.Tag, | ||
RequiredPeerCount: 0, | ||
MaxPeerCount: 3, | ||
BlockToLive: 1000000, | ||
MemberOnlyRead: true, | ||
Policy: generatePolicy(a.Readers, orgs), | ||
} | ||
collection = append(collection, elem) | ||
} | ||
} | ||
|
||
b, err := json.MarshalIndent(collection, "", " ") | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
err = ioutil.WriteFile("collections.json", b, 0644) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
|
||
func generatePolicy(readers []string, orgs ArrayFlags) string { | ||
firstElem := true | ||
policy := "OR(" | ||
for _, r := range readers { | ||
if len(orgs) > 0 { | ||
found := false | ||
for _, o := range orgs { | ||
if r == o { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
continue | ||
} | ||
} | ||
if !firstElem { | ||
policy += ", " | ||
} | ||
policy += fmt.Sprintf("'%s.member'", r) | ||
firstElem = false | ||
} | ||
policy += ")" | ||
return policy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/bash | ||
|
||
while getopts "o:h" opt; do | ||
case $opt in | ||
o) orgs+=("$OPTARG");; | ||
#... | ||
h) | ||
echo "Usage: ./generateCollection.sh [-o <org name>]" | ||
echo " -o: Include an organization in the collection configuration file" | ||
echo " This option can be used multiple times to include multiple organizations" | ||
echo " If no organizations are specified, the default is to include any organization found in the readers" | ||
echo "" | ||
echo "Example: ./generateCollection.sh -o org1MSP -o org2MSP -o org3MSP" | ||
exit 0 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND -1)) | ||
|
||
if [ ${#orgs[@]} -gt 0 ] | ||
then | ||
cd ./chaincode; go run . -g --orgs ${orgs[@]}; cd .. | ||
else | ||
cd ./chaincode; go run . -g; cd .. | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.