-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetters.go
57 lines (49 loc) · 1.48 KB
/
getters.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
package main
import (
"github.com/btcsuite/btcd/btcjson"
)
type BlockChainInfoGetter interface {
GetBlockChainInfo() (*btcjson.GetBlockChainInfoResult, error)
GetIndexInfo() (*btcjson.GetIndexInfoResult, error)
EstimateSmartFee(int64, *btcjson.EstimateSmartFeeMode) (*btcjson.EstimateSmartFeeResult, error)
}
func getBlockChainInfo(client BlockChainInfoGetter) (*float64, error) {
vLog("getters.go: Getting blockchain info")
info, err := client.GetBlockChainInfo()
if err != nil || info == nil {
vLog("getters.go: Error getting blockchain info: %s", err)
return nil, err
}
vLog("getters.go: Blockchain info: %f", info.VerificationProgress)
return &info.VerificationProgress, nil
}
func getIndexInfo(client BlockChainInfoGetter) (*float64, error) {
vLog("getters.go: Getting index info")
info, err := client.GetIndexInfo()
if err != nil || info == nil {
vLog("getters.go: Error getting index info: %s", err)
return nil, err
}
var result float64
result = 0.0
if info.Synced {
vLog("getters.go: Index is synced")
result = 1.0
}
return &result, nil
}
func getFeeEstimation(client BlockChainInfoGetter) (*float64, error) {
vLog("getters.go: Getting fee estimation")
info, err := client.EstimateSmartFee(1, nil)
if err != nil || info == nil {
vLog("getters.go: Error getting fee estimation: %s", err)
return nil, err
}
var result float64
result = 0.0
if info.FeeRate != nil {
vLog("getters.go: Fee estimation: %d", info.FeeRate)
result = 1.0
}
return &result, nil
}