-
Notifications
You must be signed in to change notification settings - Fork 18
/
info.go
50 lines (43 loc) · 1.72 KB
/
info.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
package btc
import (
"encoding/json"
"github.com/hiromaily/go-bitcoin/pkg/enum"
"github.com/pkg/errors"
)
// GetNetworkInfoResult getnetworkinfo RPC のレスポンス
type GetNetworkInfoResult struct {
Version enum.BTCVersion `json:"version"`
Subversion string `json:"subversion"`
Protocolversion int `json:"protocolversion"`
Localservices string `json:"localservices"`
Localrelay bool `json:"localrelay"`
Timeoffset int `json:"timeoffset"`
Networkactive bool `json:"networkactive"`
Connections int `json:"connections"`
Networks []Network `json:"networks"`
Relayfee float64 `json:"relayfee"`
Incrementalfee float64 `json:"incrementalfee"`
Localaddresses []string `json:"localaddresses"`
Warnings string `json:"warnings"`
}
// Network ネットワーク情報
type Network struct {
Name string `json:"name"`
Limited bool `json:"limited"`
Reachable bool `json:"reachable"`
Proxy string `json:"proxy"`
ProxyRandomizeCredentials bool `json:"proxy_randomize_credentials"`
}
// GetNetworkInfo getnetworkinfo RPC をcallする
func (b *Bitcoin) GetNetworkInfo() (*GetNetworkInfoResult, error) {
rawResult, err := b.client.RawRequest("getnetworkinfo", []json.RawMessage{})
if err != nil {
return nil, errors.Errorf("json.RawRequest(logging): error: %v", err)
}
networkInfoResult := GetNetworkInfoResult{}
err = json.Unmarshal([]byte(rawResult), &networkInfoResult)
if err != nil {
return nil, errors.Errorf("json.Unmarshal(): error: %v", err)
}
return &networkInfoResult, nil
}