3 Star 6 Fork 7

Gitee 极速下载 / Hyperledger fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
transaction_context.go 3.24 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package chaincode
import (
"sync"
commonledger "github.com/hyperledger/fabric/common/ledger"
"github.com/hyperledger/fabric/core/common/privdata"
"github.com/hyperledger/fabric/core/ledger"
pb "github.com/hyperledger/fabric/protos/peer"
)
type TransactionContext struct {
ChainID string
SignedProp *pb.SignedProposal
Proposal *pb.Proposal
ResponseNotifier chan *pb.ChaincodeMessage
TXSimulator ledger.TxSimulator
HistoryQueryExecutor ledger.HistoryQueryExecutor
CollectionStore privdata.CollectionStore
IsInitTransaction bool
// tracks open iterators used for range queries
queryMutex sync.Mutex
queryIteratorMap map[string]commonledger.ResultsIterator
pendingQueryResults map[string]*PendingQueryResult
totalReturnCount map[string]*int32
// cache used to save the result of collection acl
// as a transactionContext is created for every chaincode
// invoke (even in case of chaincode-calling-chaincode,
// we do not need to store the namespace in the map and
// collection alone is sufficient.
AllowedCollectionAccess map[string]bool
}
func (t *TransactionContext) InitializeQueryContext(queryID string, iter commonledger.ResultsIterator) {
t.queryMutex.Lock()
if t.queryIteratorMap == nil {
t.queryIteratorMap = map[string]commonledger.ResultsIterator{}
}
if t.pendingQueryResults == nil {
t.pendingQueryResults = map[string]*PendingQueryResult{}
}
if t.totalReturnCount == nil {
t.totalReturnCount = map[string]*int32{}
}
t.queryIteratorMap[queryID] = iter
t.pendingQueryResults[queryID] = &PendingQueryResult{}
zeroValue := int32(0)
t.totalReturnCount[queryID] = &zeroValue
t.queryMutex.Unlock()
}
func (t *TransactionContext) GetQueryIterator(queryID string) commonledger.ResultsIterator {
t.queryMutex.Lock()
iter := t.queryIteratorMap[queryID]
t.queryMutex.Unlock()
return iter
}
func (t *TransactionContext) GetPendingQueryResult(queryID string) *PendingQueryResult {
t.queryMutex.Lock()
result := t.pendingQueryResults[queryID]
t.queryMutex.Unlock()
return result
}
func (t *TransactionContext) GetTotalReturnCount(queryID string) *int32 {
t.queryMutex.Lock()
result := t.totalReturnCount[queryID]
t.queryMutex.Unlock()
return result
}
func (t *TransactionContext) CleanupQueryContext(queryID string) {
t.queryMutex.Lock()
defer t.queryMutex.Unlock()
iter := t.queryIteratorMap[queryID]
if iter != nil {
iter.Close()
}
delete(t.queryIteratorMap, queryID)
delete(t.pendingQueryResults, queryID)
delete(t.totalReturnCount, queryID)
}
func (t *TransactionContext) CleanupQueryContextWithBookmark(queryID string) string {
t.queryMutex.Lock()
defer t.queryMutex.Unlock()
iter := t.queryIteratorMap[queryID]
bookmark := ""
if iter != nil {
if queryResultIterator, ok := iter.(commonledger.QueryResultsIterator); ok {
bookmark = queryResultIterator.GetBookmarkAndClose()
}
}
delete(t.queryIteratorMap, queryID)
delete(t.pendingQueryResults, queryID)
delete(t.totalReturnCount, queryID)
return bookmark
}
func (t *TransactionContext) CloseQueryIterators() {
t.queryMutex.Lock()
defer t.queryMutex.Unlock()
for _, iter := range t.queryIteratorMap {
iter.Close()
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/fabric.git
git@gitee.com:mirrors/fabric.git
mirrors
fabric
Hyperledger fabric
v1.4.4

搜索帮助

344bd9b3 5694891 D2dac590 5694891