This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.go
57 lines (47 loc) · 1.59 KB
/
processor.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
package utils
import (
"syscall"
"github.com/rberg2/sawtooth-go-sdk/processor"
"github.com/rberg2/sawtooth-go-sdk/protobuf/processor_pb2"
)
type MethodDelegate interface {
DelegateMethod(*processor_pb2.TpProcessRequest, *processor.Context) error
}
// TransactionHandler ...
type TransactionHandler struct {
FName string `json:"familyName"`
FVersions []string `json:"familyVersions"`
MethodDelegate MethodDelegate
NamespaceMngr *NamespaceMngr
}
// FamilyName ...
func (t *TransactionHandler) FamilyName() string {
return t.FName
}
// FamilyVersions ...
func (t *TransactionHandler) FamilyVersions() []string {
return t.FVersions
}
// Namespaces ...
func (t *TransactionHandler) Namespaces() []string {
return t.NamespaceMngr.NameSpaces
}
// Apply ...
func (t *TransactionHandler) Apply(request *processor_pb2.TpProcessRequest, context *processor.Context) error {
return t.MethodDelegate.DelegateMethod(request, context)
}
// NewTransactionHandler returns a new transaction handler
func NewTransactionHandler(methodDelegate MethodDelegate, fname string, fversions, namespaces []string) *TransactionHandler {
return &TransactionHandler{
FName: fname,
FVersions: fversions,
MethodDelegate: methodDelegate,
NamespaceMngr: NewNamespaceMngr().RegisterNamespaces(namespaces...),
}
}
func NewTransactionProcessor(validator string, handler processor.TransactionHandler) *processor.TransactionProcessor {
processor := processor.NewTransactionProcessor(validator)
processor.AddHandler(handler)
processor.ShutdownOnSignal(syscall.SIGINT, syscall.SIGTERM)
return processor
}