chainfee: simplify WebAPIFeeSource interface
This commit removes the interface methods `GenQueryURL` and `ParseResponse` so the `WebAPIEstimator` can care less about the implementation details of this interface.
This commit is contained in:
2 files changed
+13
-48
No files matched your search
@@ -493,16 +493,6 @@ var _ Estimator = (*BitcoindEstimator)(nil)
|
||||
// implementation of this interface in order to allow the WebAPIEstimator to
|
||||
// be fully generic in its logic.
|
||||
type WebAPIFeeSource interface {
|
||||
// GenQueryURL generates the full query URL. The value returned by this
|
||||
// method should be able to be used directly as a path for an HTTP GET
|
||||
// request.
|
||||
GenQueryURL() string
|
||||
|
||||
// ParseResponse attempts to parse the body of the response generated
|
||||
// by the above query URL. Typically this will be JSON, but the
|
||||
// specifics are left to the WebAPIFeeSource implementation.
|
||||
ParseResponse(r io.Reader) (map[uint32]uint32, error)
|
||||
|
||||
// GetFeeMap will query the web API, parse the response and return a
|
||||
// map of confirmation targets to sat/kw fees.
|
||||
GetFeeMap() (map[uint32]uint32, error)
|
||||
@@ -517,21 +507,12 @@ type SparseConfFeeSource struct {
|
||||
URL string
|
||||
}
|
||||
|
||||
// GenQueryURL generates the full query URL. The value returned by this
|
||||
// method should be able to be used directly as a path for an HTTP GET
|
||||
// request.
|
||||
//
|
||||
// NOTE: Part of the WebAPIFeeSource interface.
|
||||
func (s SparseConfFeeSource) GenQueryURL() string {
|
||||
return s.URL
|
||||
}
|
||||
|
||||
// ParseResponse attempts to parse the body of the response generated by the
|
||||
// parseResponse attempts to parse the body of the response generated by the
|
||||
// above query URL. Typically this will be JSON, but the specifics are left to
|
||||
// the WebAPIFeeSource implementation.
|
||||
//
|
||||
// NOTE: Part of the WebAPIFeeSource interface.
|
||||
func (s SparseConfFeeSource) ParseResponse(r io.Reader) (map[uint32]uint32, error) {
|
||||
func (s SparseConfFeeSource) parseResponse(r io.Reader) (
|
||||
map[uint32]uint32, error) {
|
||||
|
||||
type jsonResp struct {
|
||||
FeeByBlockTarget map[uint32]uint32 `json:"fee_by_block_target"`
|
||||
}
|
||||
@@ -567,7 +548,7 @@ func (s SparseConfFeeSource) GetFeeMap() (map[uint32]uint32, error) {
|
||||
|
||||
// With the client created, we'll query the API source to fetch the URL
|
||||
// that we should use to query for the fee estimation.
|
||||
targetURL := s.GenQueryURL()
|
||||
targetURL := s.URL
|
||||
resp, err := netClient.Get(targetURL)
|
||||
if err != nil {
|
||||
log.Errorf("unable to query web api for fee response: %v",
|
||||
@@ -578,7 +559,7 @@ func (s SparseConfFeeSource) GetFeeMap() (map[uint32]uint32, error) {
|
||||
|
||||
// Once we've obtained the response, we'll instruct the WebAPIFeeSource
|
||||
// to parse out the body to obtain our final result.
|
||||
feesByBlockTarget, err := s.ParseResponse(resp.Body)
|
||||
feesByBlockTarget, err := s.parseResponse(resp.Body)
|
||||
if err != nil {
|
||||
log.Errorf("unable to parse fee api response: %v", err)
|
||||
|
||||
|
||||
Reference in new issue
Block a user