This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
task.go
113 lines (94 loc) · 2.84 KB
/
task.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
106
107
108
109
110
111
112
113
package crosschain
import "fmt"
// Task represents a tx, e.g. smart contract function call, on a blockchain.
type Task string
// TaskConfig is the model used to represent a task read from config file or db
type TaskConfig struct {
Name string `yaml:"name"`
Code string `yaml:"code"`
Allow []string `yaml:"allow"`
Signer string `yaml:"signer"`
DefaultParams map[string]interface{} `yaml:"default_params"`
Operations []TaskConfigOperation `yaml:"operations"`
// internal
AllowList []*AllowEntry `yaml:"-"`
SrcAsset ITask `yaml:"-"`
DstAsset ITask `yaml:"-"`
}
// PipelineConfig is the model used to represent a pipeline (list of tasks) read from config file or db
type PipelineConfig struct {
ID string `yaml:"name"`
Allow []string `yaml:"allow"`
Tasks []string `yaml:"tasks"`
// internal
AllowList []*AllowEntry `yaml:"-"`
}
func (p PipelineConfig) String() string {
return fmt.Sprintf(
"PipelineConfig(id=%s)",
p.ID,
)
}
type AllowEntry struct {
Src AssetID
Dst AssetID
}
type TaskConfigOperation struct {
Function string `yaml:"function"`
Signature string `yaml:"signature"`
Contract interface{} `yaml:"contract"` // string or map[string]string
Payable bool `yaml:"payable"`
Params []TaskConfigOperationParam `yaml:"params"`
}
type TaskConfigOperationParam struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Bind string `yaml:"bind"`
Match string `yaml:"match"`
Value interface{} `yaml:"value"` // string or map[string]string
// Defaults []TaskConfigOperationParamDefaults `yaml:"defaults"`
// Fields []TaskConfigOperationParamField `yaml:"fields"`
}
type TaskConfigOperationParamDefaults struct {
Match string `yaml:"match"`
Value string `yaml:"value"`
}
type ITask interface {
ID() AssetID
GetDriver() string
GetAssetConfig() *AssetConfig
GetNativeAsset() *NativeAssetConfig
GetTask() *TaskConfig
}
func (task TaskConfig) String() string {
src := "not-set"
if task.SrcAsset != nil {
src = string(task.SrcAsset.ID())
}
dst := "not-set"
if task.DstAsset != nil {
dst = string(task.DstAsset.ID())
}
return fmt.Sprintf(
"TaskConfig(id=%s src=%s dst=%s)",
task.ID(), src, dst,
)
}
func (task *TaskConfig) ID() AssetID {
return AssetID(task.Name)
}
func (task TaskConfig) GetAssetConfig() *AssetConfig {
return task.SrcAsset.GetAssetConfig()
}
func (task TaskConfig) GetDriver() string {
return task.SrcAsset.GetAssetConfig().Driver
}
func (task TaskConfig) GetAsset() string {
return task.SrcAsset.GetAssetConfig().Asset
}
func (task TaskConfig) GetNativeAsset() *NativeAssetConfig {
return task.SrcAsset.GetNativeAsset()
}
func (task TaskConfig) GetTask() *TaskConfig {
return &task
}