chain: allow setting the client's birthday after creation

This commit is contained in:
Wilmer Paulino 2018-09-12 14:24:30 -07:00
parent f4ae41ce5f
commit 1ddb9f2c11
No known key found for this signature in database
GPG key ID: 6DF57B9F9514972F
2 changed files with 14 additions and 4 deletions

View file

@ -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) {

View file

@ -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,