From 1ddb9f2c116f9724ea8acb9b3320074c8f85e488 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 12 Sep 2018 14:24:30 -0700 Subject: [PATCH] chain: allow setting the client's birthday after creation --- chain/bitcoind_client.go | 12 ++++++++++++ chain/bitcoind_conn.go | 6 ++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/chain/bitcoind_client.go b/chain/bitcoind_client.go index 75cc078..f285fd0 100644 --- a/chain/bitcoind_client.go +++ b/chain/bitcoind_client.go @@ -108,6 +108,10 @@ type BitcoindClient struct { wg sync.WaitGroup } +// A compile-time check to ensure that BitcoindClient satisfies the +// chain.Interface interface. +var _ Interface = (*BitcoindClient)(nil) + // BackEnd returns the name of the driver. func (c *BitcoindClient) BackEnd() string { return "bitcoind" @@ -596,6 +600,14 @@ func (c *BitcoindClient) ntfnHandler() { } } +// SetBirthday sets the birthday of the bitcoind rescan client. +// +// NOTE: This should be done before the client has been started in order for it +// to properly carry its duties. +func (c *BitcoindClient) SetBirthday(t time.Time) { + c.birthday = t +} + // BlockStamp returns the latest block notified by the client, or an error // if the client has been shut down. func (c *BitcoindClient) BlockStamp() (*waddrmgr.BlockStamp, error) { diff --git a/chain/bitcoind_conn.go b/chain/bitcoind_conn.go index 845df22..e89631c 100644 --- a/chain/bitcoind_conn.go +++ b/chain/bitcoind_conn.go @@ -333,15 +333,13 @@ func (c *BitcoindConn) getCurrentNet() (wire.BitcoinNet, error) { // NewBitcoindClient returns a bitcoind client using the current bitcoind // connection. This allows us to share the same connection using multiple -// clients. The birthday signifies the earliest time for which we should begin -// scanning the chain. -func (c *BitcoindConn) NewBitcoindClient(birthday time.Time) *BitcoindClient { +// clients. +func (c *BitcoindConn) NewBitcoindClient() *BitcoindClient { return &BitcoindClient{ quit: make(chan struct{}), id: atomic.AddUint64(&c.rescanClientCounter, 1), - birthday: birthday, chainParams: c.chainParams, chainConn: c,