diff --git a/pkg/config/config.go b/pkg/config/config.go index 899cc47..a0b7c9f 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -19,6 +19,7 @@ type ChiaConfig struct { Harvester HarvesterConfig `yaml:"harvester"` Wallet WalletConfig `yaml:"wallet"` Seeder SeederConfig `yaml:"seeder"` + DataLayer DataLayerConfig `yaml:"data_layer"` SelectedNetwork string `yaml:"selected_network"` } @@ -60,6 +61,12 @@ type CrawlerConfig struct { SSL SSLConfig `yaml:"ssl"` } +// DataLayerConfig datalayer configuration section +type DataLayerConfig struct { + PortConfig `yaml:",inline"` + SSL SSLConfig `yaml:"ssl"` +} + // PortConfig common port settings found in many sections of the config type PortConfig struct { Port uint16 `yaml:"port"` diff --git a/pkg/httpclient/httpclient.go b/pkg/httpclient/httpclient.go index b8107e4..964fae6 100644 --- a/pkg/httpclient/httpclient.go +++ b/pkg/httpclient/httpclient.go @@ -46,6 +46,10 @@ type HTTPClient struct { crawlerPort uint16 crawlerKeyPair *tls.Certificate crawlerClient *http.Client + + datalayerPort uint16 + datalayerKeyPair *tls.Certificate + datalayerClient *http.Client } // NewHTTPClient returns a new HTTP client that satisfies the rpcinterface.Client interface @@ -60,6 +64,7 @@ func NewHTTPClient(cfg *config.ChiaConfig, options ...rpcinterface.ClientOptionF harvesterPort: cfg.Harvester.RPCPort, walletPort: cfg.Wallet.RPCPort, crawlerPort: cfg.Seeder.CrawlerConfig.RPCPort, + datalayerPort: cfg.DataLayer.RPCPort, } // Sets the default host. Can be overridden by client options @@ -226,6 +231,14 @@ func (c *HTTPClient) generateHTTPClientForService(service rpcinterface.ServiceTy } } keyPair = c.crawlerKeyPair + case rpcinterface.ServiceDataLayer: + if c.datalayerKeyPair == nil { + c.datalayerKeyPair, err = c.config.DataLayer.SSL.LoadPrivateKeyPair(c.config.ChiaRoot) + if err != nil { + return nil, err + } + } + keyPair = c.datalayerKeyPair default: return nil, fmt.Errorf("unknown service") } @@ -266,6 +279,8 @@ func (c *HTTPClient) portForService(service rpcinterface.ServiceType) uint16 { port = c.walletPort case rpcinterface.ServiceCrawler: port = c.crawlerPort + case rpcinterface.ServiceDataLayer: + port = c.datalayerPort } return port @@ -319,6 +334,14 @@ func (c *HTTPClient) httpClientForService(service rpcinterface.ServiceType) (*ht } } client = c.crawlerClient + case rpcinterface.ServiceDataLayer: + if c.datalayerClient == nil { + c.datalayerClient, err = c.generateHTTPClientForService(rpcinterface.ServiceDataLayer) + if err != nil { + return nil, err + } + } + client = c.datalayerClient } if client == nil { diff --git a/pkg/rpc/client.go b/pkg/rpc/client.go index c23ea77..52af01b 100644 --- a/pkg/rpc/client.go +++ b/pkg/rpc/client.go @@ -23,6 +23,7 @@ type Client struct { FarmerService *FarmerService HarvesterService *HarvesterService CrawlerService *CrawlerService + DataLayerService *DataLayerService websocketHandlers []rpcinterface.WebsocketResponseHandler } @@ -67,6 +68,7 @@ func NewClient(connectionMode ConnectionMode, configOption rpcinterface.ConfigOp c.FarmerService = &FarmerService{client: c} c.HarvesterService = &HarvesterService{client: c} c.CrawlerService = &CrawlerService{client: c} + c.DataLayerService = &DataLayerService{client: c} return c, nil } diff --git a/pkg/rpc/client_test.go b/pkg/rpc/client_test.go index 2406185..c828c1a 100644 --- a/pkg/rpc/client_test.go +++ b/pkg/rpc/client_test.go @@ -64,11 +64,11 @@ func setup(t *testing.T) (*http.ServeMux, *httptest.Server, *Client) { ChiaRoot: tmpDir, DaemonPort: portConf.RPCPort, DaemonSSL: sslConf, - FullNode: config.FullNodeConfig{ + Farmer: config.FarmerConfig{ PortConfig: portConf, SSL: sslConf, }, - Farmer: config.FarmerConfig{ + FullNode: config.FullNodeConfig{ PortConfig: portConf, SSL: sslConf, }, @@ -86,6 +86,10 @@ func setup(t *testing.T) (*http.ServeMux, *httptest.Server, *Client) { SSL: sslConf, }, }, + DataLayer: config.DataLayerConfig{ + PortConfig: portConf, + SSL: sslConf, + }, })) if err != nil { t.Fatal(err) diff --git a/pkg/rpc/datalayer.go b/pkg/rpc/datalayer.go new file mode 100644 index 0000000..f4dc6ee --- /dev/null +++ b/pkg/rpc/datalayer.go @@ -0,0 +1,22 @@ +package rpc + +import ( + "net/http" + + "github.com/chia-network/go-chia-libs/pkg/rpcinterface" +) + +// DataLayerService encapsulates data layer RPC methods +type DataLayerService struct { + client *Client +} + +// NewRequest returns a new request specific to the wallet service +func (s *DataLayerService) NewRequest(rpcEndpoint rpcinterface.Endpoint, opt interface{}) (*rpcinterface.Request, error) { + return s.client.NewRequest(rpcinterface.ServiceDataLayer, rpcEndpoint, opt) +} + +// Do is just a shortcut to the client's Do method +func (s *DataLayerService) Do(req *rpcinterface.Request, v interface{}) (*http.Response, error) { + return s.client.Do(req, v) +} diff --git a/pkg/rpcinterface/servicetype.go b/pkg/rpcinterface/servicetype.go index 38ddf2e..a644f1a 100644 --- a/pkg/rpcinterface/servicetype.go +++ b/pkg/rpcinterface/servicetype.go @@ -27,4 +27,7 @@ const ( // ServiceCrawler crawler service ServiceCrawler + + // ServiceDataLayer datalayer service + ServiceDataLayer )