@@ -2,10 +2,7 @@ package blockchain
22
33import (
44 "context"
5- "encoding/json"
65 "fmt"
7- "net/http"
8- "net/url"
96 "strconv"
107 "time"
118
@@ -29,62 +26,6 @@ const (
2926 liteServerPortOffset = 100 // arbitrary offset for lite server port
3027)
3128
32- // TON config structures (e.g.: ton-blockchain.github.io/testnet-global.config.json)
33- type tonLiteServer struct {
34- IP int64 `json:"ip"`
35- Port int `json:"port"`
36- ID struct {
37- Key string `json:"key"`
38- Type string `json:"@type"`
39- } `json:"id"`
40- }
41-
42- type tonConfig struct {
43- LiteServers []tonLiteServer `json:"liteservers"`
44- }
45-
46- // convert int64 IP to string format (matches https://github.com/xssnick/tonutils-go/liteclient/connection.go/intToIP4)
47- func intToIP4 (ip int64 ) string {
48- uip := uint32 (ip ) //nolint:gosec // IP conversion is safe for TON format
49- return fmt .Sprintf ("%d.%d.%d.%d" ,
50- (uip >> 24 )& 0xFF ,
51- (uip >> 16 )& 0xFF ,
52- (uip >> 8 )& 0xFF ,
53- uip & 0xFF )
54- }
55-
56- // fetch and parse TON config to generate liteserver URLs
57- func fetchTonConfig (configURL string ) ([]string , error ) {
58- parsedURL , err := url .Parse (configURL )
59- if err != nil {
60- return nil , fmt .Errorf ("invalid config URL: %w" , err )
61- }
62- if parsedURL .Scheme != "http" && parsedURL .Scheme != "https" {
63- return nil , fmt .Errorf ("invalid URL scheme: %s" , parsedURL .Scheme )
64- }
65-
66- resp , err := http .Get (configURL ) //nolint:gosec // URL is validated above
67- if err != nil {
68- return nil , fmt .Errorf ("failed to fetch config: %w" , err )
69- }
70- defer resp .Body .Close ()
71- defer resp .Body .Close ()
72-
73- var config tonConfig
74- if err := json .NewDecoder (resp .Body ).Decode (& config ); err != nil {
75- return nil , fmt .Errorf ("failed to decode config: %w" , err )
76- }
77-
78- var liteServerURLs []string
79- for _ , ls := range config .LiteServers {
80- ipStr := intToIP4 (ls .IP )
81- url := fmt .Sprintf ("liteserver://%s@%s:%d" , ls .ID .Key , ipStr , ls .Port )
82- liteServerURLs = append (liteServerURLs , url )
83- }
84-
85- return liteServerURLs , nil
86- }
87-
8829type portMapping struct {
8930 HTTPServer string
9031 LiteServer string
@@ -196,18 +137,6 @@ func newTon(in *Input) (*Output, error) {
196137 return nil , err
197138 }
198139
199- // fetch config and generate liteserver URLs from actual config
200- configURL := fmt .Sprintf ("http://localhost:%s/localhost.global.config.json" , ports .SimpleServer )
201-
202- liteServerURLs , err := fetchTonConfig (configURL )
203- if err != nil {
204- return nil , err
205- }
206-
207- if len (liteServerURLs ) == 0 {
208- return nil , fmt .Errorf ("no liteservers found in config" )
209- }
210-
211140 return & Output {
212141 UseCache : true ,
213142 ChainID : in .ChainID ,
0 commit comments