Skip to content

Commit

Permalink
create a func to parse config from a custom url
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhar-petukhov committed Dec 11, 2024
1 parent 3d3a044 commit 6b686db
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions liteapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,21 @@ func FromEnvs() Option {
// Mainnet configures a client to use lite servers from the mainnet.
func Mainnet() Option {
return func(o *Options) error {
file, err := downloadConfig("https://ton.org/global.config.json")
if err != nil {
return err
}
o.LiteServers = file.LiteServers
return nil
return setLiteServersFromURL("https://ton.org/global.config.json", o)
}
}

// Testnet configures a client to use lite servers from the testnet.
func Testnet() Option {
return func(o *Options) error {
file, err := downloadConfig("https://ton.org/testnet-global.config.json")
if err != nil {
return err
}
o.LiteServers = file.LiteServers
return nil
return setLiteServersFromURL("https://ton.org/testnet-global.config.json", o)
}
}

// WithConfigurationUrl configures a client using a custom configuration URL.
func WithConfigurationUrl(url string) Option {
return func(o *Options) error {
return setLiteServersFromURL(url, o)
}
}

Expand Down Expand Up @@ -1066,6 +1063,15 @@ func downloadConfig(path string) (*config.GlobalConfigurationFile, error) {
return o, nil
}

func setLiteServersFromURL(url string, o *Options) error {
file, err := downloadConfig(url)
if err != nil {
return err
}
o.LiteServers = file.LiteServers
return nil
}

func (c *Client) getNetworkGlobalID() *int32 {
c.mu.RLock()
defer c.mu.RUnlock()
Expand Down

0 comments on commit 6b686db

Please sign in to comment.