@@ -34,15 +34,27 @@ const (
3434 RegularFilter FilterType = iota
3535)
3636
37+ // FilterData holds all the info about a filter required to store it.
38+ type FilterData struct {
39+ // Filter is the actual filter to be stored.
40+ Filter * gcs.Filter
41+
42+ // BlockHash is the block header hash of the block associated with the
43+ // Filter.
44+ BlockHash * chainhash.Hash
45+
46+ // Type is the filter type.
47+ Type FilterType
48+ }
49+
3750// FilterDatabase is an interface which represents an object that is capable of
3851// storing and retrieving filters according to their corresponding block hash
3952// and also their filter type.
4053//
4154// TODO(roasbeef): similar interface for headerfs?
4255type FilterDatabase interface {
43- // PutFilter stores a filter with the given hash and type to persistent
44- // storage.
45- PutFilter (* chainhash.Hash , * gcs.Filter , FilterType ) error
56+ // PutFilter stores a filter to persistent storage.
57+ PutFilter (* FilterData ) error
4658
4759 // FetchFilter attempts to fetch a filter with the given hash and type
4860 // from persistent storage. In the case that a filter matching the
@@ -155,30 +167,22 @@ func putFilter(bucket walletdb.ReadWriteBucket, hash *chainhash.Hash,
155167// storage.
156168//
157169// NOTE: This method is a part of the FilterDatabase interface.
158- func (f * FilterStore ) PutFilter (hash * chainhash.Hash ,
159- filter * gcs.Filter , fType FilterType ) error {
160-
170+ func (f * FilterStore ) PutFilter (filterData * FilterData ) error {
161171 return walletdb .Update (f .db , func (tx walletdb.ReadWriteTx ) error {
162172 filters := tx .ReadWriteBucket (filterBucket )
163173
164174 var targetBucket walletdb.ReadWriteBucket
165- switch fType {
175+ switch filterData . Type {
166176 case RegularFilter :
167177 targetBucket = filters .NestedReadWriteBucket (regBucket )
168178 default :
169- return fmt .Errorf ("unknown filter type: %v" , fType )
179+ return fmt .Errorf ("unknown filter type: %v" ,
180+ filterData .Type )
170181 }
171182
172- if filter == nil {
173- return targetBucket .Put (hash [:], nil )
174- }
175-
176- bytes , err := filter .NBytes ()
177- if err != nil {
178- return err
179- }
180-
181- return targetBucket .Put (hash [:], bytes )
183+ return putFilter (
184+ targetBucket , filterData .BlockHash , filterData .Filter ,
185+ )
182186 })
183187}
184188
0 commit comments