diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index 5228a3c4..ad108069 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -84,12 +84,23 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { // Index indexes a single transaction using the given list of tags. func (txi *TxIndex) Index(result *types.TxResult) error { - batch := txindex.NewBatch(1) - err := batch.Add(result) - if err != nil { - return errors.Wrap(err, "failed to add tx result to batch") + b := txi.store.NewBatch() + + hash := result.Tx.Hash() + + // index tx by tags + for _, tag := range result.Result.Tags { + if cmn.StringInSlice(tag.Key, txi.tagsToIndex) { + b.Set(keyForTag(tag, result), hash) + } } - return txi.AddBatch(batch) + + // index tx by hash + rawBytes := wire.BinaryBytes(result) + b.Set(hash, rawBytes) + + b.Write() + return nil } // Search performs a search using the given query. It breaks the query into