diff --git a/liteapi/client.go b/liteapi/client.go index 292e967..014611b 100644 --- a/liteapi/client.go +++ b/liteapi/client.go @@ -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 configureWithUrl("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 configureWithUrl("https://ton.org/testnet-global.config.json", o) + } +} + +// CustomConfigUrl configures a client using a custom configuration URL. +func CustomConfigUrl(url string) Option { + return func(o *Options) error { + return configureWithUrl(url, o) } } @@ -1066,6 +1063,15 @@ func downloadConfig(path string) (*config.GlobalConfigurationFile, error) { return o, nil } +func configureWithUrl(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()