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_old.go
105 lines (86 loc) · 2.65 KB
/
chaincode_old.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"
"github.com/s7techlab/cckit/convert"
)
// All this components are deprecated and will be removed, use ChaincodeInvoker
// ====================================================================
type Action string
const (
Query Action = `query`
Invoke Action = `invoke`
)
// Deprecated: use ChaincodeInvoker
type Chaincode interface {
Query(ctx context.Context, fn string, args []interface{}, target interface{}) (interface{}, error)
Invoke(ctx context.Context, fn string, args []interface{}, target interface{}) (interface{}, error)
Events(ctx context.Context, r ...*ChaincodeInstanceEventsStreamRequest) (ChaincodeEventSub, error)
}
// Deprecated: use ChaincodeInstanceEventDelivery
type ChaincodeEventSub interface {
Context() context.Context
Events() <-chan *ChaincodeEvent
Recv(*ChaincodeEvent) error
Close()
}
type chaincode struct {
Service *ChaincodeService
Channel string
Chaincode string
}
// Deprecated: use NewChaincodeInvoker
func NewChaincode(service *ChaincodeService, channelName, chaincodeName string, opts ...Opt) *chaincode {
c := &chaincode{
Service: service,
Channel: channelName,
Chaincode: chaincodeName,
}
return c
}
func (c *chaincode) Locator() *ChaincodeLocator {
return &ChaincodeLocator{
Channel: c.Channel,
Chaincode: c.Chaincode,
}
}
// Deprecated: use ChaincodeInstanceEventDelivery
// ChaincodeInstance for converting to new model
func (c *chaincode) ChaincodeInstance() *ChaincodeInstanceService {
return c.Service.InstanceService(c.Locator())
}
// Deprecated: use ChaincodeInstanceEventDelivery
func (c *chaincode) Events(ctx context.Context, r ...*ChaincodeInstanceEventsStreamRequest) (_ chan<- *ChaincodeEvent, closer func() error, _ error) {
req := &ChaincodeInstanceEventsStreamRequest{}
if len(r) == 1 {
req = r[0]
}
return c.ChaincodeInstance().EventsChan(ctx, req)
}
func (c *chaincode) Query(ctx context.Context, fn string, args []interface{}, target interface{}) (interface{}, error) {
ccInput, err := ccInput(ctx, fn, args)
if err != nil {
return nil, err
}
response, err := c.Service.Query(ctx, &ChaincodeQueryRequest{
Locator: c.Locator(),
Input: ccInput,
})
if err != nil {
return nil, err
}
return convert.FromBytes(response.Payload, target)
}
func (c *chaincode) Invoke(ctx context.Context, fn string, args []interface{}, target interface{}) (interface{}, error) {
ccInput, err := ccInput(ctx, fn, args)
if err != nil {
return nil, err
}
response, err := c.Service.Invoke(ctx, &ChaincodeInvokeRequest{
Locator: c.Locator(),
Input: ccInput,
})
if err != nil {
return nil, err
}
return convert.FromBytes(response.Payload, target)
}