-
Notifications
You must be signed in to change notification settings - Fork 17
/
config_feed.go
110 lines (91 loc) · 3.07 KB
/
config_feed.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
package monitoring
import (
"encoding/json"
"fmt"
"io"
"math/big"
relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
)
type StarknetFeedConfig struct {
Name string `json:"name,omitempty"`
Path string `json:"path,omitempty"`
Symbol string `json:"symbol,omitempty"`
HeartbeatSec int64 `json:"heartbeat,omitempty"`
ContractType string `json:"contract_type,omitempty"`
ContractStatus string `json:"status,omitempty"`
MultiplyRaw string `json:"multiply,omitempty"`
Multiply *big.Int `json:"-"`
ContractAddress string `json:"contract_address,omitempty"`
ProxyAddress string `json:"proxy_address,omitempty"`
}
var _ relayMonitoring.FeedConfig = StarknetFeedConfig{}
// GetID returns the state account's address as that uniquely
// identifies a feed on Starknet. In Starknet, a program is stateless and we
// use the same program for all feeds so we can't use the program
// account's address.
func (s StarknetFeedConfig) GetID() string {
return s.ContractAddress
}
func (s StarknetFeedConfig) GetName() string {
return s.Name
}
func (s StarknetFeedConfig) GetPath() string {
return s.Path
}
func (s StarknetFeedConfig) GetFeedPath() string {
return s.Path
}
func (s StarknetFeedConfig) GetSymbol() string {
return s.Symbol
}
func (s StarknetFeedConfig) GetHeartbeatSec() int64 {
return s.HeartbeatSec
}
func (s StarknetFeedConfig) GetContractType() string {
return s.ContractType
}
func (s StarknetFeedConfig) GetContractStatus() string {
return s.ContractStatus
}
func (s StarknetFeedConfig) GetMultiply() *big.Int {
return s.Multiply
}
func (s StarknetFeedConfig) GetContractAddress() string {
return s.ContractAddress
}
func (s StarknetFeedConfig) GetContractAddressBytes() []byte {
return []byte(s.ContractAddress)
}
func (s StarknetFeedConfig) ToMapping() map[string]interface{} {
return map[string]interface{}{
"feed_name": s.Name,
"feed_path": s.Path,
"symbol": s.Symbol,
"heartbeat_sec": int64(s.HeartbeatSec),
"contract_type": s.ContractType,
"contract_status": s.ContractStatus,
"contract_address": []byte(s.ContractAddress),
// These fields are legacy. They are required in the schema but they
// should be set to a zero value for any other chain.
"transmissions_account": []byte{},
"state_account": []byte{},
}
}
func StarknetFeedsParser(buf io.ReadCloser) ([]relayMonitoring.FeedConfig, error) {
rawFeeds := []StarknetFeedConfig{}
decoder := json.NewDecoder(buf)
if err := decoder.Decode(&rawFeeds); err != nil {
return nil, fmt.Errorf("unable to unmarshal feeds config data: %w", err)
}
feeds := make([]relayMonitoring.FeedConfig, len(rawFeeds))
for i, rawFeed := range rawFeeds {
multiply, ok := new(big.Int).SetString(rawFeed.MultiplyRaw, 10)
if !ok {
return nil, fmt.Errorf("failed to parse multiply '%s' into a big.Int", rawFeed.MultiplyRaw)
}
// NOTE: multiply is not required so if a parse error occurs, we'll use 0.
rawFeed.Multiply = multiply
feeds[i] = relayMonitoring.FeedConfig(rawFeed)
}
return feeds, nil
}