1 Star 0 Fork 0

妥協/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
v13.go 2.41 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package statebased
import (
commonerrors "github.com/hyperledger/fabric/common/errors"
validation "github.com/hyperledger/fabric/core/handlers/validation/api/policies"
"github.com/hyperledger/fabric/protoutil"
"github.com/pkg/errors"
)
// NewV13Evaluator returns a policy evaluator that checks
// 2 kinds of policies:
// 1) chaincode endorsement policies;
// 2) state-based endorsement policies.
func NewV13Evaluator(policySupport validation.PolicyEvaluator, vpmgr KeyLevelValidationParameterManager) *policyCheckerFactoryV13 {
return &policyCheckerFactoryV13{
policySupport: policySupport,
vpmgr: vpmgr,
}
}
type policyCheckerFactoryV13 struct {
vpmgr KeyLevelValidationParameterManager
policySupport validation.PolicyEvaluator
}
func (p *policyCheckerFactoryV13) Evaluator(ccEP []byte) RWSetPolicyEvaluator {
return &baseEvaluator{
epEvaluator: &policyCheckerV13{
policySupport: p.policySupport,
ccEP: ccEP,
},
vpmgr: p.vpmgr,
policySupport: p.policySupport,
}
}
/**********************************************************************************************************/
/**********************************************************************************************************/
type policyCheckerV13 struct {
someEPChecked bool
ccEPChecked bool
policySupport validation.PolicyEvaluator
ccEP []byte
}
func (p *policyCheckerV13) checkCCEPIfCondition(cc string, blockNum, txNum uint64, condition bool, sd []*protoutil.SignedData) commonerrors.TxValidationError {
if condition {
return nil
}
// validate against cc ep
err := p.policySupport.Evaluate(p.ccEP, sd)
if err != nil {
return policyErr(errors.Wrapf(err, "validation of endorsement policy for chaincode %s in tx %d:%d failed", cc, blockNum, txNum))
}
p.ccEPChecked = true
p.someEPChecked = true
return nil
}
func (p *policyCheckerV13) CheckCCEPIfNotChecked(cc, coll string, blockNum, txNum uint64, sd []*protoutil.SignedData) commonerrors.TxValidationError {
return p.checkCCEPIfCondition(cc, blockNum, txNum, p.ccEPChecked, sd)
}
func (p *policyCheckerV13) CheckCCEPIfNoEPChecked(cc string, blockNum, txNum uint64, sd []*protoutil.SignedData) commonerrors.TxValidationError {
return p.checkCCEPIfCondition(cc, blockNum, txNum, p.someEPChecked, sd)
}
func (p *policyCheckerV13) SBEPChecked() {
p.someEPChecked = true
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liurenhao/fabric.git
git@gitee.com:liurenhao/fabric.git
liurenhao
fabric
fabric
v2.1.1

搜索帮助