-
Notifications
You must be signed in to change notification settings - Fork 8
/
farmer.go
106 lines (87 loc) · 3.27 KB
/
farmer.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
100
101
102
103
104
105
106
package rpc
import (
"net/http"
"github.com/samber/mo"
"github.com/chia-network/go-chia-libs/pkg/protocols"
"github.com/chia-network/go-chia-libs/pkg/rpcinterface"
"github.com/chia-network/go-chia-libs/pkg/types"
)
// FarmerService encapsulates farmer RPC methods
type FarmerService struct {
client *Client
}
// NewRequest returns a new request specific to the wallet service
func (s *FarmerService) NewRequest(rpcEndpoint rpcinterface.Endpoint, opt interface{}) (*rpcinterface.Request, error) {
return s.client.NewRequest(rpcinterface.ServiceFarmer, rpcEndpoint, opt)
}
// Do is just a shortcut to the client's Do method
func (s *FarmerService) Do(req *rpcinterface.Request, v interface{}) (*http.Response, error) {
return s.client.Do(req, v)
}
// GetConnections returns connections
func (s *FarmerService) GetConnections(opts *GetConnectionsOptions) (*GetConnectionsResponse, *http.Response, error) {
request, err := s.NewRequest("get_connections", opts)
if err != nil {
return nil, nil, err
}
c := &GetConnectionsResponse{}
resp, err := s.Do(request, c)
if err != nil {
return nil, resp, err
}
return c, resp, nil
}
// GetNetworkInfo gets the network name and prefix from the farmer
func (s *FarmerService) GetNetworkInfo(opts *GetNetworkInfoOptions) (*GetNetworkInfoResponse, *http.Response, error) {
request, err := s.NewRequest("get_network_info", opts)
if err != nil {
return nil, nil, err
}
r := &GetNetworkInfoResponse{}
resp, err := s.Do(request, r)
if err != nil {
return nil, resp, err
}
return r, resp, nil
}
// FarmerGetHarvestersOptions optoins for get_harvesters endpoint. Currently, accepts no options
type FarmerGetHarvestersOptions struct{}
// FarmerHarvester is a single harvester record returned by the farmer's get_harvesters endpoint
type FarmerHarvester struct {
Connection struct {
NodeID types.Bytes32 `json:"node_id"`
Host string `json:"host"`
Port uint16 `json:"port"`
} `json:"connection"`
Plots []protocols.Plot `json:"plots"`
FailedToOpenFilenames []string `json:"failed_to_open_filenames"`
NoKeyFilenames []string `json:"no_key_filenames"`
Duplicates []string `json:"duplicates"`
TotalPlotSize int `json:"total_plot_size"`
TotalEffectivePlotSize int `json:"total_effective_plot_size"`
Syncing mo.Option[struct {
Initial bool `json:"initial"`
PlotFilesProcessed uint32 `json:"plot_files_processed"`
PlotFilesTotal uint32 `json:"plot_files_total"`
}] `json:"syncing"`
LastSyncTime types.Timestamp `json:"last_sync_time"`
HarvestingMode mo.Option[types.HarvestingMode] `json:"harvesting_mode"`
}
// FarmerGetHarvestersResponse get_harvesters response format
type FarmerGetHarvestersResponse struct {
Response
Harvesters []FarmerHarvester `json:"harvesters"`
}
// GetHarvesters returns all harvester details for the farmer
func (s *FarmerService) GetHarvesters(opts *FarmerGetHarvestersOptions) (*FarmerGetHarvestersResponse, *http.Response, error) {
request, err := s.NewRequest("get_harvesters", opts)
if err != nil {
return nil, nil, err
}
c := &FarmerGetHarvestersResponse{}
resp, err := s.Do(request, c)
if err != nil {
return nil, resp, err
}
return c, resp, nil
}