Browse Source

Add TxIndexEnabled method to ResultStatus

pull/412/head
Ethan Frey 8 years ago
parent
commit
a4ee7d25d1
2 changed files with 53 additions and 0 deletions
  1. +15
    -0
      rpc/core/types/responses.go
  2. +38
    -0
      rpc/core/types/responses_test.go

+ 15
- 0
rpc/core/types/responses.go View File

@ -1,6 +1,8 @@
package core_types
import (
"strings"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-p2p"
@ -38,6 +40,19 @@ type ResultStatus struct {
LatestBlockTime int64 `json:"latest_block_time"` // nano
}
func (s *ResultStatus) TxIndexEnabled() bool {
if s == nil || s.NodeInfo == nil {
return false
}
for _, s := range s.NodeInfo.Other {
info := strings.Split(s, "=")
if len(info) == 2 && info[0] == "tx_indexer" {
return info[1] == "kv"
}
}
return false
}
type ResultNetInfo struct {
Listening bool `json:"listening"`
Listeners []string `json:"listeners"`


+ 38
- 0
rpc/core/types/responses_test.go View File

@ -0,0 +1,38 @@
package core_types
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tendermint/go-p2p"
)
func TestStatusIndexer(t *testing.T) {
assert := assert.New(t)
var status *ResultStatus
assert.False(status.TxIndexEnabled())
status = &ResultStatus{}
assert.False(status.TxIndexEnabled())
status.NodeInfo = &p2p.NodeInfo{}
assert.False(status.TxIndexEnabled())
cases := []struct {
expected bool
other []string
}{
{false, nil},
{false, []string{}},
{false, []string{"a=b"}},
{false, []string{"tx_indexeriskv", "some=dood"}},
{true, []string{"tx_indexer=kv", "tx_indexer=other"}},
{true, []string{"^(*^(", "tx_indexer=kv", "a=n=b=d="}},
}
for _, tc := range cases {
status.NodeInfo.Other = tc.other
assert.Equal(tc.expected, status.TxIndexEnabled())
}
}

Loading…
Cancel
Save