github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/pricegetter/config.go (about) 1 package pricegetter 2 3 import ( 4 "fmt" 5 "math/big" 6 7 "github.com/0xPolygon/supernets2-node/config/types" 8 "github.com/0xPolygon/supernets2-node/pricegetter/priceprovider" 9 ) 10 11 // TokenPrice is a wrapper type that parses token amount to big float 12 type TokenPrice struct { 13 *big.Float `validate:"required"` 14 } 15 16 // UnmarshalText unmarshal token amount from float string to big int 17 func (t *TokenPrice) UnmarshalText(data []byte) error { 18 amount, ok := new(big.Float).SetString(string(data)) 19 if !ok { 20 return fmt.Errorf("failed to unmarshal string to float") 21 } 22 t.Float = amount 23 24 return nil 25 } 26 27 // Type for the pricegetter 28 type Type string 29 30 const ( 31 // SyncType synchronous request to price provider 32 SyncType Type = "sync" 33 // AsyncType update price every n second 34 AsyncType Type = "async" 35 // DefaultType get default price from the config 36 DefaultType Type = "default" 37 ) 38 39 // Config represents the configuration of the pricegetter 40 type Config struct { 41 // Type is price getter type 42 Type Type `mapstructure:"Type"` 43 44 // PriceProvider config 45 PriceProvider priceprovider.Config `mapstructure:"PriceProvider"` 46 47 // UpdateFrequency is price updating frequency, used only for the async type 48 UpdateFrequency types.Duration `mapstructure:"UpdateFrequency"` 49 50 // DefaultPrice is used only for the default type 51 DefaultPrice TokenPrice `mapstructure:"DefaultPrice"` 52 }