From 2d600fe6ab020193b286cc6f1ef7ac3ce6bdc23d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 14 Jun 2018 22:03:10 -0700 Subject: [PATCH] chain: create new Rescan wrapper for btcd to comply w/ future BIP 158 usage --- chain/rpc.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/chain/rpc.go b/chain/rpc.go index ca2bb16..4c30c12 100644 --- a/chain/rpc.go +++ b/chain/rpc.go @@ -140,6 +140,21 @@ func (c *RPCClient) Stop() { c.quitMtx.Unlock() } +// Rescan wraps the normal Rescan command with an additional paramter that +// allows us to map an oupoint to the address in the chain that it pays to. +// This is useful when using BIP 158 filters as they include the prev pkScript +// rather than the full outpoint. +func (c *RPCClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Address, + outPoints map[wire.OutPoint]btcutil.Address) error { + + flatOutpoints := make([]*wire.OutPoint, 0, len(outPoints)) + for ops := range outPoints { + flatOutpoints = append(flatOutpoints, &ops) + } + + return c.Client.Rescan(startHash, addrs, flatOutpoints) +} + // WaitForShutdown blocks until both the client has finished disconnecting // and all handlers have exited. func (c *RPCClient) WaitForShutdown() { @@ -200,7 +215,9 @@ func (c *RPCClient) FilterBlocks( continue } - filter, err := gcs.FromNBytes(builder.DefaultP, rawFilter.Data) + filter, err := gcs.FromNBytes( + builder.DefaultP, builder.DefaultM, rawFilter.Data, + ) if err != nil { return nil, err }