diff --git a/bitcoin/client.go b/bitcoin/client.go index bdb1efd..ff21196 100644 --- a/bitcoin/client.go +++ b/bitcoin/client.go @@ -161,32 +161,6 @@ func newHTTPClient(timeout time.Duration) *http.Client { return httpClient } -// NetworkStatus returns the *types.NetworkStatusResponse for -// bitcoind. -func (b *Client) NetworkStatus(ctx context.Context) (*types.NetworkStatusResponse, error) { - rawBlock, err := b.getBlock(ctx, nil) - if err != nil { - return nil, fmt.Errorf("%w: unable to get current block", err) - } - - currentBlock, err := b.parseBlockData(rawBlock) - if err != nil { - return nil, fmt.Errorf("%w: unable to parse current block", err) - } - - peers, err := b.GetPeers(ctx) - if err != nil { - return nil, err - } - - return &types.NetworkStatusResponse{ - CurrentBlockIdentifier: currentBlock.BlockIdentifier, - CurrentBlockTimestamp: currentBlock.Timestamp, - GenesisBlockIdentifier: b.genesisBlockIdentifier, - Peers: peers, - }, nil -} - // GetPeers fetches the list of peer nodes func (b *Client) GetPeers(ctx context.Context) ([]*types.Peer, error) { info, err := b.getPeerInfo(ctx) diff --git a/mocks/services/client.go b/mocks/services/client.go index 838124f..a47044e 100644 --- a/mocks/services/client.go +++ b/mocks/services/client.go @@ -15,16 +15,16 @@ type Client struct { mock.Mock } -// NetworkStatus provides a mock function with given fields: _a0 -func (_m *Client) NetworkStatus(_a0 context.Context) (*types.NetworkStatusResponse, error) { +// GetPeers provides a mock function with given fields: _a0 +func (_m *Client) GetPeers(_a0 context.Context) ([]*types.Peer, error) { ret := _m.Called(_a0) - var r0 *types.NetworkStatusResponse - if rf, ok := ret.Get(0).(func(context.Context) *types.NetworkStatusResponse); ok { + var r0 []*types.Peer + if rf, ok := ret.Get(0).(func(context.Context) []*types.Peer); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*types.NetworkStatusResponse) + r0 = ret.Get(0).([]*types.Peer) } } diff --git a/services/network_service.go b/services/network_service.go index 0d1932b..92046cc 100644 --- a/services/network_service.go +++ b/services/network_service.go @@ -65,7 +65,7 @@ func (s *NetworkAPIService) NetworkStatus( return nil, wrapErr(ErrUnavailableOffline, nil) } - rawStatus, err := s.client.NetworkStatus(ctx) + peers, err := s.client.GetPeers(ctx) if err != nil { return nil, wrapErr(ErrBitcoind, err) } @@ -75,9 +75,12 @@ func (s *NetworkAPIService) NetworkStatus( return nil, wrapErr(ErrNotReady, nil) } - rawStatus.CurrentBlockIdentifier = cachedBlockResponse.Block.BlockIdentifier - - return rawStatus, nil + return &types.NetworkStatusResponse{ + CurrentBlockIdentifier: cachedBlockResponse.Block.BlockIdentifier, + CurrentBlockTimestamp: cachedBlockResponse.Block.Timestamp, + GenesisBlockIdentifier: s.config.GenesisBlockIdentifier, + Peers: peers, + }, nil } // NetworkOptions implements the /network/options endpoint. diff --git a/services/types.go b/services/types.go index 158c0b3..feebdf5 100644 --- a/services/types.go +++ b/services/types.go @@ -44,7 +44,7 @@ var ( // Client is used by the servicers to get Peer information // and to submit transactions. type Client interface { - NetworkStatus(context.Context) (*types.NetworkStatusResponse, error) + GetPeers(context.Context) ([]*types.Peer, error) SendRawTransaction(context.Context, string) (string, error) SuggestedFeeRate(context.Context, int64) (float64, error) RawMempool(context.Context) ([]string, error)