@ -1,21 +0,0 @@ | |||
package tx | |||
import ( | |||
txindexer "github.com/tendermint/tendermint/state/tx/indexer" | |||
"github.com/tendermint/tendermint/types" | |||
) | |||
// Indexer interface defines methods to index and search transactions. | |||
type Indexer interface { | |||
// Batch analyzes, indexes or stores a batch of transactions. | |||
// | |||
// NOTE We do not specify Index method for analyzing a single transaction | |||
// here because it bears heavy perfomance loses. Almost all advanced indexers | |||
// support batching. | |||
Batch(b *txindexer.Batch) error | |||
// Tx returns specified transaction or nil if the transaction is not indexed | |||
// or stored. | |||
Tx(hash []byte) (*types.TxResult, error) | |||
} |
@ -1,32 +0,0 @@ | |||
package indexer | |||
import "github.com/tendermint/tendermint/types" | |||
// A Batch groups together multiple Index operations you would like performed | |||
// at the same time. The Batch structure is NOT thread-safe. You should only | |||
// perform operations on a batch from a single thread at a time. Once batch | |||
// execution has started, you may not modify it. | |||
type Batch struct { | |||
Ops map[string]types.TxResult | |||
} | |||
// NewBatch creates a new Batch. | |||
func NewBatch() *Batch { | |||
return &Batch{ | |||
Ops: make(map[string]types.TxResult), | |||
} | |||
} | |||
// Index adds or updates entry for the given hash. | |||
func (b *Batch) Index(hash []byte, result types.TxResult) error { | |||
if len(hash) == 0 { | |||
return ErrorEmptyHash | |||
} | |||
b.Ops[string(hash)] = result | |||
return nil | |||
} | |||
// Size returns the total number of operations inside the batch. | |||
func (b *Batch) Size() int { | |||
return len(b.Ops) | |||
} |
@ -1,6 +0,0 @@ | |||
package indexer | |||
import "errors" | |||
// ErrorEmptyHash indicates empty hash | |||
var ErrorEmptyHash = errors.New("Transaction hash cannot be empty") |
@ -1,19 +0,0 @@ | |||
package indexer | |||
import ( | |||
"errors" | |||
"github.com/tendermint/tendermint/types" | |||
) | |||
// Null acts as a /dev/null. | |||
type Null struct{} | |||
// Tx panics. | |||
func (indexer *Null) Tx(hash []byte) (*types.TxResult, error) { | |||
return nil, errors.New(`Indexing is disabled (set 'tx_indexer = "kv"' in config)`) | |||
} | |||
// Batch returns nil. | |||
func (indexer *Null) Batch(batch *Batch) error { | |||
return nil | |||
} |
@ -0,0 +1,60 @@ | |||
package txindex | |||
import ( | |||
"errors" | |||
"github.com/tendermint/tendermint/types" | |||
) | |||
// Indexer interface defines methods to index and search transactions. | |||
type TxIndexer interface { | |||
// Batch analyzes, indexes or stores a batch of transactions. | |||
// | |||
// NOTE We do not specify Index method for analyzing a single transaction | |||
// here because it bears heavy perfomance loses. Almost all advanced indexers | |||
// support batching. | |||
AddBatch(b *Batch) error | |||
// Tx returns specified transaction or nil if the transaction is not indexed | |||
// or stored. | |||
Get(hash []byte) (*types.TxResult, error) | |||
} | |||
//---------------------------------------------------- | |||
// Txs are written as a batch | |||
// A Batch groups together multiple Index operations you would like performed | |||
// at the same time. The Batch structure is NOT thread-safe. You should only | |||
// perform operations on a batch from a single thread at a time. Once batch | |||
// execution has started, you may not modify it. | |||
type Batch struct { | |||
Ops map[string]types.TxResult | |||
} | |||
// NewBatch creates a new Batch. | |||
func NewBatch() *Batch { | |||
return &Batch{ | |||
Ops: make(map[string]types.TxResult), | |||
} | |||
} | |||
// Index adds or updates entry for the given hash. | |||
func (b *Batch) Index(hash []byte, result types.TxResult) error { | |||
if len(hash) == 0 { | |||
return ErrorEmptyHash | |||
} | |||
b.Ops[string(hash)] = result | |||
return nil | |||
} | |||
// Size returns the total number of operations inside the batch. | |||
func (b *Batch) Size() int { | |||
return len(b.Ops) | |||
} | |||
//---------------------------------------------------- | |||
// Errors | |||
// ErrorEmptyHash indicates empty hash | |||
var ErrorEmptyHash = errors.New("Transaction hash cannot be empty") |
@ -0,0 +1,21 @@ | |||
package null | |||
import ( | |||
"errors" | |||
"github.com/tendermint/tendermint/state/txindex" | |||
"github.com/tendermint/tendermint/types" | |||
) | |||
// TxIndex acts as a /dev/null. | |||
type TxIndex struct{} | |||
// Tx panics. | |||
func (txi *TxIndex) Get(hash []byte) (*types.TxResult, error) { | |||
return nil, errors.New(`Indexing is disabled (set 'tx_indexer = "kv"' in config)`) | |||
} | |||
// Batch returns nil. | |||
func (txi *TxIndex) AddBatch(batch *txindex.Batch) error { | |||
return nil | |||
} |