1 Star 0 Fork 0

13683679291/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
metadata.go 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package chaincode
import (
"sync"
"github.com/hyperledger/fabric/protos/gossip"
)
// InstalledChaincode defines metadata about an installed chaincode
type InstalledChaincode struct {
Name string
Version string
Id []byte
}
// Metadata defines channel-scoped metadata of a chaincode
type Metadata struct {
Name string
Version string
Policy []byte
Id []byte
CollectionsConfig []byte
}
// MetadataSet defines an aggregation of Metadata
type MetadataSet []Metadata
// AsChaincodes converts this MetadataSet to a slice of gossip.Chaincodes
func (ccs MetadataSet) AsChaincodes() []*gossip.Chaincode {
var res []*gossip.Chaincode
for _, cc := range ccs {
res = append(res, &gossip.Chaincode{
Name: cc.Name,
Version: cc.Version,
})
}
return res
}
// MetadataMapping defines a mapping from chaincode name to Metadata
type MetadataMapping struct {
sync.RWMutex
mdByName map[string]Metadata
}
// NewMetadataMapping creates a new metadata mapping
func NewMetadataMapping() *MetadataMapping {
return &MetadataMapping{
mdByName: make(map[string]Metadata),
}
}
// Lookup returns the Metadata that is associated with the given chaincode
func (m *MetadataMapping) Lookup(cc string) (Metadata, bool) {
m.RLock()
defer m.RUnlock()
md, exists := m.mdByName[cc]
return md, exists
}
// Update updates the chaincode metadata in the mapping
func (m *MetadataMapping) Update(ccMd Metadata) {
m.Lock()
defer m.Unlock()
m.mdByName[ccMd.Name] = ccMd
}
// Aggregate aggregates all Metadata to a MetadataSet
func (m *MetadataMapping) Aggregate() MetadataSet {
m.RLock()
defer m.RUnlock()
var set MetadataSet
for _, md := range m.mdByName {
set = append(set, md)
}
return set
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mmcro/fabric.git
git@gitee.com:mmcro/fabric.git
mmcro
fabric
fabric
v1.4.1-rc1

搜索帮助