forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
events.go
executable file
·172 lines (147 loc) · 5.09 KB
/
events.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package dispatcher
import (
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
cb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)
// Event is an event that's sent to the dispatcher. This includes client registration
// requests or events that come from an event producer.
type Event interface{}
// RegisterEvent is the base for all registration events.
type RegisterEvent struct {
RegCh chan<- fab.Registration
ErrCh chan<- error
}
// StopEvent tells the dispatcher to stop processing
type StopEvent struct {
ErrCh chan<- error
}
// RegisterBlockEvent registers for block events
type RegisterBlockEvent struct {
RegisterEvent
Reg *BlockReg
}
// RegisterFilteredBlockEvent registers for filtered block events
type RegisterFilteredBlockEvent struct {
RegisterEvent
Reg *FilteredBlockReg
}
// RegisterChaincodeEvent registers for chaincode events
type RegisterChaincodeEvent struct {
RegisterEvent
Reg *ChaincodeReg
}
// RegisterTxStatusEvent registers for transaction status events
type RegisterTxStatusEvent struct {
RegisterEvent
Reg *TxStatusReg
}
// UnregisterEvent unregisters a registration
type UnregisterEvent struct {
Reg fab.Registration
}
// RegistrationInfo contains a snapshot of the current event registrations
type RegistrationInfo struct {
TotalRegistrations int
NumBlockRegistrations int
NumFilteredBlockRegistrations int
NumCCRegistrations int
NumTxStatusRegistrations int
}
// RegistrationInfoEvent requests registration information
type RegistrationInfoEvent struct {
RegInfoCh chan<- *RegistrationInfo
}
// NewRegisterBlockEvent creates a new RegisterBlockEvent
func NewRegisterBlockEvent(filter fab.BlockFilter, eventch chan<- *fab.BlockEvent, respch chan<- fab.Registration, errCh chan<- error) *RegisterBlockEvent {
return &RegisterBlockEvent{
Reg: &BlockReg{Filter: filter, Eventch: eventch},
RegisterEvent: NewRegisterEvent(respch, errCh),
}
}
// NewRegisterFilteredBlockEvent creates a new RegisterFilterBlockEvent
func NewRegisterFilteredBlockEvent(eventch chan<- *fab.FilteredBlockEvent, respch chan<- fab.Registration, errCh chan<- error) *RegisterFilteredBlockEvent {
return &RegisterFilteredBlockEvent{
Reg: &FilteredBlockReg{Eventch: eventch},
RegisterEvent: NewRegisterEvent(respch, errCh),
}
}
// NewUnregisterEvent creates a new UnregisterEvent
func NewUnregisterEvent(reg fab.Registration) *UnregisterEvent {
return &UnregisterEvent{
Reg: reg,
}
}
// NewRegisterChaincodeEvent creates a new RegisterChaincodeEvent
func NewRegisterChaincodeEvent(ccID, eventFilter string, eventch chan<- *fab.CCEvent, respch chan<- fab.Registration, errCh chan<- error) *RegisterChaincodeEvent {
return &RegisterChaincodeEvent{
Reg: &ChaincodeReg{
ChaincodeID: ccID,
EventFilter: eventFilter,
Eventch: eventch,
},
RegisterEvent: NewRegisterEvent(respch, errCh),
}
}
// NewRegisterTxStatusEvent creates a new RegisterTxStatusEvent
func NewRegisterTxStatusEvent(txID string, eventch chan<- *fab.TxStatusEvent, respch chan<- fab.Registration, errCh chan<- error) *RegisterTxStatusEvent {
return &RegisterTxStatusEvent{
Reg: &TxStatusReg{TxID: txID, Eventch: eventch},
RegisterEvent: NewRegisterEvent(respch, errCh),
}
}
// NewRegisterEvent creates a new RgisterEvent
func NewRegisterEvent(respch chan<- fab.Registration, errCh chan<- error) RegisterEvent {
return RegisterEvent{
RegCh: respch,
ErrCh: errCh,
}
}
// NewBlockEvent creates a new BlockEvent
func NewBlockEvent(block *cb.Block, sourceURL string) *fab.BlockEvent {
return &fab.BlockEvent{
Block: block,
SourceURL: sourceURL,
}
}
// NewFilteredBlockEvent creates a new FilteredBlockEvent
func NewFilteredBlockEvent(fblock *pb.FilteredBlock, sourceURL string) *fab.FilteredBlockEvent {
return &fab.FilteredBlockEvent{
FilteredBlock: fblock,
SourceURL: sourceURL,
}
}
// NewChaincodeEvent creates a new ChaincodeEvent
func NewChaincodeEvent(chaincodeID, eventName, txID string, payload []byte, blockNum uint64, sourceURL string) *fab.CCEvent {
return &fab.CCEvent{
ChaincodeID: chaincodeID,
EventName: eventName,
TxID: txID,
Payload: payload,
BlockNumber: blockNum,
SourceURL: sourceURL,
}
}
// NewTxStatusEvent creates a new TxStatusEvent
func NewTxStatusEvent(txID string, txValidationCode pb.TxValidationCode, blockNum uint64, sourceURL string) *fab.TxStatusEvent {
return &fab.TxStatusEvent{
TxID: txID,
TxValidationCode: txValidationCode,
BlockNumber: blockNum,
SourceURL: sourceURL,
}
}
// NewStopEvent creates a new StopEvent
func NewStopEvent(errch chan<- error) *StopEvent {
return &StopEvent{
ErrCh: errch,
}
}
// NewRegistrationInfoEvent returns a new RegistrationInfoEvent
func NewRegistrationInfoEvent(regInfoCh chan<- *RegistrationInfo) *RegistrationInfoEvent {
return &RegistrationInfoEvent{RegInfoCh: regInfoCh}
}