@@ -104,6 +104,50 @@ func WithInitializationContext(ctx context.Context) Option {
104104 }
105105}
106106
107+ // FromEnvsOrMainnet configures a client to use lite servers from the LITE_SERVERS env variable.
108+ // If LITE_SERVERS is not set, it downloads public config for mainnet from ton.org.
109+ func FromEnvsOrMainnet () Option {
110+ return func (o * Options ) error {
111+ if value , ok := os .LookupEnv (LiteServerEnvName ); ok {
112+ servers , err := config .ParseLiteServersEnvVar (value )
113+ if err != nil {
114+ return err
115+ }
116+ o .LiteServers = servers
117+ o .MaxConnections = len (servers )
118+ return nil
119+ }
120+ file , err := downloadConfig ("https://ton-blockchain.github.io/global.config.json" )
121+ if err != nil {
122+ return err
123+ }
124+ o .LiteServers = file .LiteServers
125+ return nil
126+ }
127+ }
128+
129+ // FromEnvsOrTestnet configures a client to use lite servers from the LITE_SERVERS env variable.
130+ // If LITE_SERVERS is not set, it downloads public config for testnet from ton.org.
131+ func FromEnvsOrTestnet () Option {
132+ return func (o * Options ) error {
133+ if value , ok := os .LookupEnv (LiteServerEnvName ); ok {
134+ servers , err := config .ParseLiteServersEnvVar (value )
135+ if err != nil {
136+ return err
137+ }
138+ o .LiteServers = servers
139+ o .MaxConnections = len (servers )
140+ return nil
141+ }
142+ file , err := downloadConfig ("https://ton-blockchain.github.io/testnet-global.config.json" )
143+ if err != nil {
144+ return err
145+ }
146+ o .LiteServers = file .LiteServers
147+ return nil
148+ }
149+ }
150+
107151// FromEnvs configures a Client based on the following environment variables:
108152// LITE_SERVERS - a list of lite servers to use.
109153// FromEnvs() also sets MaxConnectionsNumber to be equal to the number of servers in LITE_SERVERS.
0 commit comments