-
Notifications
You must be signed in to change notification settings - Fork 3
/
publisher.go
85 lines (72 loc) · 1.98 KB
/
publisher.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
package dkafka
import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"reflect"
"strings"
"github.com/google/cel-go/cel"
)
type extension struct {
name string
expr string
prog cel.Program
}
var irreversibleOnly = false
type ActionInfo struct {
Account string `json:"account"`
Receiver string `json:"receiver"`
Action string `json:"action"`
GlobalSequence uint64 `json:"global_seq"`
Authorization []string `json:"authorizations"`
DBOps []*decodedDBOp `json:"db_ops"`
JSONData *json.RawMessage `json:"json_data"`
}
type event struct {
BlockNum uint32 `json:"block_num"`
BlockID string `json:"block_id"`
Status string `json:"status"`
Executed bool `json:"executed"`
Step string `json:"block_step"`
TransactionID string `json:"trx_id"`
ActionInfo ActionInfo `json:"act_info"`
}
func (e event) JSON() []byte {
b, _ := json.Marshal(e)
return b
}
func hashString(data string) []byte {
h := sha256.New()
h.Write([]byte(data))
return []byte(base64.StdEncoding.EncodeToString(([]byte(h.Sum(nil)))))
}
var stringType = reflect.TypeOf("")
var stringArrayType = reflect.TypeOf([]string{})
func evalString(prog cel.Program, activation interface{}) (string, error) {
res, _, err := prog.Eval(activation)
if err != nil {
return "", err
}
out, err := res.ConvertToNative(stringType)
if err != nil {
return "", err
}
return out.(string), nil
}
func evalStringArray(prog cel.Program, activation interface{}) ([]string, error) {
res, _, err := prog.Eval(activation)
if err != nil {
return nil, err
}
out, err := res.ConvertToNative(stringArrayType)
if err != nil {
return nil, err
}
return out.([]string), nil
}
func sanitizeStep(step string) string {
return strings.Title(strings.TrimPrefix(step, "STEP_"))
}
func sanitizeStatus(status string) string {
return strings.Title(strings.TrimPrefix(status, "TRANSACTIONSTATUS_"))
}