forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
52 lines (41 loc) · 1.33 KB
/
config.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
package pricegetter
import (
"fmt"
"math/big"
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/pricegetter/priceprovider"
)
// TokenPrice is a wrapper type that parses token amount to big float
type TokenPrice struct {
*big.Float `validate:"required"`
}
// UnmarshalText unmarshal token amount from float string to big int
func (t *TokenPrice) UnmarshalText(data []byte) error {
amount, ok := new(big.Float).SetString(string(data))
if !ok {
return fmt.Errorf("failed to unmarshal string to float")
}
t.Float = amount
return nil
}
// Type for the pricegetter
type Type string
const (
// SyncType synchronous request to price provider
SyncType Type = "sync"
// AsyncType update price every n second
AsyncType Type = "async"
// DefaultType get default price from the config
DefaultType Type = "default"
)
// Config represents the configuration of the pricegetter
type Config struct {
// Type is price getter type
Type Type `mapstructure:"Type"`
// PriceProvider config
PriceProvider priceprovider.Config `mapstructure:"PriceProvider"`
// UpdateFrequency is price updating frequency, used only for the async type
UpdateFrequency types.Duration `mapstructure:"UpdateFrequency"`
// DefaultPrice is used only for the default type
DefaultPrice TokenPrice `mapstructure:"DefaultPrice"`
}