From 8b8c7bcf05b38d6e43448bc4b3e0cff84cbaa7df Mon Sep 17 00:00:00 2001 From: pedro martelletto Date: Mon, 16 Jan 2017 11:50:29 +0000 Subject: [PATCH] Implement DisconnectBlock() for the CBF Indexer --- blockchain/indexers/cbfindex.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/blockchain/indexers/cbfindex.go b/blockchain/indexers/cbfindex.go index 178c8871..e09505c8 100644 --- a/blockchain/indexers/cbfindex.go +++ b/blockchain/indexers/cbfindex.go @@ -152,8 +152,15 @@ func (idx *CBFIndex) ConnectBlock(dbTx database.Tx, block *btcutil.Block, // mapping for every passed block. // // This is part of the Indexer interface. -func (idx *CBFIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, view *blockchain.UtxoViewpoint) error { - return nil +func (idx *CBFIndex) DisconnectBlock(dbTx database.Tx, block *btcutil.Block, + view *blockchain.UtxoViewpoint) error { + index := dbTx.Metadata().Bucket(cbfIndexKey) + filterBytes := index.Get(block.Hash().CloneBytes()) + if len(filterBytes) == 0 { + return fmt.Errorf("can't remove non-existent filter %s from " + + "the cbfilter index", block.Hash()) + } + return index.Delete(block.Hash().CloneBytes()) } func (idx *CBFIndex) GetFilterByBlockHash(hash *chainhash.Hash) ([]byte,