-
Notifications
You must be signed in to change notification settings - Fork 3
/
vc.go
103 lines (88 loc) · 2.78 KB
/
vc.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
package crypto
import (
"bytes"
"sync"
)
// MethodName plugin function name
const MethodName = "NewSDK"
// curve name
const (
CurveNameBN254 = "bn254"
CurveNameSM9 = "sm9"
CurveNameCurve101 = "testCurve101"
CurveNameCurve101NonFFT = "testCurve101NonFFT"
)
// NewSDKFunc plugin function type
type NewSDKFunc func(path, user, namespace string, logger Logger) (ChainSDK, error)
// EventType type EventType
type EventType int
// event type
const (
EventTypeCompute EventType = iota
EventTypeFinish
)
// ChainSDK sdk for specific blockchain
type ChainSDK interface {
//ChainType 返回链的类型
ChainType() string
//InvokeFinish 调用Finish方法, namespace是分区(通道),address是合约地址(名称)
InvokeFinish(nodes []string, address, taskID, proof, result, error string) ([]byte, error)
//RegisterListening 注册监听EVENT_FINISH和EVENT_COMPUTE事件
RegisterListening(proxyAddress, businessAddress []string) (chan *Event, error)
//UnregisterListening 解注册事件
UnregisterListening(address string) error
}
// Event event
type Event struct {
ChannelID string `json:"channelID"`
Type EventType `json:"type"`
Event []byte `json:"event"` //json content
TxHash string `json:"txHash"`
BlockNum int `json:"blockNum"`
}
// EventCompute event compute
type EventCompute struct {
TaskID string `json:"taskID"`
CircuitID [32]byte `json:"circuitID"`
CCName string `json:"ccName"`
WebHook string `json:"webHook"`
WebHookBodyPattern string `json:"webHookBodyPattern"`
BusinessContractAddr string `json:"businessContractAddr"`
BusinessContractMethod string `json:"businessContractMethod"`
Input string `json:"input"`
}
// EventFinish event finish
type EventFinish struct {
TaskID string `json:"taskID"`
CircuitID [32]byte `json:"circuitID"`
Proof string `json:"proof"`
Result string `json:"result"`
Error string `json:"error"`
Response []byte `json:"response"`
NextCompute []byte `json:"nextCompute"`
}
// Response callback response
type Response struct {
Continue bool `json:"continue"`
//NextParam: proxyContractAddr, input, businessContractAddr, businessContractMethod, WebHook and WebHookBodyPattern
NextParam [6]string `json:"nextParam"`
//response
Response []byte `json:"response"`
}
var pairing sync.Map
// RegisterPairing register pairing
func RegisterPairing(p Pairing) {
pairing.Store(p.Name(), p)
}
// UnMarshalPairing unmarshal pairing
func UnMarshalPairing(data []byte) Pairing {
var ret Pairing
pairing.Range(func(key, value interface{}) bool {
if bytes.Equal(data, []byte(key.(string))) {
ret = value.(Pairing)
return false
}
return true
})
return ret
}