Skip to content

Commit

Permalink
Merge pull request #8 from tonutils/test
Browse files Browse the repository at this point in the history
Updated tonutils-go core
  • Loading branch information
xssnick authored Jan 29, 2024
2 parents 9285794 + 1fd8c0d commit b47440e
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 75 deletions.
6 changes: 5 additions & 1 deletion build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
go build -o tonutils-reverse-proxy cmd/proxy/main.go
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o build/tonutils-reverse-proxy-linux-amd64 cmd/proxy/main.go
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o build/tonutils-reverse-proxy-linux-arm64 cmd/proxy/main.go
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" -o build/tonutils-reverse-proxy-windows-x64.exe cmd/proxy/main.go
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" -o build/tonutils-reverse-proxy-mac-amd64 cmd/proxy/main.go
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" -o build/tonutils-reverse-proxy-mac-arm64 cmd/proxy/main.go
26 changes: 17 additions & 9 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"github.com/mdp/qrterminal/v3"
"github.com/sigurn/crc16"
"github.com/ton-utils/reverse-proxy/config"
"github.com/xssnick/tonutils-go/adnl"
"github.com/xssnick/tonutils-go/adnl/dht"
rldphttp "github.com/xssnick/tonutils-go/adnl/rldp/http"
Expand Down Expand Up @@ -46,14 +47,16 @@ type Handler struct {
func (h Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
hdr := http.Header{}
for k := range request.Header {
// exception for ton.run, make headers canonical
hdr.Set(k, request.Header.Get(k))
// make headers canonical
for _, s := range request.Header.Values(k) {
hdr.Add(k, s)
}
}
request.Header = hdr

log.Println("request:", request.Method, request.Host, request.RequestURI)

writer.Header().Set("Ton-Reverse-Proxy", "Tonutils Reverse Proxy v0.2.0")
writer.Header().Set("Ton-Reverse-Proxy", "Tonutils Reverse Proxy v0.3.0")
h.h.ServeHTTP(writer, request)
}

Expand All @@ -68,9 +71,14 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

netCfg, err := liteclient.GetConfigFromUrl(ctx, cfg.NetworkConfigURL)
netCfg, err := liteclient.GetConfigFromUrl(context.Background(), cfg.NetworkConfigURL)
if err != nil {
panic("failed to load network config: " + err.Error())
log.Println("failed to download ton config:", err.Error(), "; we will take it from static cache")
netCfg = &liteclient.GlobalConfig{}
if err = json.NewDecoder(bytes.NewBufferString(config.FallbackNetworkConfig)).Decode(netCfg); err != nil {
log.Println("failed to parse fallback ton config:", err.Error())
os.Exit(1)
}
}

client := liteclient.NewConnectionPool()
Expand All @@ -91,7 +99,7 @@ func main() {
panic("failed to load network config: " + err.Error())
}

dhtClient, err := dht.NewClientFromConfig(ctx, gateway, netCfg)
dhtClient, err := dht.NewClientFromConfig(gateway, netCfg)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -161,7 +169,7 @@ func loadConfig() (*Config, error) {
return nil, err
}
cfg.PrivateKey = srvKey.Seed()
cfg.NetworkConfigURL = "https://ton-blockchain.github.io/global.config.json"
cfg.NetworkConfigURL = "https://ton.org/global.config.json"

cfg.ExternalIP, err = getPublicIP()
if err != nil {
Expand Down Expand Up @@ -194,7 +202,7 @@ func loadConfig() (*Config, error) {

// backwards compatibility with old configs
if cfg.NetworkConfigURL == "" {
cfg.NetworkConfigURL = "https://ton-blockchain.github.io/global.config.json"
cfg.NetworkConfigURL = "https://ton.org/global.config.json"
}

return &cfg, nil
Expand All @@ -221,7 +229,7 @@ func setupDomain(client *liteclient.ConnectionPool, domain string, adnlAddr []by
record, isStorage := domainInfo.GetSiteRecord()
if isStorage || !bytes.Equal(record, adnlAddr) {
data := domainInfo.BuildSetSiteRecordPayload(adnlAddr, false).ToBOCWithFlags(false)
args := "?bin=" + base64.URLEncoding.EncodeToString(data) + "&amount=" + tlb.MustFromTON("0.02").NanoTON().String()
args := "?bin=" + base64.URLEncoding.EncodeToString(data) + "&amount=" + tlb.MustFromTON("0.02").Nano().String()

nftData, err := domainInfo.GetNFTData(context.Background())
if err != nil {
Expand Down
Loading

0 comments on commit b47440e

Please sign in to comment.