mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-04 17:11:19 +00:00
Fix rpc tests
This commit is contained in:
parent
c541d58d2f
commit
3ca5292dc9
6
Gopkg.lock
generated
6
Gopkg.lock
generated
@ -254,8 +254,8 @@
|
|||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/tendermint/go-amino"
|
name = "github.com/tendermint/go-amino"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "26718ab6738f938d4b33d593543cee7681f2a6a6"
|
revision = "42246108ff925a457fb709475070a03dfd3e2b5c"
|
||||||
version = "0.9.5"
|
version = "0.9.6"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/tendermint/go-crypto"
|
name = "github.com/tendermint/go-crypto"
|
||||||
@ -383,6 +383,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "0dacd2eb1550ca01e0c64f77b721eda1a381dde1d246a56bfe5a2746b78b7bad"
|
inputs-digest = "d14dbd59436d0ea3b322c42ce33c213b26cd2451ba023a466764b8002e0e649d"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
@ -79,7 +79,7 @@
|
|||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/tendermint/go-amino"
|
name = "github.com/tendermint/go-amino"
|
||||||
version = "0.9.5"
|
version = "0.9.6"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "github.com/tendermint/tmlibs"
|
name = "github.com/tendermint/tmlibs"
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/p2p/trust"
|
"github.com/tendermint/tendermint/p2p/trust"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
rpccore "github.com/tendermint/tendermint/rpc/core"
|
rpccore "github.com/tendermint/tendermint/rpc/core"
|
||||||
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
grpccore "github.com/tendermint/tendermint/rpc/grpc"
|
grpccore "github.com/tendermint/tendermint/rpc/grpc"
|
||||||
rpc "github.com/tendermint/tendermint/rpc/lib"
|
rpc "github.com/tendermint/tendermint/rpc/lib"
|
||||||
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
|
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
|
||||||
@ -489,6 +490,8 @@ func (n *Node) ConfigureRPC() {
|
|||||||
func (n *Node) startRPC() ([]net.Listener, error) {
|
func (n *Node) startRPC() ([]net.Listener, error) {
|
||||||
n.ConfigureRPC()
|
n.ConfigureRPC()
|
||||||
listenAddrs := strings.Split(n.config.RPC.ListenAddress, ",")
|
listenAddrs := strings.Split(n.config.RPC.ListenAddress, ",")
|
||||||
|
coreCodec := amino.NewCodec()
|
||||||
|
ctypes.RegisterAmino(coreCodec)
|
||||||
|
|
||||||
if n.config.RPC.Unsafe {
|
if n.config.RPC.Unsafe {
|
||||||
rpccore.AddUnsafeRoutes()
|
rpccore.AddUnsafeRoutes()
|
||||||
@ -499,10 +502,10 @@ func (n *Node) startRPC() ([]net.Listener, error) {
|
|||||||
for i, listenAddr := range listenAddrs {
|
for i, listenAddr := range listenAddrs {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
rpcLogger := n.Logger.With("module", "rpc-server")
|
rpcLogger := n.Logger.With("module", "rpc-server")
|
||||||
wm := rpcserver.NewWebsocketManager(rpccore.Routes, rpccore.RoutesCodec, rpcserver.EventSubscriber(n.eventBus))
|
wm := rpcserver.NewWebsocketManager(rpccore.Routes, coreCodec, rpcserver.EventSubscriber(n.eventBus))
|
||||||
wm.SetLogger(rpcLogger.With("protocol", "websocket"))
|
wm.SetLogger(rpcLogger.With("protocol", "websocket"))
|
||||||
mux.HandleFunc("/websocket", wm.WebsocketHandler)
|
mux.HandleFunc("/websocket", wm.WebsocketHandler)
|
||||||
rpcserver.RegisterRPCFuncs(mux, rpccore.Routes, rpccore.RoutesCodec, rpcLogger)
|
rpcserver.RegisterRPCFuncs(mux, rpccore.Routes, coreCodec, rpcLogger)
|
||||||
listener, err := rpcserver.StartHTTPServer(listenAddr, mux, rpcLogger)
|
listener, err := rpcserver.StartHTTPServer(listenAddr, mux, rpcLogger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
package client_test
|
package client_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/rpc/client"
|
"github.com/tendermint/tendermint/rpc/client"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var waitForEventTimeout = 5 * time.Second
|
var waitForEventTimeout = 5 * time.Second
|
||||||
@ -23,116 +23,127 @@ func MakeTxKV() ([]byte, []byte, []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHeaderEvents(t *testing.T) {
|
func TestHeaderEvents(t *testing.T) {
|
||||||
require := require.New(t)
|
|
||||||
for i, c := range GetClients() {
|
for i, c := range GetClients() {
|
||||||
// start for this test it if it wasn't already running
|
i, c := i, c // capture params
|
||||||
if !c.IsRunning() {
|
t.Run(reflect.TypeOf(c).String(), func(t *testing.T) {
|
||||||
// if so, then we start it, listen, and stop it.
|
// start for this test it if it wasn't already running
|
||||||
err := c.Start()
|
if !c.IsRunning() {
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
// if so, then we start it, listen, and stop it.
|
||||||
defer c.Stop()
|
err := c.Start()
|
||||||
}
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
|
defer c.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
evtTyp := types.EventNewBlockHeader
|
evtTyp := types.EventNewBlockHeader
|
||||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
_, ok := evt.(types.EventDataNewBlockHeader)
|
_, ok := evt.(types.EventDataNewBlockHeader)
|
||||||
require.True(ok, "%d: %#v", i, evt)
|
require.True(t, ok, "%d: %#v", i, evt)
|
||||||
// TODO: more checks...
|
// TODO: more checks...
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockEvents(t *testing.T) {
|
func TestBlockEvents(t *testing.T) {
|
||||||
require := require.New(t)
|
|
||||||
for i, c := range GetClients() {
|
for i, c := range GetClients() {
|
||||||
// start for this test it if it wasn't already running
|
i, c := i, c // capture params
|
||||||
if !c.IsRunning() {
|
t.Run(reflect.TypeOf(c).String(), func(t *testing.T) {
|
||||||
// if so, then we start it, listen, and stop it.
|
|
||||||
err := c.Start()
|
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
|
||||||
defer c.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// listen for a new block; ensure height increases by 1
|
// start for this test it if it wasn't already running
|
||||||
var firstBlockHeight int64
|
if !c.IsRunning() {
|
||||||
for j := 0; j < 3; j++ {
|
// if so, then we start it, listen, and stop it.
|
||||||
evtTyp := types.EventNewBlock
|
err := c.Start()
|
||||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
require.Nil(err, "%d: %+v", j, err)
|
defer c.Stop()
|
||||||
blockEvent, ok := evt.(types.EventDataNewBlock)
|
|
||||||
require.True(ok, "%d: %#v", j, evt)
|
|
||||||
|
|
||||||
block := blockEvent.Block
|
|
||||||
if j == 0 {
|
|
||||||
firstBlockHeight = block.Header.Height
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(block.Header.Height, firstBlockHeight+int64(j))
|
// listen for a new block; ensure height increases by 1
|
||||||
}
|
var firstBlockHeight int64
|
||||||
|
for j := 0; j < 3; j++ {
|
||||||
|
evtTyp := types.EventNewBlock
|
||||||
|
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||||
|
require.Nil(t, err, "%d: %+v", j, err)
|
||||||
|
blockEvent, ok := evt.(types.EventDataNewBlock)
|
||||||
|
require.True(t, ok, "%d: %#v", j, evt)
|
||||||
|
|
||||||
|
block := blockEvent.Block
|
||||||
|
if j == 0 {
|
||||||
|
firstBlockHeight = block.Header.Height
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Equal(t, block.Header.Height, firstBlockHeight+int64(j))
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
|
func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
|
||||||
require := require.New(t)
|
|
||||||
for i, c := range GetClients() {
|
for i, c := range GetClients() {
|
||||||
// start for this test it if it wasn't already running
|
i, c := i, c // capture params
|
||||||
if !c.IsRunning() {
|
t.Run(reflect.TypeOf(c).String(), func(t *testing.T) {
|
||||||
// if so, then we start it, listen, and stop it.
|
|
||||||
err := c.Start()
|
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
|
||||||
defer c.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// make the tx
|
// start for this test it if it wasn't already running
|
||||||
_, _, tx := MakeTxKV()
|
if !c.IsRunning() {
|
||||||
evtTyp := types.EventTx
|
// if so, then we start it, listen, and stop it.
|
||||||
|
err := c.Start()
|
||||||
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
|
defer c.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
// send async
|
// make the tx
|
||||||
txres, err := c.BroadcastTxAsync(tx)
|
_, _, tx := MakeTxKV()
|
||||||
require.Nil(err, "%+v", err)
|
evtTyp := types.EventTx
|
||||||
require.Equal(txres.Code, abci.CodeTypeOK) // FIXME
|
|
||||||
|
|
||||||
// and wait for confirmation
|
// send async
|
||||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
txres, err := c.BroadcastTxAsync(tx)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
require.Nil(t, err, "%+v", err)
|
||||||
// and make sure it has the proper info
|
require.Equal(t, txres.Code, abci.CodeTypeOK) // FIXME
|
||||||
txe, ok := evt.(types.EventDataTx)
|
|
||||||
require.True(ok, "%d: %#v", i, evt)
|
// and wait for confirmation
|
||||||
// make sure this is the proper tx
|
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||||
require.EqualValues(tx, txe.Tx)
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
require.True(txe.Result.IsOK())
|
// and make sure it has the proper info
|
||||||
|
txe, ok := evt.(types.EventDataTx)
|
||||||
|
require.True(t, ok, "%d: %#v", i, evt)
|
||||||
|
// make sure this is the proper tx
|
||||||
|
require.EqualValues(t, tx, txe.Tx)
|
||||||
|
require.True(t, txe.Result.IsOK())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTxEventsSentWithBroadcastTxSync(t *testing.T) {
|
func TestTxEventsSentWithBroadcastTxSync(t *testing.T) {
|
||||||
require := require.New(t)
|
|
||||||
for i, c := range GetClients() {
|
for i, c := range GetClients() {
|
||||||
// start for this test it if it wasn't already running
|
i, c := i, c // capture params
|
||||||
if !c.IsRunning() {
|
t.Run(reflect.TypeOf(c).String(), func(t *testing.T) {
|
||||||
// if so, then we start it, listen, and stop it.
|
|
||||||
err := c.Start()
|
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
|
||||||
defer c.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// make the tx
|
// start for this test it if it wasn't already running
|
||||||
_, _, tx := MakeTxKV()
|
if !c.IsRunning() {
|
||||||
evtTyp := types.EventTx
|
// if so, then we start it, listen, and stop it.
|
||||||
|
err := c.Start()
|
||||||
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
|
defer c.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
// send sync
|
// make the tx
|
||||||
txres, err := c.BroadcastTxSync(tx)
|
_, _, tx := MakeTxKV()
|
||||||
require.Nil(err, "%+v", err)
|
evtTyp := types.EventTx
|
||||||
require.Equal(txres.Code, abci.CodeTypeOK) // FIXME
|
|
||||||
|
|
||||||
// and wait for confirmation
|
// send sync
|
||||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
txres, err := c.BroadcastTxSync(tx)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
require.Nil(t, err, "%+v", err)
|
||||||
// and make sure it has the proper info
|
require.Equal(t, txres.Code, abci.CodeTypeOK) // FIXME
|
||||||
txe, ok := evt.(types.EventDataTx)
|
|
||||||
require.True(ok, "%d: %#v", i, evt)
|
// and wait for confirmation
|
||||||
// make sure this is the proper tx
|
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||||
require.EqualValues(tx, txe.Tx)
|
require.Nil(t, err, "%d: %+v", i, err)
|
||||||
require.True(txe.Result.IsOK())
|
// and make sure it has the proper info
|
||||||
|
txe, ok := evt.(types.EventDataTx)
|
||||||
|
require.True(t, ok, "%d: %#v", i, evt)
|
||||||
|
// make sure this is the proper tx
|
||||||
|
require.EqualValues(t, tx, txe.Tx)
|
||||||
|
require.True(t, txe.Result.IsOK())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
amino "github.com/tendermint/go-amino"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
|
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
@ -32,10 +32,14 @@ type HTTP struct {
|
|||||||
// New takes a remote endpoint in the form tcp://<host>:<port>
|
// New takes a remote endpoint in the form tcp://<host>:<port>
|
||||||
// and the websocket path (which always seems to be "/websocket")
|
// and the websocket path (which always seems to be "/websocket")
|
||||||
func NewHTTP(remote, wsEndpoint string) *HTTP {
|
func NewHTTP(remote, wsEndpoint string) *HTTP {
|
||||||
|
rc := rpcclient.NewJSONRPCClient(remote)
|
||||||
|
cdc := rc.Codec()
|
||||||
|
ctypes.RegisterAmino(cdc)
|
||||||
|
|
||||||
return &HTTP{
|
return &HTTP{
|
||||||
rpc: rpcclient.NewJSONRPCClient(remote),
|
rpc: rc,
|
||||||
remote: remote,
|
remote: remote,
|
||||||
WSEvents: newWSEvents(remote, wsEndpoint),
|
WSEvents: newWSEvents(cdc, remote, wsEndpoint),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +212,7 @@ func (c *HTTP) Validators(height *int64) (*ctypes.ResultValidators, error) {
|
|||||||
|
|
||||||
type WSEvents struct {
|
type WSEvents struct {
|
||||||
cmn.BaseService
|
cmn.BaseService
|
||||||
|
cdc *amino.Codec
|
||||||
remote string
|
remote string
|
||||||
endpoint string
|
endpoint string
|
||||||
ws *rpcclient.WSClient
|
ws *rpcclient.WSClient
|
||||||
@ -216,8 +221,9 @@ type WSEvents struct {
|
|||||||
subscriptions map[string]chan<- interface{}
|
subscriptions map[string]chan<- interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWSEvents(remote, endpoint string) *WSEvents {
|
func newWSEvents(cdc *amino.Codec, remote, endpoint string) *WSEvents {
|
||||||
wsEvents := &WSEvents{
|
wsEvents := &WSEvents{
|
||||||
|
cdc: cdc,
|
||||||
endpoint: endpoint,
|
endpoint: endpoint,
|
||||||
remote: remote,
|
remote: remote,
|
||||||
subscriptions: make(map[string]chan<- interface{}),
|
subscriptions: make(map[string]chan<- interface{}),
|
||||||
@ -231,6 +237,8 @@ func (w *WSEvents) OnStart() error {
|
|||||||
w.ws = rpcclient.NewWSClient(w.remote, w.endpoint, rpcclient.OnReconnect(func() {
|
w.ws = rpcclient.NewWSClient(w.remote, w.endpoint, rpcclient.OnReconnect(func() {
|
||||||
w.redoSubscriptions()
|
w.redoSubscriptions()
|
||||||
}))
|
}))
|
||||||
|
w.ws.SetCodec(w.cdc)
|
||||||
|
|
||||||
err := w.ws.Start()
|
err := w.ws.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -326,7 +334,7 @@ func (w *WSEvents) eventListener() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result := new(ctypes.ResultEvent)
|
result := new(ctypes.ResultEvent)
|
||||||
err := json.Unmarshal(resp.Result, result)
|
err := w.cdc.UnmarshalJSON(resp.Result, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Logger.Error("failed to unmarshal response", "err", err)
|
w.Logger.Error("failed to unmarshal response", "err", err)
|
||||||
continue
|
continue
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/go-amino"
|
|
||||||
"github.com/tendermint/go-crypto"
|
|
||||||
rpc "github.com/tendermint/tendermint/rpc/lib/server"
|
rpc "github.com/tendermint/tendermint/rpc/lib/server"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: better system than "unsafe" prefix
|
// TODO: better system than "unsafe" prefix
|
||||||
|
// NOTE: Amino is registered in rpc/core/types/wire.go.
|
||||||
var Routes = map[string]*rpc.RPCFunc{
|
var Routes = map[string]*rpc.RPCFunc{
|
||||||
// subscribe/unsubscribe are reserved for websocket events.
|
// subscribe/unsubscribe are reserved for websocket events.
|
||||||
"subscribe": rpc.NewWSRPCFunc(Subscribe, "query"),
|
"subscribe": rpc.NewWSRPCFunc(Subscribe, "query"),
|
||||||
@ -50,14 +48,3 @@ func AddUnsafeRoutes() {
|
|||||||
Routes["unsafe_stop_cpu_profiler"] = rpc.NewRPCFunc(UnsafeStopCPUProfiler, "")
|
Routes["unsafe_stop_cpu_profiler"] = rpc.NewRPCFunc(UnsafeStopCPUProfiler, "")
|
||||||
Routes["unsafe_write_heap_profile"] = rpc.NewRPCFunc(UnsafeWriteHeapProfile, "filename")
|
Routes["unsafe_write_heap_profile"] = rpc.NewRPCFunc(UnsafeWriteHeapProfile, "filename")
|
||||||
}
|
}
|
||||||
|
|
||||||
var RoutesCodec *amino.Codec
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
cdc := amino.NewCodec()
|
|
||||||
RoutesCodec = cdc
|
|
||||||
|
|
||||||
types.RegisterEventDatas(cdc)
|
|
||||||
types.RegisterEvidences(cdc)
|
|
||||||
crypto.RegisterAmino(cdc)
|
|
||||||
}
|
|
||||||
|
13
rpc/core/types/wire.go
Normal file
13
rpc/core/types/wire.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package core_types
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tendermint/go-amino"
|
||||||
|
"github.com/tendermint/go-crypto"
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterAmino(cdc *amino.Codec) {
|
||||||
|
types.RegisterEventDatas(cdc)
|
||||||
|
types.RegisterEvidences(cdc)
|
||||||
|
crypto.RegisterAmino(cdc)
|
||||||
|
}
|
@ -21,6 +21,7 @@ import (
|
|||||||
type HTTPClient interface {
|
type HTTPClient interface {
|
||||||
Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)
|
Call(method string, params map[string]interface{}, result interface{}) (interface{}, error)
|
||||||
Codec() *amino.Codec
|
Codec() *amino.Codec
|
||||||
|
SetCodec(*amino.Codec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Deprecate support for IP:PORT or /path/to/socket
|
// TODO: Deprecate support for IP:PORT or /path/to/socket
|
||||||
@ -111,6 +112,10 @@ func (c *JSONRPCClient) Codec() *amino.Codec {
|
|||||||
return c.cdc
|
return c.cdc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *JSONRPCClient) SetCodec(cdc *amino.Codec) {
|
||||||
|
c.cdc = cdc
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------
|
//-------------------------------------------------------------
|
||||||
|
|
||||||
// URI takes params as a map
|
// URI takes params as a map
|
||||||
@ -152,6 +157,10 @@ func (c *URIClient) Codec() *amino.Codec {
|
|||||||
return c.cdc
|
return c.cdc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *URIClient) SetCodec(cdc *amino.Codec) {
|
||||||
|
c.cdc = cdc
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
|
|
||||||
func unmarshalResponseBytes(cdc *amino.Codec, responseBytes []byte, result interface{}) (interface{}, error) {
|
func unmarshalResponseBytes(cdc *amino.Codec, responseBytes []byte, result interface{}) (interface{}, error) {
|
||||||
|
@ -230,6 +230,10 @@ func (c *WSClient) Codec() *amino.Codec {
|
|||||||
return c.cdc
|
return c.cdc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *WSClient) SetCodec(cdc *amino.Codec) {
|
||||||
|
c.cdc = cdc
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Private methods
|
// Private methods
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
@ -26,11 +27,15 @@ var globalConfig *cfg.Config
|
|||||||
func waitForRPC() {
|
func waitForRPC() {
|
||||||
laddr := GetConfig().RPC.ListenAddress
|
laddr := GetConfig().RPC.ListenAddress
|
||||||
client := rpcclient.NewJSONRPCClient(laddr)
|
client := rpcclient.NewJSONRPCClient(laddr)
|
||||||
|
ctypes.RegisterAmino(client.Codec())
|
||||||
result := new(ctypes.ResultStatus)
|
result := new(ctypes.ResultStatus)
|
||||||
for {
|
for {
|
||||||
_, err := client.Call("status", map[string]interface{}{}, result)
|
_, err := client.Call("status", map[string]interface{}{}, result)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
fmt.Println("error", err)
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,20 +35,19 @@ const (
|
|||||||
// ENCODING / DECODING
|
// ENCODING / DECODING
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var (
|
|
||||||
EventDataNameNewBlock = "new_block"
|
|
||||||
EventDataNameNewBlockHeader = "new_block_header"
|
|
||||||
EventDataNameTx = "tx"
|
|
||||||
EventDataNameRoundState = "round_state"
|
|
||||||
EventDataNameVote = "vote"
|
|
||||||
EventDataNameProposalHeartbeat = "proposal_heartbeat"
|
|
||||||
)
|
|
||||||
|
|
||||||
// implements events.EventData
|
// implements events.EventData
|
||||||
type TMEventData interface {
|
type TMEventData interface {
|
||||||
|
AssertIsTMEventData()
|
||||||
// empty interface
|
// empty interface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (_ EventDataNewBlock) AssertIsTMEventData() {}
|
||||||
|
func (_ EventDataNewBlockHeader) AssertIsTMEventData() {}
|
||||||
|
func (_ EventDataTx) AssertIsTMEventData() {}
|
||||||
|
func (_ EventDataRoundState) AssertIsTMEventData() {}
|
||||||
|
func (_ EventDataVote) AssertIsTMEventData() {}
|
||||||
|
func (_ EventDataProposalHeartbeat) AssertIsTMEventData() {}
|
||||||
|
|
||||||
func RegisterEventDatas(cdc *amino.Codec) {
|
func RegisterEventDatas(cdc *amino.Codec) {
|
||||||
cdc.RegisterInterface((*TMEventData)(nil), nil)
|
cdc.RegisterInterface((*TMEventData)(nil), nil)
|
||||||
cdc.RegisterConcrete(EventDataNewBlock{}, "tendermint/EventDataNameNewBlock", nil)
|
cdc.RegisterConcrete(EventDataNewBlock{}, "tendermint/EventDataNameNewBlock", nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user