-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework the websocket client with new sync mode + more intuitive usage…
… patterns + add daemon service (#113) * Rework the websocket mode to be a bit more intuiative to use + add a sync mode + ability to remove handlers after they're registered Sync mode will cause the rpc function calls to wait for their response before returning (request/response style calls vs async handlers) * Add daemon service * Update readme with new websocket usage patterns * Don't return errors from the http client methods that exist only to satisfy the interface * Simplify return signature of functions that can't actually return errors anyways (because of goroutines) * Make error messages a bit more detailed * Return errors from any methods that try to do something specifically not supported by the HTTP client, leave nil return as implied/only-option type functions
- Loading branch information
1 parent
ee18932
commit 71666e5
Showing
10 changed files
with
359 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package rpc | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/chia-network/go-chia-libs/pkg/rpcinterface" | ||
) | ||
|
||
// DaemonService encapsulates direct daemon RPC methods | ||
type DaemonService struct { | ||
client *Client | ||
} | ||
|
||
// NewRequest returns a new request specific to the crawler service | ||
func (s *DaemonService) NewRequest(rpcEndpoint rpcinterface.Endpoint, opt interface{}) (*rpcinterface.Request, error) { | ||
return s.client.NewRequest(rpcinterface.ServiceDaemon, rpcEndpoint, opt) | ||
} | ||
|
||
// Do is just a shortcut to the client's Do method | ||
func (s *DaemonService) Do(req *rpcinterface.Request, v interface{}) (*http.Response, error) { | ||
return s.client.Do(req, v) | ||
} | ||
|
||
// GetNetworkInfo gets the network name and prefix from the full node | ||
func (s *DaemonService) 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.