forked from Elecman/directory.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbtc-address-check-balanceBL.go
79 lines (69 loc) · 2.01 KB
/
btc-address-check-balanceBL.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
package main
import (
"os"
"fmt"
"log"
"strconv"
"math/big"
"math/rand"
"net/http"
"io/ioutil"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
)
func checkBalance(address string, ch chan int) {
queryComp := "https://blockchain.info/q/addressbalance/" + address
resp, err := http.Get(queryComp)
if err != nil {
log.Fatalf("Checking balance (uncomp): %s\n", err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
bodystring := string(body)
balance, _ := strconv.Atoi(bodystring)
ch <- balance
}
func generateSeedAddress() []byte {
padded := make([]byte, 32)
for i := 0; i < 32; i++ {
padded[i] = byte(rand.Intn(256))
}
return padded
}
func main() {
ch := make(chan int)
file, err := os.OpenFile("resultBL.txt", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer file.Close()
// Initialise big numbers with small numbers
count, one := big.NewInt(0), big.NewInt(1)
// Create a slice to pad our count to 32 bytes
//padded := make([]byte, 32)
// Loop forever because we're never going to hit the end anyway
for {
// Increment our counter
count.Add(count, one)
// Copy count value's bytes to padded slice
copy(generateSeedAddress()[32-len(count.Bytes()):], count.Bytes())
// Get public key
privkey, public := btcec.PrivKeyFromBytes(btcec.S256(), generateSeedAddress())
wif, err := btcutil.NewWIF(privkey, &chaincfg.MainNetParams, true)
// Get addresses
caddr, _ := btcutil.NewAddressPubKey(public.SerializeCompressed(), &chaincfg.MainNetParams)
var uncom_balance int
if err != nil {
log.Fatalf("Checking balance (comp): %s\n", err)
}
go checkBalance(caddr.EncodeAddress(), ch)
uncom_balance = <-ch
fmt.Println(wif.String() + " " + caddr.EncodeAddress() + " " + strconv.Itoa(uncom_balance))
if uncom_balance > 0 {
var balance int
balance = uncom_balance
file.WriteString(wif.String() + " " + caddr.EncodeAddress() + " " + strconv.Itoa(balance) + "\n")
}
}
}