-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive_reader.go
73 lines (62 loc) · 1.44 KB
/
archive_reader.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
package main
import (
"context"
"flag"
"fmt"
"io"
"log"
"github.com/lantah/go/historyarchive"
"github.com/lantah/go/ingest"
)
func main() {
ledgerPtr := flag.Uint64("ledger", 0, "`ledger to analyze` (tip: has to be of the form `ledger = 64*n - 1`, where n is > 0)")
flag.Parse()
seqNum := uint32(*ledgerPtr)
if seqNum == 0 {
flag.Usage()
return
}
archive, e := archive()
if e != nil {
panic(e)
}
sr, e := ingest.NewCheckpointChangeReader(context.Background(), archive, seqNum)
if e != nil {
panic(e)
}
accounts := map[string]bool{}
var i uint64 = 0
var count uint64 = 0
for {
le, e := sr.Read()
if e != nil {
panic(e)
}
if e == io.EOF {
log.Printf("total seen %d entries of which %d were accounts", i, count)
return
}
if ae, valid := le.Post.Data.GetAccount(); valid {
addr := ae.AccountId.Address()
if _, exists := accounts[addr]; exists {
log.Fatalf("error, total seen %d entries of which %d were unique accounts; repeated account: %s", i, count, addr)
}
accounts[addr] = true
count += 1
}
i += 1
if i%1000 == 0 {
log.Printf("seen %d entries of which %d were accounts", i, count)
}
}
}
func archive() (*historyarchive.Archive, error) {
return historyarchive.Connect(
fmt.Sprintf("s3://history.stellar.org/prd/core-live/core_live_001/"),
historyarchive.ConnectOptions{
S3Region: "eu-west-1",
UnsignedRequests: true,
UserAgent: "archive-reader",
},
)
}