Skip to content

Commit

Permalink
try to fix #106
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Yuan <[email protected]>
  • Loading branch information
SamYuan1990 committed Mar 11, 2023
1 parent d97cfb6 commit 61f2356
Show file tree
Hide file tree
Showing 3 changed files with 413 additions and 14 deletions.
38 changes: 38 additions & 0 deletions pkg/chaincode/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"

"github.com/hyperledger/fabric-protos-go-apiv2/peer"
"google.golang.org/protobuf/proto"
)

const (
Expand Down Expand Up @@ -85,3 +86,40 @@ func (d *Definition) validate() error {
}
return nil
}

func CreateChaincodeDefinition(channelName, packageID, name, version, endorsementPlugin, validationPlugin, signaturePolicy, channelConfigPolicy string, seq int64, initflag bool, pollections *peer.CollectionConfigPackage) (*Definition, error) {
signaturePolicyEnvelope, err := FromString(signaturePolicy)
if err != nil {
return nil, err
}
applicationPolicy := &peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_SignaturePolicy{
SignaturePolicy: signaturePolicyEnvelope,
},
}
if channelConfigPolicy != "" {
applicationPolicy = &peer.ApplicationPolicy{
Type: &peer.ApplicationPolicy_ChannelConfigPolicyReference{
ChannelConfigPolicyReference: channelConfigPolicy,
},
}
}
data, err := proto.Marshal(applicationPolicy)
if err != nil {
return nil, err
}

chaincodeDef := &Definition{
ChannelName: channelName,
PackageID: packageID,
Name: name,
Version: version,
EndorsementPlugin: endorsementPlugin,
ValidationPlugin: validationPlugin,
Sequence: seq,
ValidationParameter: data,
InitRequired: initflag,
Collections: pollections,
}
return chaincodeDef, nil
}
Loading

0 comments on commit 61f2356

Please sign in to comment.