Get current block from indexer instead of bitcoind
This commit is contained in:
parent
f4ca8b1318
commit
b72461dbee
4 changed files with 13 additions and 36 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue