6 Star 46 Fork 28

Hyperledger/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
util.go 2.48 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package policies
import (
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
)
// ConfigPolicy defines a common representation for different *cb.ConfigPolicy values.
type ConfigPolicy interface {
// Key is the key this value should be stored in the *cb.ConfigGroup.Policies map.
Key() string
// Value is the backing policy implementation for this ConfigPolicy
Value() *cb.Policy
}
// StandardConfigValue implements the ConfigValue interface.
type StandardConfigPolicy struct {
key string
value *cb.Policy
}
// Key is the key this value should be stored in the *cb.ConfigGroup.Values map.
func (scv *StandardConfigPolicy) Key() string {
return scv.key
}
// Value is the *cb.Policy which should be stored as the *cb.ConfigPolicy.Policy.
func (scv *StandardConfigPolicy) Value() *cb.Policy {
return scv.value
}
func makeImplicitMetaPolicy(subPolicyName string, rule cb.ImplicitMetaPolicy_Rule) *cb.Policy {
return &cb.Policy{
Type: int32(cb.Policy_IMPLICIT_META),
Value: utils.MarshalOrPanic(&cb.ImplicitMetaPolicy{
Rule: rule,
SubPolicy: subPolicyName,
}),
}
}
// ImplicitMetaAllPolicy defines an implicit meta policy whose sub_policy and key is policyname with rule ALL.
func ImplicitMetaAllPolicy(policyName string) *StandardConfigPolicy {
return &StandardConfigPolicy{
key: policyName,
value: makeImplicitMetaPolicy(policyName, cb.ImplicitMetaPolicy_ALL),
}
}
// ImplicitMetaAnyPolicy defines an implicit meta policy whose sub_policy and key is policyname with rule ANY.
func ImplicitMetaAnyPolicy(policyName string) *StandardConfigPolicy {
return &StandardConfigPolicy{
key: policyName,
value: makeImplicitMetaPolicy(policyName, cb.ImplicitMetaPolicy_ANY),
}
}
// ImplicitMetaMajorityPolicy defines an implicit meta policy whose sub_policy and key is policyname with rule MAJORITY.
func ImplicitMetaMajorityPolicy(policyName string) *StandardConfigPolicy {
return &StandardConfigPolicy{
key: policyName,
value: makeImplicitMetaPolicy(policyName, cb.ImplicitMetaPolicy_MAJORITY),
}
}
// ImplicitMetaMajorityPolicy defines a policy with key policyName and the given signature policy.
func SignaturePolicy(policyName string, sigPolicy *cb.SignaturePolicyEnvelope) *StandardConfigPolicy {
return &StandardConfigPolicy{
key: policyName,
value: &cb.Policy{
Type: int32(cb.Policy_SIGNATURE),
Value: utils.MarshalOrPanic(sigPolicy),
},
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hyperledger/fabric.git
git@gitee.com:hyperledger/fabric.git
hyperledger
fabric
fabric
v1.1.1

搜索帮助