-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
70 lines (61 loc) · 1.68 KB
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Copyright IBM Corp. 2018 All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package endorser
import (
"github.com/hyperledger/fabric/core/handlers/endorsement/api/state"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/transientstore"
"github.com/hyperledger/fabric/protos/ledger/rwset"
"github.com/pkg/errors"
)
//go:generate mockery -dir . -name QueryCreator -case underscore -output mocks/
// QueryCreator creates new QueryExecutors
type QueryCreator interface {
NewQueryExecutor() (ledger.QueryExecutor, error)
}
// ChannelState defines state operations
type ChannelState struct {
transientstore.Store
QueryCreator
}
// FetchState fetches state
func (cs *ChannelState) FetchState() (endorsement.State, error) {
qe, err := cs.NewQueryExecutor()
if err != nil {
return nil, err
}
return &StateContext{
QueryExecutor: qe,
Store: cs.Store,
}, nil
}
// StateContext defines an execution context that interacts with the state
type StateContext struct {
transientstore.Store
ledger.QueryExecutor
}
// GetTransientByTXID returns the private data associated with this transaction ID.
func (sc *StateContext) GetTransientByTXID(txID string) ([]*rwset.TxPvtReadWriteSet, error) {
scanner, err := sc.Store.GetTxPvtRWSetByTxid(txID, nil)
if err != nil {
return nil, errors.WithStack(err)
}
defer scanner.Close()
var data []*rwset.TxPvtReadWriteSet
for {
res, err := scanner.NextWithConfig()
if err != nil {
return nil, errors.WithStack(err)
}
if res == nil {
break
}
if res.PvtSimulationResultsWithConfig == nil {
continue
}
data = append(data, res.PvtSimulationResultsWithConfig.PvtRwset)
}
return data, nil
}