mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-04 11:02:13 +00:00
Add TxIndexEnabled method to ResultStatus
This commit is contained in:
parent
58c860ba11
commit
a4ee7d25d1
@ -1,6 +1,8 @@
|
|||||||
package core_types
|
package core_types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/go-p2p"
|
"github.com/tendermint/go-p2p"
|
||||||
@ -38,6 +40,19 @@ type ResultStatus struct {
|
|||||||
LatestBlockTime int64 `json:"latest_block_time"` // nano
|
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 {
|
type ResultNetInfo struct {
|
||||||
Listening bool `json:"listening"`
|
Listening bool `json:"listening"`
|
||||||
Listeners []string `json:"listeners"`
|
Listeners []string `json:"listeners"`
|
||||||
|
38
rpc/core/types/responses_test.go
Normal file
38
rpc/core/types/responses_test.go
Normal 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…
x
Reference in New Issue
Block a user