Skip to content

Commit fd3a78f

Browse files
committed
chore: clean up
1 parent 0ef6c14 commit fd3a78f

File tree

1 file changed

+24
-36
lines changed
  • framework/components/blockchain

1 file changed

+24
-36
lines changed

framework/components/blockchain/ton.go

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,21 @@ import (
1616

1717
const (
1818
DefaultTonSimpleServerPort = "8000"
19+
liteServerPortOffset = 100 // internal, arbitrary offset for lite server port
1920
// NOTE: Prefunded high-load wallet from MyLocalTon pre-funded wallet, that can send up to 254 messages per 1 external message
2021
// https://docs.ton.org/v3/documentation/smart-contracts/contracts-specs/highload-wallet#highload-wallet-v2
2122
DefaultTonHlWalletAddress = "-1:5ee77ced0b7ae6ef88ab3f4350d8872c64667ffbe76073455215d3cdfab3294b"
2223
DefaultTonHlWalletMnemonic = "twenty unfair stay entry during please water april fabric morning length lumber style tomorrow melody similar forum width ride render void rather custom coin"
2324
)
2425

25-
type hostPortMapping struct {
26+
type portMapping struct {
2627
SimpleServer string
2728
LiteServer string
2829
DHTServer string
2930
Console string
3031
ValidatorUDP string
3132
}
3233

33-
func generateUniquePortsFromBase(basePort string) (*hostPortMapping, error) {
34-
base, err := strconv.Atoi(basePort)
35-
if err != nil {
36-
return nil, fmt.Errorf("invalid base port %s: %w", basePort, err)
37-
}
38-
return &hostPortMapping{
39-
SimpleServer: basePort, // external HTTP → internal 8000
40-
LiteServer: strconv.Itoa(base + 10),
41-
DHTServer: strconv.Itoa(base + 20),
42-
Console: strconv.Itoa(base + 30),
43-
ValidatorUDP: strconv.Itoa(base + 40),
44-
}, nil
45-
}
46-
4734
func defaultTon(in *Input) {
4835
if in.Image == "" {
4936
in.Image = "ghcr.io/neodix42/mylocalton-docker:latest"
@@ -53,51 +40,52 @@ func defaultTon(in *Input) {
5340
}
5441
}
5542

56-
// newTon starts only the genesis node and nothing else.
5743
func newTon(in *Input) (*Output, error) {
5844
defaultTon(in)
5945

60-
hostPorts, err := generateUniquePortsFromBase(in.Port)
46+
base, err := strconv.Atoi(in.Port)
6147
if err != nil {
62-
return nil, err
48+
return nil, fmt.Errorf("invalid base port %s: %w", in.Port, err)
49+
}
50+
51+
ports := &portMapping{
52+
SimpleServer: in.Port,
53+
LiteServer: strconv.Itoa(base + liteServerPortOffset),
6354
}
6455

6556
ctx := context.Background()
6657

67-
net, err := network.New(ctx,
58+
network, err := network.New(ctx,
6859
network.WithAttachable(),
6960
network.WithLabels(framework.DefaultTCLabels()),
7061
)
7162
if err != nil {
7263
return nil, err
7364
}
74-
networkName := net.Name
75-
76-
bindPorts := []string{
77-
fmt.Sprintf("%s:%s/tcp", hostPorts.SimpleServer, DefaultTonSimpleServerPort),
78-
fmt.Sprintf("%s:%s/tcp", hostPorts.LiteServer, hostPorts.LiteServer),
79-
fmt.Sprintf("%s:40003/udp", hostPorts.DHTServer),
80-
fmt.Sprintf("%s:40002/tcp", hostPorts.Console),
81-
fmt.Sprintf("%s:40001/udp", hostPorts.ValidatorUDP),
82-
}
83-
65+
networkName := network.Name
8466
req := testcontainers.ContainerRequest{
8567
Image: in.Image,
8668
AlwaysPullImage: in.PullImage,
8769
Name: framework.DefaultTCName("ton-genesis"),
88-
ExposedPorts: bindPorts,
89-
Networks: []string{networkName},
90-
NetworkAliases: map[string][]string{networkName: {"genesis"}},
91-
Labels: framework.DefaultTCLabels(),
70+
ExposedPorts: []string{
71+
fmt.Sprintf("%s:%s/tcp", ports.SimpleServer, DefaultTonSimpleServerPort),
72+
fmt.Sprintf("%s:%s/tcp", ports.LiteServer, ports.LiteServer),
73+
"40003/udp",
74+
"40002/tcp",
75+
"40001/udp",
76+
},
77+
Networks: []string{networkName},
78+
NetworkAliases: map[string][]string{networkName: {"genesis"}},
79+
Labels: framework.DefaultTCLabels(),
9280
Env: map[string]string{
9381
"GENESIS": "true",
9482
"NAME": "genesis",
95-
"LITE_PORT": hostPorts.LiteServer,
83+
"LITE_PORT": ports.LiteServer, // Note: exposed config file follows this env
9684
"CUSTOM_PARAMETERS": "--state-ttl 315360000 --archive-ttl 315360000",
9785
},
9886
WaitingFor: wait.ForExec([]string{
9987
"/usr/local/bin/lite-client",
100-
"-a", fmt.Sprintf("127.0.0.1:%s", hostPorts.LiteServer),
88+
"-a", fmt.Sprintf("127.0.0.1:%s", ports.LiteServer),
10189
"-b", "E7XwFSQzNkcRepUC23J2nRpASXpnsEKmyyHYV4u/FZY=",
10290
"-t", "3", "-c", "last",
10391
}).WithStartupTimeout(2 * time.Minute),
@@ -137,7 +125,7 @@ func newTon(in *Input) (*Output, error) {
137125
ContainerName: name,
138126
Nodes: []*Node{{
139127
// Note: define if we need more access other than the global config(tonutils-go only uses liteclients defined in the config)
140-
ExternalHTTPUrl: fmt.Sprintf("%s:%s", "localhost", hostPorts.SimpleServer),
128+
ExternalHTTPUrl: fmt.Sprintf("%s:%s", "localhost", ports.SimpleServer),
141129
InternalHTTPUrl: fmt.Sprintf("%s:%s", name, DefaultTonSimpleServerPort),
142130
}},
143131
}, nil

0 commit comments

Comments
 (0)