expose /tx?hash="XXXXXXXXXXXX" RPC call

This commit is contained in:
Anton Kaliaev
2017-04-10 22:44:07 +04:00
parent b08f29cb71
commit 63704454a3
9 changed files with 88 additions and 145 deletions
+3 -1
View File
@@ -1,6 +1,7 @@
package state
import (
"encoding/hex"
"errors"
"fmt"
@@ -251,7 +252,8 @@ func (s *State) ApplyBlock(eventCache types.Fireable, proxyAppConn proxy.AppConn
for i, r := range txResults {
if r != nil {
tx := block.Txs[i]
batch.Index(string(tx.Hash()), *r)
// dd2e325f79f7e5f77788759d278c1d4b370c842e => {"height":2405, "index":0, ...}
batch.Index(hex.EncodeToString(tx.Hash()), *r)
}
}
s.TxIndexer.Batch(batch)
+1 -11
View File
@@ -44,13 +44,12 @@ type State struct {
TxIndexer tx.Indexer `json:"-"` // Transaction indexer.
}
// Used in tests.
func LoadState(db dbm.DB) *State {
return loadState(db, stateKey)
}
func loadState(db dbm.DB, key []byte) *State {
s := &State{db: db}
s := &State{db: db, TxIndexer: &txindexer.Null{}}
buf := db.Get(key)
if len(buf) == 0 {
return nil
@@ -132,15 +131,6 @@ func GetState(config cfg.Config, stateDB dbm.DB) *State {
state.Save()
}
// Transaction indexing
switch config.GetString("tx_indexer") {
case "kv":
store := dbm.NewDB("tx_indexer", config.GetString("db_backend"), config.GetString("db_dir"))
state.TxIndexer = txindexer.NewKV(store)
default:
state.TxIndexer = &txindexer.Null{}
}
return state
}
+5 -2
View File
@@ -1,13 +1,16 @@
package indexer
import "github.com/tendermint/tendermint/types"
import (
"errors"
"github.com/tendermint/tendermint/types"
)
// Null acts as a /dev/null.
type Null struct{}
// Tx panics.
func (indexer *Null) Tx(hash string) (*types.TxResult, error) {
panic("You are trying to get the transaction from a null indexer")
return nil, errors.New("Indexing is disabled (set `tx_indexer=kv` in config)")
}
// Batch returns nil.