Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to fix #106 #108

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/chaincode/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ func Approve(ctx context.Context, connection grpc.ClientConnInterface, id identi
if err != nil {
return err
}
validationParameter, err := chaincodeDef.getApplicationPolicyBytes()
if err != nil {
return err
}
approveArgs := &lifecycle.ApproveChaincodeDefinitionForMyOrgArgs{
Name: chaincodeDef.Name,
Version: chaincodeDef.Version,
Sequence: chaincodeDef.Sequence,
EndorsementPlugin: chaincodeDef.EndorsementPlugin,
ValidationPlugin: chaincodeDef.ValidationPlugin,
ValidationParameter: chaincodeDef.ValidationParameter,
ValidationParameter: validationParameter,
Collections: chaincodeDef.Collections,
InitRequired: chaincodeDef.InitRequired,
Source: newChaincodeSource(chaincodeDef.PackageID),
Expand Down
6 changes: 5 additions & 1 deletion pkg/chaincode/checkcommitreadiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ import (
// CheckCommitReadiness for a chaincode and return all approval records. The connection may be to any Gateway peer that
// is a member of the channel.
func CheckCommitReadiness(ctx context.Context, connection grpc.ClientConnInterface, id identity.SigningIdentity, chaincodeDef *Definition) (*lifecycle.CheckCommitReadinessResult, error) {
validationParameter, err := chaincodeDef.getApplicationPolicyBytes()
if err != nil {
return nil, err
}
args := &lifecycle.CheckCommitReadinessArgs{
Name: chaincodeDef.Name,
Version: chaincodeDef.Version,
Sequence: chaincodeDef.Sequence,
EndorsementPlugin: chaincodeDef.EndorsementPlugin,
ValidationPlugin: chaincodeDef.ValidationPlugin,
ValidationParameter: chaincodeDef.ValidationParameter,
ValidationParameter: validationParameter,
Collections: chaincodeDef.Collections,
InitRequired: chaincodeDef.InitRequired,
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/chaincode/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ func Commit(ctx context.Context, connection grpc.ClientConnInterface, id identit
if err != nil {
return err
}
validationParameter, err := chaincodeDef.getApplicationPolicyBytes()
if err != nil {
return err
}
commitArgs := &lifecycle.CommitChaincodeDefinitionArgs{
Name: chaincodeDef.Name,
Version: chaincodeDef.Version,
Sequence: chaincodeDef.Sequence,
EndorsementPlugin: chaincodeDef.EndorsementPlugin,
ValidationPlugin: chaincodeDef.ValidationPlugin,
ValidationParameter: chaincodeDef.ValidationParameter,
ValidationParameter: validationParameter,
Collections: chaincodeDef.Collections,
InitRequired: chaincodeDef.InitRequired,
}
Expand Down
19 changes: 16 additions & 3 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 @@ -57,9 +58,9 @@ type Definition struct {
// track of chaincode upgrades.
Sequence int64

// ValidationParameter defines the endorsement policy for the chaincode. This can be an explicit endorsement policy
// string or reference a policy in the channel configuration.
ValidationParameter []byte
// ApplicationPolicy defines the endorsement policy for the chaincode. This can be an explicit endorsement policy
// it follows fabric-protos-go-apiv2/peer format and it will convert to validationParameter during validation phase.
ApplicationPolicy *peer.ApplicationPolicy

// InitRequired is true only if the chaincode defines an Init function using the low-level shim API, which must be
// invoked before other transaction functions may be invoked; otherwise false. It is not recommended to rely on
Expand All @@ -85,3 +86,15 @@ func (d *Definition) validate() error {
}
return nil
}

// getApplicationPolicyBytes is to convert ApplicationPolicy to Bytes for proto usage
func (d *Definition) getApplicationPolicyBytes() ([]byte, error) {
if d.ApplicationPolicy != nil {
AppPolicydata, err := proto.Marshal(d.ApplicationPolicy)
if err != nil {
return nil, err
}
return AppPolicydata, nil
}
return nil, nil
}
Loading