Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared GetNetworkInfo #107

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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