-
Notifications
You must be signed in to change notification settings - Fork 0
/
blockinfo.go
48 lines (39 loc) · 1.02 KB
/
blockinfo.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
/*
Blockinfo is an example program using the bbrpc interface.
It prints out the trailing 24 hour average reward from the
blockchain (actually, 720 blocks, not strictly 24 hours).
The secondary purpose of this program is to benchmark the time
it takes to retrieve a lot of blockchain data.
*/
package main
import (
"fmt"
"github.com/dave-andersen/gobbr"
)
const DAEMON_ADDRESS = "http://localhost:10102"
func main() {
d := gobbr.NewDaemon(DAEMON_ADDRESS)
height, err := d.GetHeight()
if err != nil {
fmt.Println("Error getting height: ", err)
return
}
orphans := 0
nonOrphans := 0
totalReward := uint64(0)
for i := (height-720); i < height; i++ {
bh, err := d.GetBlockHeaderByHeight(i)
if err != nil {
fmt.Println("Error getting blockheader: ", err)
return
}
if bh.OrphanStatus {
orphans++
} else {
nonOrphans++
totalReward += bh.Reward
}
}
fmt.Printf("Normal: %d Orphans: %d Avg Reward: %2.f\n", nonOrphans, orphans,
float64(totalReward)/float64(nonOrphans*gobbr.Multiplier) )
}