-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
194 lines (167 loc) · 5 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/xssnick/tonutils-go/ton/wallet"
)
// Input parameters
type Config struct {
Version int
Suffix string
CaseSensitive bool
Bounce bool
Threads int
Testnet bool
}
func main() {
// Parse input parameters
config := parseFlags()
// Determine the number of threads (default: use all CPU cores if threads=0)
if config.Threads == 0 {
config.Threads = runtime.NumCPU()
}
log.Printf("Using %d threads\n", config.Threads)
// Channel to signal when a match is found
stopChan := make(chan struct{})
// Use sync.Once to ensure stopChan is closed only once
var once sync.Once
// Start tracking the number of processed wallets
var counter uint64
var wg sync.WaitGroup
// Start logging progress every second
go logProgress(&counter, stopChan)
// Start wallet generation and processing
for i := 0; i < config.Threads; i++ {
wg.Add(1)
go func() {
defer wg.Done()
processWallets(config, &counter, stopChan, &once)
}()
}
// Wait for all threads to finish
wg.Wait()
}
// parseFlags handles command-line input parameters
func parseFlags() Config {
version := flag.Int("version", 5, "Wallet version (4 or 5, default: 5)")
suffix := flag.String("suffix", "", "Desired contract address suffix (required)")
caseSensitive := flag.Bool("case-sensitive", false, "Enable case-sensitive suffix matching (default: false)")
bounce := flag.Bool("bounce", false, "Enable bounceable address (default: false)")
threads := flag.Int("threads", 0, "Number of parallel threads (default: 0, meaning use all CPU cores)")
testnet := flag.Bool("testnet", false, "Use testnet (default: false)")
flag.Parse()
if *suffix == "" || (*version != 4 && *version != 5) {
flag.PrintDefaults()
os.Exit(1)
}
return Config{
Version: *version,
Suffix: *suffix,
CaseSensitive: *caseSensitive,
Bounce: *bounce,
Threads: *threads,
Testnet: *testnet,
}
}
// processWallets generates wallets, checks if the address matches the suffix, and stops on a match
func processWallets(config Config, counter *uint64, stopChan chan struct{}, once *sync.Once) {
for {
select {
case <-stopChan:
return
default:
// Generate the seed phrase
seed := wallet.NewSeed()
// Create a wallet based on the selected version (V4 or V5)
var addressStr string
var err error
if config.Version == 5 {
addressStr, err = generateV5Wallet(seed, config)
} else {
addressStr, err = generateV4Wallet(seed, config)
}
if err != nil {
log.Printf("Failed to create wallet: %v", err)
continue
}
// Case-sensitive or case-insensitive suffix comparison
if config.CaseSensitive {
if strings.HasSuffix(addressStr, config.Suffix) {
printFoundWallet(seed, addressStr)
once.Do(func() { close(stopChan) })
return
}
} else {
if strings.HasSuffix(strings.ToLower(addressStr), strings.ToLower(config.Suffix)) {
printFoundWallet(seed, addressStr)
once.Do(func() { close(stopChan) })
return
}
}
// Increment the counter
atomic.AddUint64(counter, 1)
}
}
}
// generateV5Wallet creates a V5 wallet and returns the corresponding address
func generateV5Wallet(seed []string, config Config) (string, error) {
// Create a V5R1Final wallet using the seed
w, err := wallet.FromSeed(nil, seed, wallet.ConfigV5R1Final{
NetworkGlobalID: getNetworkID(config.Testnet),
Workchain: 0, // Base workchain
})
if err != nil {
return "", err
}
// Get the wallet address
addr := w.WalletAddress()
addressStr := addr.Testnet(config.Testnet).Bounce(config.Bounce).String()
return addressStr, nil
}
// generateV4Wallet creates a V4 wallet and returns the corresponding address
func generateV4Wallet(seed []string, config Config) (string, error) {
// Create a V4R2 wallet using the seed
w, err := wallet.FromSeed(nil, seed, wallet.V4R2)
if err != nil {
return "", err
}
// Get the wallet address
addr := w.WalletAddress()
addressStr := addr.Testnet(config.Testnet).Bounce(config.Bounce).String()
return addressStr, nil
}
// logProgress logs how many wallets were processed in the last second
func logProgress(counter *uint64, stopChan chan struct{}) {
var lastCount uint64
for {
select {
case <-stopChan:
return
case <-time.After(1 * time.Second):
currentCount := atomic.LoadUint64(counter)
processedLastSecond := currentCount - lastCount
lastCount = currentCount
log.Printf("Processed %d addresses in the last second\n", processedLastSecond)
}
}
}
// getNetworkID returns the correct network ID for mainnet or testnet (only for V5)
func getNetworkID(isTestnet bool) int32 {
if isTestnet {
return -3 // Testnet Global ID
}
return -239 // Mainnet Global ID
}
// printFoundWallet prints the found seed and wallet address
func printFoundWallet(seed []string, address string) {
fmt.Println("=== FOUND ===")
fmt.Println("Seed phrase:", strings.Join(seed, " "))
fmt.Println("Wallet address:", address)
}