-
Notifications
You must be signed in to change notification settings - Fork 117
/
main.go
72 lines (59 loc) · 1.54 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"context"
"crypto/ed25519"
"fmt"
"github.com/xssnick/tonutils-go/adnl"
"github.com/xssnick/tonutils-go/adnl/dht"
rldphttp "github.com/xssnick/tonutils-go/adnl/rldp/http"
"github.com/xssnick/tonutils-go/liteclient"
"github.com/xssnick/tonutils-go/ton"
"github.com/xssnick/tonutils-go/ton/dns"
"io"
"net/http"
)
func main() {
_, clientKey, err := ed25519.GenerateKey(nil)
if err != nil {
panic(err)
}
gateway := adnl.NewGateway(clientKey)
err = gateway.StartClient()
if err != nil {
panic(err)
}
dhtClient, err := dht.NewClientFromConfigUrl(context.Background(), gateway, "https://ton.org/global.config.json")
if err != nil {
panic(err)
}
client := &http.Client{
Transport: rldphttp.NewTransport(dhtClient, getDNSResolver()),
}
resp, err := client.Get("http://utils.ton/")
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println("Status code:", resp.StatusCode, resp.Status)
fmt.Println("Response:\n", string(data))
}
func getDNSResolver() *dns.Client {
client := liteclient.NewConnectionPool()
// connect to testnet lite server
err := client.AddConnectionsFromConfigUrl(context.Background(), "https://ton.org/global.config.json")
if err != nil {
panic(err)
}
// initialize ton api lite connection wrapper
api := ton.NewAPIClient(client)
// get root dns address from network config
root, err := dns.GetRootContractAddr(context.Background(), api)
if err != nil {
panic(err)
}
return dns.NewDNSClient(api, root)
}