Browse Source

rpc: refactor lib folder (#4836)

Closes https://github.com/tendermint/tendermint/issues/3857

Moves `lib/` folder to `jsonrpc/`.

Renames:

**packages**

`rpc` package -> `jsonrpc` package
`rpcclient` package -> `client` package
`rpcserver` package -> `server` package

**structs and interfaces**

```
JSONRPCClient to Client
JSONRPCRequestBatch to RequestBatch
JSONRPCCaller to Caller
```

**functions**

```
StartHTTPServer to Serve
StartHTTPAndTLSServer to ServeTLS

rpc/jsonrpc/client: rename NewURIClient to NewURI

NewJSONRPCClient to New
NewJSONRPCClientWithHTTPClient to NewWithHTTPClient
NewWSClient to NewWS
```

**misc**

- unexpose `ResponseWriterWrapper`
- remove unused http_params.go
pull/5202/head
Anton Kaliaev 4 years ago
committed by Tess Rinearson
parent
commit
e8b4226b17
57 changed files with 191 additions and 249 deletions
  1. +18
    -0
      CHANGELOG_PENDING.md
  2. +4
    -4
      Makefile
  3. +1
    -1
      cmd/tendermint/commands/lite.go
  4. +3
    -3
      lite/proxy/proxy.go
  5. +1
    -1
      lite/proxy/wrapper.go
  6. +3
    -3
      lite2/proxy/proxy.go
  7. +2
    -2
      lite2/proxy/routes.go
  8. +1
    -1
      lite2/rpc/client.go
  9. +3
    -3
      node/node.go
  10. +9
    -9
      rpc/client/http/http.go
  11. +1
    -1
      rpc/client/local/local.go
  12. +1
    -1
      rpc/client/mock/client.go
  13. +4
    -4
      rpc/client/rpc_test.go
  14. +1
    -1
      rpc/core/abci.go
  15. +1
    -1
      rpc/core/blocks.go
  16. +1
    -1
      rpc/core/blocks_test.go
  17. +1
    -1
      rpc/core/consensus.go
  18. +1
    -1
      rpc/core/dev.go
  19. +1
    -1
      rpc/core/events.go
  20. +1
    -1
      rpc/core/evidence.go
  21. +1
    -1
      rpc/core/health.go
  22. +1
    -1
      rpc/core/mempool.go
  23. +1
    -1
      rpc/core/net.go
  24. +1
    -1
      rpc/core/net_test.go
  25. +1
    -1
      rpc/core/routes.go
  26. +1
    -1
      rpc/core/status.go
  27. +1
    -1
      rpc/core/tx.go
  28. +1
    -1
      rpc/grpc/api.go
  29. +1
    -1
      rpc/jsonrpc/client/args_test.go
  30. +2
    -2
      rpc/jsonrpc/client/decode.go
  31. +1
    -1
      rpc/jsonrpc/client/encode.go
  32. +34
    -34
      rpc/jsonrpc/client/http_json_client.go
  33. +1
    -1
      rpc/jsonrpc/client/http_json_client_test.go
  34. +4
    -4
      rpc/jsonrpc/client/http_uri_client.go
  35. +2
    -2
      rpc/jsonrpc/client/integration_test.go
  36. +4
    -4
      rpc/jsonrpc/client/ws_client.go
  37. +3
    -3
      rpc/jsonrpc/client/ws_client_test.go
  38. +2
    -2
      rpc/jsonrpc/doc.go
  39. +18
    -18
      rpc/jsonrpc/jsonrpc_test.go
  40. +2
    -2
      rpc/jsonrpc/server/http_json_handler.go
  41. +2
    -2
      rpc/jsonrpc/server/http_json_handler_test.go
  42. +16
    -12
      rpc/jsonrpc/server/http_server.go
  43. +4
    -4
      rpc/jsonrpc/server/http_server_test.go
  44. +15
    -4
      rpc/jsonrpc/server/http_uri_handler.go
  45. +2
    -2
      rpc/jsonrpc/server/parse_test.go
  46. +1
    -1
      rpc/jsonrpc/server/rpc_func.go
  47. +0
    -0
      rpc/jsonrpc/server/test.crt
  48. +0
    -0
      rpc/jsonrpc/server/test.key
  49. +2
    -2
      rpc/jsonrpc/server/ws_handler.go
  50. +2
    -2
      rpc/jsonrpc/server/ws_handler_test.go
  51. +0
    -0
      rpc/jsonrpc/test/data.json
  52. +0
    -0
      rpc/jsonrpc/test/integration_test.sh
  53. +3
    -3
      rpc/jsonrpc/test/main.go
  54. +1
    -1
      rpc/jsonrpc/types/types.go
  55. +1
    -1
      rpc/jsonrpc/types/types_test.go
  56. +0
    -91
      rpc/lib/server/http_params.go
  57. +2
    -2
      rpc/test/helpers.go

+ 18
- 0
CHANGELOG_PENDING.md View File

@ -20,6 +20,24 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- [privval] [\#4744](https://github.com/tendermint/tendermint/pull/4744) Remove deprecated `OldFilePV` (@melekes)
- [mempool] [\#4759](https://github.com/tendermint/tendermint/pull/4759) Modify `Mempool#InitWAL` to return an error (@melekes)
- [node] [\#4832](https://github.com/tendermint/tendermint/pull/4832) `ConfigureRPC` returns an error (@melekes)
- [rpc] [\#4836](https://github.com/tendermint/tendermint/pull/4836) Overhaul `lib` folder (@melekes)
Move lib/ folder to jsonrpc/.
Rename:
rpc package -> jsonrpc package
rpcclient package -> client package
rpcserver package -> server package
JSONRPCClient to Client
JSONRPCRequestBatch to RequestBatch
JSONRPCCaller to Caller
StartHTTPServer to Serve
StartHTTPAndTLSServer to ServeTLS
NewURIClient to NewURI
NewJSONRPCClient to New
NewJSONRPCClientWithHTTPClient to NewWithHTTPClient
NewWSClient to NewWS
Unexpose ResponseWriterWrapper
Remove unused http_params.go
- Blockchain Protocol


+ 4
- 4
Makefile View File

@ -135,15 +135,15 @@ gen_certs: clean_certs
certstrap init --common-name "tendermint.com" --passphrase ""
certstrap request-cert --common-name "server" -ip "127.0.0.1" --passphrase ""
certstrap sign "server" --CA "tendermint.com" --passphrase ""
mv out/server.crt rpc/lib/server/test.crt
mv out/server.key rpc/lib/server/test.key
mv out/server.crt rpc/jsonrpc/server/test.crt
mv out/server.key rpc/jsonrpc/server/test.key
rm -rf out
.PHONY: gen_certs
# deletes generated certificates
clean_certs:
rm -f rpc/lib/server/test.crt
rm -f rpc/lib/server/test.key
rm -f rpc/jsonrpc/server/test.crt
rm -f rpc/jsonrpc/server/test.key
.PHONY: clean_certs
###############################################################################


+ 1
- 1
cmd/tendermint/commands/lite.go View File

@ -19,7 +19,7 @@ import (
lrpc "github.com/tendermint/tendermint/lite2/rpc"
dbs "github.com/tendermint/tendermint/lite2/store/db"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
)
// LiteCmd represents the base command when called without any subcommands


+ 3
- 3
lite/proxy/proxy.go View File

@ -11,8 +11,8 @@ import (
"github.com/tendermint/tendermint/rpc/client"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)
@ -54,7 +54,7 @@ func StartProxy(c rpcclient.Client, listenAddr string, logger log.Logger, maxOpe
if err != nil {
return err
}
return rpcserver.StartHTTPServer(l, mux, logger, config)
return rpcserver.Serve(l, mux, logger, config)
}
// RPCRoutes just routes everything to the given client, as if it were


+ 1
- 1
lite/proxy/wrapper.go View File

@ -8,7 +8,7 @@ import (
"github.com/tendermint/tendermint/lite"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
var _ rpcclient.Client = Wrapper{}


+ 3
- 3
lite2/proxy/proxy.go View File

@ -13,7 +13,7 @@ import (
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
lrpc "github.com/tendermint/tendermint/lite2/rpc"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
)
// A Proxy defines parameters for running an HTTP server proxy.
@ -37,7 +37,7 @@ func (p *Proxy) ListenAndServe() error {
}
p.Listener = listener
return rpcserver.StartHTTPServer(
return rpcserver.Serve(
listener,
mux,
p.Logger,
@ -55,7 +55,7 @@ func (p *Proxy) ListenAndServeTLS(certFile, keyFile string) error {
}
p.Listener = listener
return rpcserver.StartHTTPAndTLSServer(
return rpcserver.ServeTLS(
listener,
mux,
certFile,


+ 2
- 2
lite2/proxy/routes.go View File

@ -4,8 +4,8 @@ import (
"github.com/tendermint/tendermint/libs/bytes"
lrpc "github.com/tendermint/tendermint/lite2/rpc"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
lite2/rpc/client.go View File

@ -14,7 +14,7 @@ import (
lite "github.com/tendermint/tendermint/lite2"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)


+ 3
- 3
node/node.go View File

@ -38,7 +38,7 @@ import (
rpccore "github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
grpccore "github.com/tendermint/tendermint/rpc/grpc"
rpcserver "github.com/tendermint/tendermint/rpc/lib/server"
rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/state/txindex/kv"
@ -929,7 +929,7 @@ func (n *Node) startRPC() ([]net.Listener, error) {
rootHandler = corsMiddleware.Handler(mux)
}
if n.config.RPC.IsTLSEnabled() {
go rpcserver.StartHTTPAndTLSServer(
go rpcserver.ServeTLS(
listener,
rootHandler,
n.config.RPC.CertFile(),
@ -938,7 +938,7 @@ func (n *Node) startRPC() ([]net.Listener, error) {
config,
)
} else {
go rpcserver.StartHTTPServer(
go rpcserver.Serve(
listener,
rootHandler,
rpcLogger,


+ 9
- 9
rpc/client/http/http.go View File

@ -17,7 +17,7 @@ import (
"github.com/tendermint/tendermint/libs/service"
rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcclientlib "github.com/tendermint/tendermint/rpc/lib/client"
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tendermint/tendermint/types"
)
@ -62,7 +62,7 @@ Example:
*/
type HTTP struct {
remote string
rpc *rpcclientlib.JSONRPCClient
rpc *jsonrpcclient.Client
*baseRPCClient
*WSEvents
@ -79,7 +79,7 @@ type HTTP struct {
// batch, but ordering of transactions in the batch cannot be guaranteed in such
// an example.
type BatchHTTP struct {
rpcBatch *rpcclientlib.JSONRPCRequestBatch
rpcBatch *jsonrpcclient.RequestBatch
*baseRPCClient
}
@ -97,7 +97,7 @@ type rpcClient interface {
// baseRPCClient implements the basic RPC method logic without the actual
// underlying RPC call functionality, which is provided by `caller`.
type baseRPCClient struct {
caller rpcclientlib.JSONRPCCaller
caller jsonrpcclient.Caller
}
var _ rpcClient = (*HTTP)(nil)
@ -111,7 +111,7 @@ var _ rpcClient = (*baseRPCClient)(nil)
// the websocket path (which always seems to be "/websocket")
// An error is returned on invalid remote. The function panics when remote is nil.
func New(remote, wsEndpoint string) (*HTTP, error) {
httpClient, err := rpcclientlib.DefaultHTTPClient(remote)
httpClient, err := jsonrpcclient.DefaultHTTPClient(remote)
if err != nil {
return nil, err
}
@ -120,7 +120,7 @@ func New(remote, wsEndpoint string) (*HTTP, error) {
// Create timeout enabled http client
func NewWithTimeout(remote, wsEndpoint string, timeout uint) (*HTTP, error) {
httpClient, err := rpcclientlib.DefaultHTTPClient(remote)
httpClient, err := jsonrpcclient.DefaultHTTPClient(remote)
if err != nil {
return nil, err
}
@ -135,7 +135,7 @@ func NewWithClient(remote, wsEndpoint string, client *http.Client) (*HTTP, error
panic("nil http.Client provided")
}
rc, err := rpcclientlib.NewJSONRPCClientWithHTTPClient(remote, client)
rc, err := jsonrpcclient.NewWithHTTPClient(remote, client)
if err != nil {
return nil, err
}
@ -441,7 +441,7 @@ type WSEvents struct {
cdc *amino.Codec
remote string
endpoint string
ws *rpcclientlib.WSClient
ws *jsonrpcclient.WSClient
mtx sync.RWMutex
subscriptions map[string]chan ctypes.ResultEvent // query -> chan
@ -457,7 +457,7 @@ func newWSEvents(cdc *amino.Codec, remote, endpoint string) (*WSEvents, error) {
w.BaseService = *service.NewBaseService(nil, "WSEvents", w)
var err error
w.ws, err = rpcclientlib.NewWSClient(w.remote, w.endpoint, rpcclientlib.OnReconnect(func() {
w.ws, err = jsonrpcclient.NewWS(w.remote, w.endpoint, jsonrpcclient.OnReconnect(func() {
// resubscribe immediately
w.redoSubscriptionsAfter(0 * time.Second)
}))


+ 1
- 1
rpc/client/local/local.go View File

@ -14,7 +14,7 @@ import (
rpcclient "github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
rpc/client/mock/client.go View File

@ -22,7 +22,7 @@ import (
"github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)


+ 4
- 4
rpc/client/rpc_test.go View File

@ -26,7 +26,7 @@ import (
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
rpclocal "github.com/tendermint/tendermint/rpc/client/local"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
rpctest "github.com/tendermint/tendermint/rpc/test"
"github.com/tendermint/tendermint/types"
)
@ -68,7 +68,7 @@ func TestNilCustomHTTPClient(t *testing.T) {
_, _ = rpchttp.NewWithClient("http://example.com", "/websocket", nil)
})
require.Panics(t, func() {
_, _ = rpcclient.NewJSONRPCClientWithHTTPClient("http://example.com", nil)
_, _ = rpcclient.NewWithHTTPClient("http://example.com", nil)
})
}
@ -771,14 +771,14 @@ func TestBatchedJSONRPCCallsCancellation(t *testing.T) {
require.Equal(t, 0, batch.Count())
}
func TestSendingEmptyJSONRPCRequestBatch(t *testing.T) {
func TestSendingEmptyRequestBatch(t *testing.T) {
c := getHTTPClient()
batch := c.NewBatch()
_, err := batch.Send()
require.Error(t, err, "sending an empty batch of JSON RPC requests should result in an error")
}
func TestClearingEmptyJSONRPCRequestBatch(t *testing.T) {
func TestClearingEmptyRequestBatch(t *testing.T) {
c := getHTTPClient()
batch := c.NewBatch()
require.Zero(t, batch.Clear(), "clearing an empty batch of JSON RPC requests should result in a 0 result")


+ 1
- 1
rpc/core/abci.go View File

@ -5,7 +5,7 @@ import (
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/proxy"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// ABCIQuery queries the application for some information.


+ 1
- 1
rpc/core/blocks.go View File

@ -5,7 +5,7 @@ import (
tmmath "github.com/tendermint/tendermint/libs/math"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
rpc/core/blocks_test.go View File

@ -11,7 +11,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
rpc/core/consensus.go View File

@ -4,7 +4,7 @@ import (
cm "github.com/tendermint/tendermint/consensus"
tmmath "github.com/tendermint/tendermint/libs/math"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
rpc/core/dev.go View File

@ -5,7 +5,7 @@ import (
"runtime/pprof"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// UnsafeFlushMempool removes all transactions from the mempool.


+ 1
- 1
rpc/core/events.go View File

@ -9,7 +9,7 @@ import (
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
const (


+ 1
- 1
rpc/core/evidence.go View File

@ -3,7 +3,7 @@ package core
import (
"github.com/tendermint/tendermint/evidence"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
rpc/core/health.go View File

@ -2,7 +2,7 @@ package core
import (
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// Health gets node health. Returns empty result (200 OK) on success, no


+ 1
- 1
rpc/core/mempool.go View File

@ -10,7 +10,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
mempl "github.com/tendermint/tendermint/mempool"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
rpc/core/net.go View File

@ -7,7 +7,7 @@ import (
"github.com/tendermint/tendermint/p2p"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
// NetInfo returns network info.


+ 1
- 1
rpc/core/net_test.go View File

@ -9,7 +9,7 @@ import (
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
func TestUnsafeDialSeeds(t *testing.T) {


+ 1
- 1
rpc/core/routes.go View File

@ -1,7 +1,7 @@
package core
import (
rpc "github.com/tendermint/tendermint/rpc/lib/server"
rpc "github.com/tendermint/tendermint/rpc/jsonrpc/server"
)
// TODO: better system than "unsafe" prefix


+ 1
- 1
rpc/core/status.go View File

@ -7,7 +7,7 @@ import (
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/p2p"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
rpc/core/tx.go View File

@ -9,7 +9,7 @@ import (
tmmath "github.com/tendermint/tendermint/libs/math"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
"github.com/tendermint/tendermint/state/txindex/null"
"github.com/tendermint/tendermint/types"
)


+ 1
- 1
rpc/grpc/api.go View File

@ -5,7 +5,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
core "github.com/tendermint/tendermint/rpc/core"
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
)
type broadcastAPI struct {


rpc/lib/client/args_test.go → rpc/jsonrpc/client/args_test.go View File


rpc/lib/client/decode.go → rpc/jsonrpc/client/decode.go View File


rpc/lib/client/encode.go → rpc/jsonrpc/client/encode.go View File


rpc/lib/client/http_json_client.go → rpc/jsonrpc/client/http_json_client.go View File


rpc/lib/client/http_json_client_test.go → rpc/jsonrpc/client/http_json_client_test.go View File


rpc/lib/client/http_uri_client.go → rpc/jsonrpc/client/http_uri_client.go View File


rpc/lib/client/integration_test.go → rpc/jsonrpc/client/integration_test.go View File


rpc/lib/client/ws_client.go → rpc/jsonrpc/client/ws_client.go View File


rpc/lib/client/ws_client_test.go → rpc/jsonrpc/client/ws_client_test.go View File


rpc/lib/doc.go → rpc/jsonrpc/doc.go View File


rpc/lib/rpc_test.go → rpc/jsonrpc/jsonrpc_test.go View File


rpc/lib/server/http_json_handler.go → rpc/jsonrpc/server/http_json_handler.go View File


rpc/lib/server/http_json_handler_test.go → rpc/jsonrpc/server/http_json_handler_test.go View File


rpc/lib/server/http_server.go → rpc/jsonrpc/server/http_server.go View File


rpc/lib/server/http_server_test.go → rpc/jsonrpc/server/http_server_test.go View File


rpc/lib/server/http_uri_handler.go → rpc/jsonrpc/server/http_uri_handler.go View File


rpc/lib/server/parse_test.go → rpc/jsonrpc/server/parse_test.go View File


rpc/lib/server/rpc_func.go → rpc/jsonrpc/server/rpc_func.go View File


rpc/lib/server/test.crt → rpc/jsonrpc/server/test.crt View File


rpc/lib/server/test.key → rpc/jsonrpc/server/test.key View File


rpc/lib/server/ws_handler.go → rpc/jsonrpc/server/ws_handler.go View File


rpc/lib/server/ws_handler_test.go → rpc/jsonrpc/server/ws_handler_test.go View File


rpc/lib/test/data.json → rpc/jsonrpc/test/data.json View File


rpc/lib/test/integration_test.sh → rpc/jsonrpc/test/integration_test.sh View File


rpc/lib/test/main.go → rpc/jsonrpc/test/main.go View File


rpc/lib/types/types.go → rpc/jsonrpc/types/types.go View File


rpc/lib/types/types_test.go → rpc/jsonrpc/types/types_test.go View File


+ 0
- 91
rpc/lib/server/http_params.go View File

@ -1,91 +0,0 @@
package rpcserver
import (
"encoding/hex"
"net/http"
"regexp"
"strconv"
"github.com/pkg/errors"
)
var (
// Parts of regular expressions
atom = "[A-Z0-9!#$%&'*+\\-/=?^_`{|}~]+"
dotAtom = atom + `(?:\.` + atom + `)*`
domain = `[A-Z0-9.-]+\.[A-Z]{2,4}`
ReInt = regexp.MustCompile(`^-?[0-9]+$`)
ReHex = regexp.MustCompile(`^(?i)[a-f0-9]+$`)
ReEmail = regexp.MustCompile(`^(?i)(` + dotAtom + `)@(` + dotAtom + `)$`)
ReAddress = regexp.MustCompile(`^(?i)[a-z0-9]{25,34}$`)
ReHost = regexp.MustCompile(`^(?i)(` + domain + `)$`)
//RE_ID12 = regexp.MustCompile(`^[a-zA-Z0-9]{12}$`)
)
func GetParam(r *http.Request, param string) string {
s := r.URL.Query().Get(param)
if s == "" {
s = r.FormValue(param)
}
return s
}
func GetParamByteSlice(r *http.Request, param string) ([]byte, error) {
s := GetParam(r, param)
return hex.DecodeString(s)
}
func GetParamInt64(r *http.Request, param string) (int64, error) {
s := GetParam(r, param)
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return 0, errors.Errorf(param, err.Error())
}
return i, nil
}
func GetParamInt32(r *http.Request, param string) (int32, error) {
s := GetParam(r, param)
i, err := strconv.ParseInt(s, 10, 32)
if err != nil {
return 0, errors.Errorf(param, err.Error())
}
return int32(i), nil
}
func GetParamUint64(r *http.Request, param string) (uint64, error) {
s := GetParam(r, param)
i, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return 0, errors.Errorf(param, err.Error())
}
return i, nil
}
func GetParamUint(r *http.Request, param string) (uint, error) {
s := GetParam(r, param)
i, err := strconv.ParseUint(s, 10, 64)
if err != nil {
return 0, errors.Errorf(param, err.Error())
}
return uint(i), nil
}
func GetParamRegexp(r *http.Request, param string, re *regexp.Regexp) (string, error) {
s := GetParam(r, param)
if !re.MatchString(s) {
return "", errors.Errorf(param, "did not match regular expression %v", re.String())
}
return s, nil
}
func GetParamFloat64(r *http.Request, param string) (float64, error) {
s := GetParam(r, param)
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return 0, errors.Errorf(param, err.Error())
}
return f, nil
}

+ 2
- 2
rpc/test/helpers.go View File

@ -19,7 +19,7 @@ import (
"github.com/tendermint/tendermint/proxy"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
core_grpc "github.com/tendermint/tendermint/rpc/grpc"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
)
// Options helps with specifying some parameters for our RPC testing for greater
@ -37,7 +37,7 @@ var defaultOptions = Options{
func waitForRPC() {
laddr := GetConfig().RPC.ListenAddress
client, err := rpcclient.NewJSONRPCClient(laddr)
client, err := rpcclient.New(laddr)
if err != nil {
panic(err)
}


Loading…
Cancel
Save