diff --git a/packages/go-kosu/go.sum b/packages/go-kosu/go.sum index 9f4f4545..aa8c05f7 100644 --- a/packages/go-kosu/go.sum +++ b/packages/go-kosu/go.sum @@ -207,6 +207,7 @@ github.com/tendermint/iavl v0.12.2 h1:Ls5p5VINCM1HRT9g5Vvs2zmDOCU/CCIvIHzd/pZ8P0 github.com/tendermint/iavl v0.12.2/go.mod h1:EoKMMv++tDOL5qKKVnoIqtVPshRrEPeJ0WsgDOLAauM= github.com/tendermint/tendermint v0.31.5 h1:vTet8tCq3B9/J9Yo11dNZ8pOB7NtSy++bVSfkP4KzR4= github.com/tendermint/tendermint v0.31.5/go.mod h1:ymcPyWblXCplCPQjbOYbrF1fWnpslATMVqiGgWbZrlc= +github.com/tendermint/tendermint v0.32.1 h1:J8ddXMbCmG6GZjdCl/N1wgdXDU9uO91J2Y5CA9xYfGo= github.com/tidwall/gjson v1.3.0 h1:kfpsw1W3trbg4Xm6doUtqSl9+LhLB6qJ9PkltVAQZYs= github.com/tidwall/gjson v1.3.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= diff --git a/packages/go-kosu/rpc/client.go b/packages/go-kosu/rpc/client.go deleted file mode 100644 index 773f04ae..00000000 --- a/packages/go-kosu/rpc/client.go +++ /dev/null @@ -1,55 +0,0 @@ -package rpc - -import ( - "context" - - "github.com/ethereum/go-ethereum/rpc" -) - -type Client struct { - rpc *rpc.Client -} - -func DialInProc(srv *rpc.Server) *Client { - return &Client{ - rpc: rpc.DialInProc(srv), - } -} - -func (c *Client) Subscribe(ctx context.Context, fn func(interface{}), query string) error { - ch := make(chan interface{}) - args := []interface{}{"subscribe", query} - sub, err := c.rpc.Subscribe(ctx, "kosu", ch, args...) - if err != nil { - return err - } - - go func() { - defer close(ch) - defer sub.Unsubscribe() - - for { - select { - case <-ctx.Done(): - return - case <-sub.Err(): - return - case i := <-ch: - fn(i) - } - } - }() - return nil -} - -func (c *Client) Call(result interface{}, ns, method string, args ...interface{}) error { - return c.rpc.Call(result, ns+"_"+method, args...) -} - -func (c *Client) LatestHeight() (int64, error) { - var latestHeight int64 - if err := c.Call(&latestHeight, "kosu", "latestHeight"); err != nil { - return 0, err - } - return latestHeight, nil -} diff --git a/packages/go-kosu/rpc/cmd.go b/packages/go-kosu/rpc/cmd.go index f7b79cc2..7acd75e6 100644 --- a/packages/go-kosu/rpc/cmd.go +++ b/packages/go-kosu/rpc/cmd.go @@ -30,7 +30,7 @@ func NewCommand() *cobra.Command { Short: "starts the rpc bridge", Long: "The RPC bridge exposes a set of kosud functionalities over JSON-RPC 2.0", PreRunE: func(cmd *cobra.Command, args []string) error { - if http == false && ws == false { + if !http && !ws { return errors.New("both `--ws` and `--http` where false, you need to enable at least one") } @@ -54,7 +54,7 @@ func NewCommand() *cobra.Command { srv := NewServer(client) wg := sync.WaitGroup{} - if http == true { + if http { wg.Add(1) go func() { defer wg.Done() @@ -64,7 +64,7 @@ func NewCommand() *cobra.Command { }() } - if ws == true { + if ws { wg.Add(1) go func() { defer wg.Done() diff --git a/packages/go-kosu/rpc/doctool/main.go b/packages/go-kosu/rpc/doctool/main.go index d579d266..b1a68e7c 100644 --- a/packages/go-kosu/rpc/doctool/main.go +++ b/packages/go-kosu/rpc/doctool/main.go @@ -10,6 +10,7 @@ import ( "os" ) +// nolint type DocEntry struct { Method string `json:"method"` Text string `json:"text"` diff --git a/packages/go-kosu/rpc/rpc.go b/packages/go-kosu/rpc/rpc.go index c990a389..bb803bf2 100644 --- a/packages/go-kosu/rpc/rpc.go +++ b/packages/go-kosu/rpc/rpc.go @@ -6,8 +6,11 @@ import ( "github.com/ethereum/go-ethereum/rpc" ) +// NewServer returns a new Server which holds the registered rpc service func NewServer(abci *abci.Client) *rpc.Server { srv := rpc.NewServer() - srv.RegisterName("kosu", &Service{abci: abci}) + if err := srv.RegisterName("kosu", &Service{abci: abci}); err != nil { + panic(err) + } return srv } diff --git a/packages/go-kosu/rpc/rpc_test.go b/packages/go-kosu/rpc/rpc_test.go index 757e91e7..7fe6f97f 100644 --- a/packages/go-kosu/rpc/rpc_test.go +++ b/packages/go-kosu/rpc/rpc_test.go @@ -30,7 +30,7 @@ func TestRPCLatestHeight(t *testing.T) { assert.EqualValues(t, 0, latest) ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - fn := func(i interface{}) { + fn := func(_ interface{}) { // this is invoked when a block is mined require.NoError(t, client.Call(&latest, "kosu_latestHeight")) assert.EqualValues(t, 1, latest) diff --git a/packages/go-kosu/rpc/service.go b/packages/go-kosu/rpc/service.go index 96398841..fe227b32 100644 --- a/packages/go-kosu/rpc/service.go +++ b/packages/go-kosu/rpc/service.go @@ -3,6 +3,7 @@ package rpc import ( "context" "go-kosu/abci" + "log" "github.com/ethereum/go-ethereum/rpc" ) @@ -44,7 +45,10 @@ func (s *Service) Subscribe(ctx context.Context, query string) (*rpc.Subscriptio case <-notifier.Closed(): return case e := <-events: - notifier.Notify(rpcSub.ID, e) + err := notifier.Notify(rpcSub.ID, e) + if err != nil { + log.Printf("rpc: %+v", err) + } } } }() diff --git a/packages/go-kosu/tests/suite_test.go b/packages/go-kosu/tests/suite_test.go index cf15fbbb..f4446e8e 100644 --- a/packages/go-kosu/tests/suite_test.go +++ b/packages/go-kosu/tests/suite_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/tendermint/tendermint/libs/db" + rpctypes "github.com/tendermint/tendermint/rpc/core/types" ) type Suite struct {