This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
chaincode_service.go
105 lines (81 loc) · 3.03 KB
/
chaincode_service.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
package gateway
import (
"context"
"time"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/s7techlab/cckit/router"
"github.com/s7techlab/cckit/sdk"
)
const EventListStreamTimeout = 500 * time.Millisecond
var _ ChaincodeServiceServer = &ChaincodeService{}
type ChaincodeService struct {
SDK sdk.SDK
EventService *ChaincodeEventService
}
// Deprecated: use NewChaincodeService instead
func New(sdk sdk.SDK) *ChaincodeService {
return NewChaincodeService(sdk)
}
func NewChaincodeService(sdk sdk.SDK) *ChaincodeService {
ccService := &ChaincodeService{
SDK: sdk,
EventService: NewChaincodeEventService(sdk),
}
return ccService
}
func NewChaincodeEventService(eventDelivery sdk.EventDelivery) *ChaincodeEventService {
eventService := &ChaincodeEventService{
EventDelivery: eventDelivery,
}
return eventService
}
// InstanceService returns ChaincodeInstanceService for current Peer interface and provided channel and chaincode name
func (cs *ChaincodeService) InstanceService(locator *ChaincodeLocator, opts ...Opt) *ChaincodeInstanceService {
return NewChaincodeInstanceService(cs.SDK, locator, opts...)
}
// ServiceDef returns service definition
func (cs *ChaincodeService) ServiceDef() ServiceDef {
return ServiceDef{
Desc: &_ChaincodeService_serviceDesc,
Service: cs,
HandlerFromEndpointRegister: RegisterChaincodeServiceHandlerFromEndpoint,
}
}
func (cs *ChaincodeService) Exec(ctx context.Context, req *ChaincodeExecRequest) (*peer.Response, error) {
if err := router.ValidateRequest(req); err != nil {
return nil, err
}
return cs.InstanceService(req.Locator).Exec(ctx, &ChaincodeInstanceExecRequest{
Type: req.Type, Input: req.Input})
}
func (cs *ChaincodeService) Invoke(ctx context.Context, req *ChaincodeInvokeRequest) (*peer.Response, error) {
if err := router.ValidateRequest(req); err != nil {
return nil, err
}
return cs.InstanceService(req.Locator).Invoke(ctx, &ChaincodeInstanceInvokeRequest{Input: req.Input})
}
func (cs *ChaincodeService) Query(ctx context.Context, req *ChaincodeQueryRequest) (*peer.Response, error) {
if err := router.ValidateRequest(req); err != nil {
return nil, err
}
return cs.InstanceService(req.Locator).Query(ctx, &ChaincodeInstanceQueryRequest{Input: req.Input})
}
func (cs *ChaincodeService) EventsStream(req *ChaincodeEventsStreamRequest, stream ChaincodeService_EventsStreamServer) error {
if err := router.ValidateRequest(req); err != nil {
return err
}
return cs.EventService.EventsStream(req, stream)
}
func (cs *ChaincodeService) Events(ctx context.Context, req *ChaincodeEventsRequest) (*ChaincodeEvents, error) {
if err := router.ValidateRequest(req); err != nil {
return nil, err
}
return cs.EventService.Events(ctx, req)
}
func (cs *ChaincodeService) EventsChan(
ctx context.Context, req *ChaincodeEventsStreamRequest) (_ chan *ChaincodeEvent, closer func() error, _ error) {
if err := router.ValidateRequest(req); err != nil {
return nil, nil, err
}
return cs.EventService.EventsChan(ctx, req)
}