Skip to content

Commit

Permalink
Merge pull request #73 from Chia-Network/get-connections
Browse files Browse the repository at this point in the history
Get Connections
  • Loading branch information
cmmarslender authored Jan 15, 2023
2 parents 14874c6 + 01c74ea commit eb0cf27
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Client struct {
// Services for the different chia services
FullNodeService *FullNodeService
WalletService *WalletService
FarmerService *FarmerService
HarvesterService *HarvesterService
CrawlerService *CrawlerService

Expand Down Expand Up @@ -63,6 +64,7 @@ func NewClient(connectionMode ConnectionMode, configOption rpcinterface.ConfigOp
// Init Services
c.FullNodeService = &FullNodeService{client: c}
c.WalletService = &WalletService{client: c}
c.FarmerService = &FarmerService{client: c}
c.HarvesterService = &HarvesterService{client: c}
c.CrawlerService = &CrawlerService{client: c}

Expand Down
38 changes: 38 additions & 0 deletions pkg/rpc/farmer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package rpc

import (
"net/http"

"github.com/chia-network/go-chia-libs/pkg/rpcinterface"
)

// 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
}
16 changes: 16 additions & 0 deletions pkg/rpc/harvester.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ func (s *HarvesterService) Do(req *rpcinterface.Request, v interface{}) (*http.R
return s.client.Do(req, v)
}

// GetConnections returns connections
func (s *HarvesterService) 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
}

// HarvesterGetPlotsResponse get_plots response format
type HarvesterGetPlotsResponse struct {
Response
Expand Down
16 changes: 16 additions & 0 deletions pkg/rpc/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ func (s *WalletService) Do(req *rpcinterface.Request, v interface{}) (*http.Resp
return s.client.Do(req, v)
}

// GetConnections returns connections
func (s *WalletService) 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
}

// GetPublicKeysResponse response from get_public_keys
type GetPublicKeysResponse struct {
Response
Expand Down

0 comments on commit eb0cf27

Please sign in to comment.