-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
48 lines (41 loc) · 935 Bytes
/
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
package main
import (
"encoding/hex"
"flag"
"fmt"
)
func main() {
dbdir := flag.String("dbdir", "/root/.bitcoin/chainstate", "utxo or blockindex database dir")
prefix := flag.Int("prefix", 67, "please input leveldb key prefix")
obfuscate := flag.String("obfuscate", "", "leveldb obfuscate key used in utxo database")
flag.Parse()
dboption := &DBOption{
FilePath: *dbdir,
CacheSize: 1 << 20,
}
if obfuscate != nil {
dboption.DontObfuscate = true
}
dbw, err := NewDBWrapper(dboption)
if err != nil {
panic(err)
}
if obfuscate != nil {
bs, err := hex.DecodeString(*obfuscate)
if err != nil {
panic(err)
}
dbw.obfuscateKey = bs
}
iter := dbw.Iterator()
defer iter.Close()
var utxoCount int
for iter.SeekToFirst(); iter.Valid(); iter.Next() {
if *prefix == -1 {
utxoCount++
} else if int(iter.GetKey()[0]) == *prefix {
utxoCount++
}
}
fmt.Println("utxo set count:", utxoCount)
}