From 837a99fa37d4565a3a7b3b9ea84bc1d5d7daef2f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 15 Jun 2022 17:22:28 -0700 Subject: [PATCH] mempool updates --- frontend/service.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/service.go b/frontend/service.go index 36f94fc..392ddfb 100644 --- a/frontend/service.go +++ b/frontend/service.go @@ -22,6 +22,8 @@ import ( "git.hush.is/duke/lightwalletd/parser" ) + + type lwdStreamer struct { cache *common.BlockCache chainName string @@ -29,6 +31,11 @@ type lwdStreamer struct { walletrpc.UnimplementedCompactTxStreamerServer } +// NewLwdStreamer constructs a gRPC context. +func NewLwdStreamer(cache *common.BlockCache, chainName string, enablePing bool) (walletrpc.CompactTxStreamerServer, error) { + return &lwdStreamer{cache: cache, chainName: chainName, pingEnable: enablePing}, nil +} + var ( ErrUnspecified = errors.New("request for unspecified identifier") ) @@ -52,15 +59,16 @@ func (s *SqlStreamer) GetCache() *common.BlockCache { return s.cache } -func (s *SqlStreamer) GetLatestBlock(ctx context.Context, placeholder *walletrpc.ChainSpec) (*walletrpc.BlockID, error) { - latestBlock := s.cache.GetLatestBlock() +// GetLatestBlock returns the height of the best chain according to hushd +func (s *lwdStreamer) GetLatestBlock(ctx context.Context, placeholder *walletrpc.ChainSpec) (*walletrpc.BlockID, error) { + latestBlock := s.cache.GetLatestHeight() + latestHash := s.cache.GetLatestHash() if latestBlock == -1 { - return nil, errors.New("Cache is empty. Server is probably not yet ready.") + return nil, errors.New("Cache is empty. Server is probably not yet ready") } - // TODO: also return block hashes here - return &walletrpc.BlockID{Height: uint64(latestBlock)}, nil + return &walletrpc.BlockID{Height: uint64(latestBlock), Hash: latestHash}, nil } func (s *SqlStreamer) GetAddressTxids(addressBlockFilter *walletrpc.TransparentAddressBlockFilter, resp walletrpc.CompactTxStreamer_GetAddressTxidsServer) error {