-
Notifications
You must be signed in to change notification settings - Fork 1
/
blockv.go
99 lines (86 loc) · 2.8 KB
/
blockv.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"
)
type CoinHeight struct {
Height int `json:"height"`
Status string `json:"status"`
}
type Block struct {
ID string `json:"id"`
Jsonrpc string `json:"jsonrpc"`
Result struct {
Block struct {
AlreadyGeneratedCoins string `json:"alreadyGeneratedCoins"`
AlreadyGeneratedTransactions int `json:"alreadyGeneratedTransactions"`
BaseReward int `json:"baseReward"`
BlockSize int `json:"blockSize"`
Depth int `json:"depth"`
Difficulty int `json:"difficulty"`
EffectiveSizeMedian int `json:"effectiveSizeMedian"`
Hash string `json:"hash"`
Height int `json:"height"`
MajorVersion int `json:"major_version"`
MinorVersion int `json:"minor_version"`
Nonce int `json:"nonce"`
OrphanStatus bool `json:"orphan_status"`
Penalty float64 `json:"penalty"`
PrevHash string `json:"prev_hash"`
Reward int `json:"reward"`
SizeMedian int `json:"sizeMedian"`
Timestamp int `json:"timestamp"`
TotalFeeAmount int `json:"totalFeeAmount"`
Transactions []struct {
AmountOut int `json:"amount_out"`
Fee int `json:"fee"`
Hash string `json:"hash"`
Size int `json:"size"`
} `json:"transactions"`
TransactionsCumulativeSize int `json:"transactionsCumulativeSize"`
} `json:"block"`
Status string `json:"status"`
} `json:"result"`
}
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
// Get height
resp, err := http.Get("http://localhost:8081/getheight")
check(err)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var ch CoinHeight
err = json.Unmarshal(body, &ch)
check(err)
printed := 0
for i := 981539; i < ch.Height; i++ {
// Don't kill the server!
time.Sleep(10 * time.Millisecond)
var height = i
height_string := strconv.Itoa(height)
jsonStr := []byte(`{"method": "f_block_json","params": {"hash": "` + height_string + `"}}`)
req, err := http.NewRequest("POST", "http://localhost:8081/json_rpc", bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
check(err)
defer resp.Body.Close()
body, _ = ioutil.ReadAll(resp.Body)
var block Block
err = json.Unmarshal(body, &block)
check(err)
if printed == 0 && block.Result.Block.MajorVersion == 3 {
fmt.Println("Height v3.0: ", height_string)
printed = 1
}
}
}