@@ -26,6 +26,8 @@ import (
26
26
"github.com/hyperledger/fabric/core/chaincode/shim"
27
27
"github.com/hyperledger/fabric/core/common/ccprovider"
28
28
"github.com/hyperledger/fabric/core/common/sysccprovider"
29
+ "github.com/hyperledger/fabric/core/peer"
30
+ "github.com/hyperledger/fabric/protos/common"
29
31
pb "github.com/hyperledger/fabric/protos/peer"
30
32
"github.com/hyperledger/fabric/protos/utils"
31
33
"github.com/op/go-logging"
@@ -469,6 +471,33 @@ func (lccc *LifeCycleSysCC) Init(stub shim.ChaincodeStubInterface) pb.Response {
469
471
return shim .Success (nil )
470
472
}
471
473
474
+ // getDefaultEndorsementPolicy returns the default
475
+ // endorsement policy for the specified chain; it
476
+ // is used in case the deployer has not specified a
477
+ // custom one
478
+ func (lccc * LifeCycleSysCC ) getDefaultEndorsementPolicy (chain string ) []byte {
479
+ // we create an array of principals, one principal
480
+ // per application MSP defined on this chain
481
+ ids := peer .GetMSPIDs (chain )
482
+ principals := make ([]* common.MSPPrincipal , len (ids ))
483
+ sigspolicy := make ([]* common.SignaturePolicy , len (ids ))
484
+ for i , id := range ids {
485
+ principals [i ] = & common.MSPPrincipal {
486
+ PrincipalClassification : common .MSPPrincipal_ROLE ,
487
+ Principal : utils .MarshalOrPanic (& common.MSPRole {Role : common .MSPRole_MEMBER , MspIdentifier : id })}
488
+ sigspolicy [i ] = cauthdsl .SignedBy (int32 (i ))
489
+ }
490
+
491
+ // create the policy: it requires exactly 1 signature from any of the principals
492
+ p := & common.SignaturePolicyEnvelope {
493
+ Version : 0 ,
494
+ Policy : cauthdsl .NOutOf (1 , sigspolicy ),
495
+ Identities : principals ,
496
+ }
497
+
498
+ return utils .MarshalOrPanic (p )
499
+ }
500
+
472
501
// Invoke implements lifecycle functions "deploy", "start", "stop", "upgrade".
473
502
// Deploy's arguments - {[]byte("deploy"), []byte(<chainname>), <unmarshalled pb.ChaincodeDeploymentSpec>}
474
503
//
@@ -515,11 +544,10 @@ func (lccc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response
515
544
// args[4] is the name of escc
516
545
// args[5] is the name of vscc
517
546
var policy []byte
518
- if len (args ) > 3 && args [3 ] != nil {
547
+ if len (args ) > 3 && len ( args [3 ]) > 0 {
519
548
policy = args [3 ]
520
549
} else {
521
- // FIXME: temporary workaround until all SDKs provide a policy
522
- policy = utils .MarshalOrPanic (cauthdsl .SignedByMspMember ("DEFAULT" ))
550
+ policy = lccc .getDefaultEndorsementPolicy (chainname )
523
551
}
524
552
525
553
var escc []byte
@@ -558,11 +586,10 @@ func (lccc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response
558
586
// args[4] is the name of escc
559
587
// args[5] is the name of vscc
560
588
var policy []byte
561
- if len (args ) > 3 && args [3 ] != nil {
589
+ if len (args ) > 3 && len ( args [3 ]) > 0 {
562
590
policy = args [3 ]
563
591
} else {
564
- // FIXME: temporary workaround until all SDKs provide a policy
565
- policy = utils .MarshalOrPanic (cauthdsl .SignedByMspMember ("DEFAULT" ))
592
+ policy = lccc .getDefaultEndorsementPolicy (chainname )
566
593
}
567
594
568
595
var escc []byte
0 commit comments