Skip to content

Commit

Permalink
Shared GetNetworkInfo (#107)
Browse files Browse the repository at this point in the history
* Get network info

* Add get network info to crawler, using the new shared strategy

* NetworkName/Prefix are optional
  • Loading branch information
cmmarslender authored Mar 6, 2024
1 parent bee711a commit 068ad4b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 deletions.
17 changes: 17 additions & 0 deletions pkg/rpc/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ func (s *CrawlerService) Do(req *rpcinterface.Request, v interface{}) (*http.Res
return s.client.Do(req, v)
}

// GetNetworkInfo gets the network name and prefix from the full node
func (s *CrawlerService) 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
}

// GetPeerCountsResponse Response for get_get_peer_counts on crawler
type GetPeerCountsResponse struct {
Response
Expand Down
17 changes: 17 additions & 0 deletions pkg/rpc/fullnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ func (s *FullNodeService) GetConnections(opts *GetConnectionsOptions) (*GetConne
return c, resp, nil
}

// GetNetworkInfo gets the network name and prefix from the full node
func (s *FullNodeService) 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
}

// GetBlockchainStateResponse is the blockchain state RPC response
type GetBlockchainStateResponse struct {
Response
Expand Down
15 changes: 15 additions & 0 deletions pkg/rpc/shared.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package rpc

import (
"github.com/samber/mo"
)

// GetNetworkInfoOptions options for the get_network_info rpc calls
type GetNetworkInfoOptions struct {}

// GetNetworkInfoResponse common get_network_info response from all RPC services
type GetNetworkInfoResponse struct {
Response
NetworkName mo.Option[string] `json:"network_name"`
NetworkPrefix mo.Option[string] `json:"network_prefix"`
}
39 changes: 16 additions & 23 deletions pkg/rpc/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ func (s *WalletService) GetConnections(opts *GetConnectionsOptions) (*GetConnect
return c, resp, nil
}

// GetNetworkInfo wallet rpc -> get_network_info
func (s *WalletService) GetNetworkInfo(opts *GetNetworkInfoOptions) (*GetNetworkInfoResponse, *http.Response, error) {
request, err := s.NewRequest("get_network_info", nil)
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
}

// GetPublicKeysResponse response from get_public_keys
type GetPublicKeysResponse struct {
Response
Expand Down Expand Up @@ -208,29 +224,6 @@ func (s *WalletService) GetHeightInfo() (*GetWalletHeightInfoResponse, *http.Res
return r, resp, nil
}

// GetWalletNetworkInfoResponse response for get_height_info on wallet
type GetWalletNetworkInfoResponse struct {
Response
NetworkName mo.Option[string] `json:"network_name"`
NetworkPrefix mo.Option[string] `json:"network_prefix"`
}

// GetNetworkInfo wallet rpc -> get_network_info
func (s *WalletService) GetNetworkInfo() (*GetWalletNetworkInfoResponse, *http.Response, error) {
request, err := s.NewRequest("get_network_info", nil)
if err != nil {
return nil, nil, err
}

r := &GetWalletNetworkInfoResponse{}
resp, err := s.Do(request, r)
if err != nil {
return nil, resp, err
}

return r, resp, nil
}

// GetWalletsOptions wallet rpc -> get_wallets
type GetWalletsOptions struct {
Type types.WalletType `json:"type"`
Expand Down

0 comments on commit 068ad4b

Please sign in to comment.