Skip to content

Instantly share code, notes, and snippets.

@kallydev
Last active December 4, 2021 12:16
Show Gist options
  • Save kallydev/615f52d9884e8868cbc4cbc1e64c931a to your computer and use it in GitHub Desktop.
Save kallydev/615f52d9884e8868cbc4cbc1e64c931a to your computer and use it in GitHub Desktop.
Generates an ETH address in a specific format.
package main
import (
"crypto/ecdsa"
"fmt"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/sirupsen/logrus"
"os"
"strings"
"sync/atomic"
"time"
)
const (
Threads = 16
ResultFilePath = "./result.txt"
)
var (
count int64
total int64
fileLogger = logrus.New()
)
func init() {
logrus.SetFormatter(&logrus.TextFormatter{
ForceColors: true,
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
logFile, err := os.OpenFile(ResultFilePath, os.O_WRONLY|os.O_CREATE, os.ModePerm)
if err != nil {
logrus.Fatalln(err)
}
fileLogger.SetFormatter(&logrus.TextFormatter{
DisableColors: true,
})
fileLogger.SetOutput(logFile)
}
func RateToString(rate int64) string {
if rate >= 1*1000*1000*1000*1000 {
return fmt.Sprintf("%dTH", rate/1000/1000/1000/1000)
} else if rate >= 1*1000*1000*1000 {
return fmt.Sprintf("%dGH", rate/1000/1000/1000)
} else if rate >= 1*1000*1000 {
return fmt.Sprintf("%dMH", rate/1000/1000)
} else if rate >= 1*1000 {
return fmt.Sprintf("%dKH", rate/1000)
} else {
return fmt.Sprintf("%dH", rate)
}
}
func main() {
for i := 0; i < Threads; i++ {
go func() {
for {
privateKey, err := crypto.GenerateKey()
if err != nil {
logrus.Fatalln(err)
}
address := crypto.PubkeyToAddress(*privateKey.Public().(*ecdsa.PublicKey)).Hex()
if strings.HasPrefix(address, "0x0000") {
fileLogger.Warningf(
"Success, after %s calculations. PrivateKey: %s Address: %s",
RateToString(atomic.LoadInt64(&total)),
hexutil.Encode(crypto.FromECDSA(privateKey)),
address,
)
atomic.StoreInt64(&total, 0)
}
atomic.AddInt64(&count, 1)
atomic.AddInt64(&total, 1)
}
}()
}
for {
logrus.Infof("In the calculation, the current rate is %s/s.\n", RateToString(atomic.LoadInt64(&count)))
atomic.StoreInt64(&count, 0)
time.Sleep(time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment