mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-17 07:01:20 +00:00
Refactor RPC/*, tendermint/config for debora+barak
This commit is contained in:
5
Makefile
5
Makefile
@ -20,6 +20,11 @@ build_race: get_deps
|
|||||||
test: build
|
test: build
|
||||||
go test github.com/tendermint/tendermint/...
|
go test github.com/tendermint/tendermint/...
|
||||||
|
|
||||||
|
draw_deps:
|
||||||
|
# requires brew install graphviz
|
||||||
|
go get github.com/hirokidaichi/goviz
|
||||||
|
goviz -i github.com/tendermint/tendermint/cmd/tendermint | dot -Tpng -o hoge.png
|
||||||
|
|
||||||
list_deps:
|
list_deps:
|
||||||
go list -f '{{join .Deps "\n"}}' github.com/tendermint/tendermint/... | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'
|
go list -f '{{join .Deps "\n"}}' github.com/tendermint/tendermint/... | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'
|
||||||
|
|
||||||
|
@ -19,13 +19,14 @@ import (
|
|||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
. "github.com/tendermint/tendermint/cmd/barak/types"
|
. "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
pcm "github.com/tendermint/tendermint/process"
|
pcm "github.com/tendermint/tendermint/process"
|
||||||
"github.com/tendermint/tendermint/rpc"
|
"github.com/tendermint/tendermint/rpc/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Routes = map[string]*rpc.RPCFunc{
|
var Routes = map[string]*rpcserver.RPCFunc{
|
||||||
"status": rpc.NewRPCFunc(Status, []string{}),
|
"status": rpcserver.NewRPCFunc(Status, []string{}),
|
||||||
"run": rpc.NewRPCFunc(Run, []string{"auth_command"}),
|
"run": rpcserver.NewRPCFunc(Run, []string{"auth_command"}),
|
||||||
// NOTE: also, two special non-JSONRPC routes called "download" and "upload"
|
// NOTE: also, two special non-JSONRPC routes called "download" and "upload"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +59,9 @@ var barak = struct {
|
|||||||
func main() {
|
func main() {
|
||||||
fmt.Printf("New Barak Process (PID: %d)\n", os.Getpid())
|
fmt.Printf("New Barak Process (PID: %d)\n", os.Getpid())
|
||||||
|
|
||||||
|
// Apply bare tendermint/* configuration.
|
||||||
|
cfg.ApplyConfig(cfg.MapConfig(map[string]interface{}{"log_level": "info"}))
|
||||||
|
|
||||||
// read flags to change options file.
|
// read flags to change options file.
|
||||||
var optionsBytes []byte
|
var optionsBytes []byte
|
||||||
var optionsFile string
|
var optionsFile string
|
||||||
@ -97,8 +101,8 @@ func main() {
|
|||||||
mux.HandleFunc("/download", ServeFile)
|
mux.HandleFunc("/download", ServeFile)
|
||||||
mux.HandleFunc("/register", Register)
|
mux.HandleFunc("/register", Register)
|
||||||
// TODO: mux.HandleFunc("/upload", UploadFile)
|
// TODO: mux.HandleFunc("/upload", UploadFile)
|
||||||
rpc.RegisterRPCFuncs(mux, Routes)
|
rpcserver.RegisterRPCFuncs(mux, Routes)
|
||||||
rpc.StartHTTPServer(options.ListenAddress, mux)
|
rpcserver.StartHTTPServer(options.ListenAddress, mux)
|
||||||
|
|
||||||
// Register this barak with central listener
|
// Register this barak with central listener
|
||||||
for _, registry := range barak.registries {
|
for _, registry := range barak.registries {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
"github.com/tendermint/tendermint/rpc"
|
"github.com/tendermint/tendermint/rpc/client"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ func GetNonce(remote string) (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetStatus(remote string) (response btypes.ResponseStatus, err error) {
|
func GetStatus(remote string) (response btypes.ResponseStatus, err error) {
|
||||||
_, err = rpc.Call(remote, "status", Arr(), &response)
|
_, err = rpcclient.Call(remote, "status", Arr(), &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, fmt.Errorf("Error fetching nonce from remote %v:\n %v", remote, err)
|
return response, fmt.Errorf("Error fetching nonce from remote %v:\n %v", remote, err)
|
||||||
}
|
}
|
||||||
@ -113,5 +113,5 @@ func RunAuthCommand(remote string, commandJSONBytes []byte, signatures []acm.Sig
|
|||||||
CommandJSONStr: string(commandJSONBytes),
|
CommandJSONStr: string(commandJSONBytes),
|
||||||
Signatures: signatures,
|
Signatures: signatures,
|
||||||
}
|
}
|
||||||
return rpc.Call(remote, "run", Arr(authCommand), dest)
|
return rpcclient.Call(remote, "run", Arr(authCommand), dest)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
btypes "github.com/tendermint/tendermint/cmd/barak/types"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func remoteNick(remote string) string {
|
func remoteNick(remote string) string {
|
||||||
@ -33,6 +34,9 @@ var Config = struct {
|
|||||||
func main() {
|
func main() {
|
||||||
fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid())
|
fmt.Printf("New Debora Process (PID: %d)\n", os.Getpid())
|
||||||
|
|
||||||
|
// Apply bare tendermint/* configuration.
|
||||||
|
cfg.ApplyConfig(cfg.MapConfig(map[string]interface{}{"log_level": "info"}))
|
||||||
|
|
||||||
rootDir := os.Getenv("DEBROOT")
|
rootDir := os.Getenv("DEBROOT")
|
||||||
if rootDir == "" {
|
if rootDir == "" {
|
||||||
rootDir = os.Getenv("HOME") + "/.debora"
|
rootDir = os.Getenv("HOME") + "/.debora"
|
||||||
|
10
node/node.go
10
node/node.go
@ -17,8 +17,8 @@ import (
|
|||||||
"github.com/tendermint/tendermint/events"
|
"github.com/tendermint/tendermint/events"
|
||||||
mempl "github.com/tendermint/tendermint/mempool"
|
mempl "github.com/tendermint/tendermint/mempool"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
"github.com/tendermint/tendermint/rpc"
|
|
||||||
"github.com/tendermint/tendermint/rpc/core"
|
"github.com/tendermint/tendermint/rpc/core"
|
||||||
|
"github.com/tendermint/tendermint/rpc/server"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
@ -190,9 +190,9 @@ func (n *Node) StartRPC() {
|
|||||||
|
|
||||||
listenAddr := config.GetString("rpc_laddr")
|
listenAddr := config.GetString("rpc_laddr")
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
rpc.RegisterEventsHandler(mux, n.evsw)
|
rpcserver.RegisterEventsHandler(mux, n.evsw)
|
||||||
rpc.RegisterRPCFuncs(mux, core.Routes)
|
rpcserver.RegisterRPCFuncs(mux, core.Routes)
|
||||||
rpc.StartHTTPServer(listenAddr, mux)
|
rpcserver.StartHTTPServer(listenAddr, mux)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) Switch() *p2p.Switch {
|
func (n *Node) Switch() *p2p.Switch {
|
||||||
@ -252,7 +252,7 @@ func RunNode() {
|
|||||||
n.Start()
|
n.Start()
|
||||||
|
|
||||||
// If seedNode is provided by config, dial out.
|
// If seedNode is provided by config, dial out.
|
||||||
if len(config.GetStringSlice("seeds")) != 0 {
|
if len(config.GetString("seeds")) > 0 {
|
||||||
n.DialSeed()
|
n.DialSeed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package rpc
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
. "github.com/tendermint/tendermint/rpc/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Call(remote string, method string, params []interface{}, dest interface{}) (interface{}, error) {
|
func Call(remote string, method string, params []interface{}, dest interface{}) (interface{}, error) {
|
7
rpc/client/log.go
Normal file
7
rpc/client/log.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package rpcclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tendermint/log15"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = log15.New("module", "rpcclient")
|
@ -1,7 +1,7 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/tendermint/rpc"
|
rpc "github.com/tendermint/tendermint/rpc/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Routes = map[string]*rpc.RPCFunc{
|
var Routes = map[string]*rpc.RPCFunc{
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
"github.com/tendermint/tendermint/rpc"
|
rpctypes "github.com/tendermint/tendermint/rpc/types"
|
||||||
// NOTE: do not import rpc/core.
|
// NOTE: do not import rpc/core.
|
||||||
// What kind of client imports all of core logic? :P
|
// What kind of client imports all of core logic? :P
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -91,7 +91,7 @@ func argsToJson(args ...interface{}) ([]string, error) {
|
|||||||
return jsons, nil
|
return jsons, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) RequestResponse(s rpc.RPCRequest) (b []byte, err error) {
|
func (c *ClientJSON) RequestResponse(s rpctypes.RPCRequest) (b []byte, err error) {
|
||||||
b = binary.JSONBytes(s)
|
b = binary.JSONBytes(s)
|
||||||
buf := bytes.NewBuffer(b)
|
buf := bytes.NewBuffer(b)
|
||||||
resp, err := http.Post(c.addr, "text/json", buf)
|
resp, err := http.Post(c.addr, "text/json", buf)
|
||||||
@ -157,7 +157,7 @@ func argsToURLValues(argNames []string, args ...interface{}) (url.Values, error)
|
|||||||
|
|
||||||
/*rpc-gen:imports:
|
/*rpc-gen:imports:
|
||||||
github.com/tendermint/tendermint/binary
|
github.com/tendermint/tendermint/binary
|
||||||
github.com/tendermint/tendermint/rpc
|
github.com/tendermint/tendermint/rpc/types
|
||||||
net/http
|
net/http
|
||||||
io/ioutil
|
io/ioutil
|
||||||
fmt
|
fmt
|
||||||
@ -166,7 +166,7 @@ fmt
|
|||||||
// Template functions to be filled in
|
// Template functions to be filled in
|
||||||
|
|
||||||
/*rpc-gen:template:*ClientJSON func (c *ClientJSON) {{name}}({{args.def}}) ({{response}}) {
|
/*rpc-gen:template:*ClientJSON func (c *ClientJSON) {{name}}({{args.def}}) ({{response}}) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["{{name}}"],
|
Method: reverseFuncMap["{{name}}"],
|
||||||
Params: []interface{}{ {{args.ident}} },
|
Params: []interface{}{ {{args.ident}} },
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/tendermint/tendermint/account"
|
"github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
"github.com/tendermint/tendermint/rpc"
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
|
"github.com/tendermint/tendermint/rpc/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -513,7 +513,7 @@ func (c *ClientHTTP) Status() (*ctypes.ResponseStatus, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.ResponseBlockchainInfo, error) {
|
func (c *ClientJSON) BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.ResponseBlockchainInfo, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["BlockchainInfo"],
|
Method: reverseFuncMap["BlockchainInfo"],
|
||||||
Params: []interface{}{minHeight, maxHeight},
|
Params: []interface{}{minHeight, maxHeight},
|
||||||
@ -540,7 +540,7 @@ func (c *ClientJSON) BlockchainInfo(minHeight uint, maxHeight uint) (*ctypes.Res
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) {
|
func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["BroadcastTx"],
|
Method: reverseFuncMap["BroadcastTx"],
|
||||||
Params: []interface{}{tx},
|
Params: []interface{}{tx},
|
||||||
@ -567,7 +567,7 @@ func (c *ClientJSON) BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) Call(address []byte, data []byte) (*ctypes.ResponseCall, error) {
|
func (c *ClientJSON) Call(address []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["Call"],
|
Method: reverseFuncMap["Call"],
|
||||||
Params: []interface{}{address, data},
|
Params: []interface{}{address, data},
|
||||||
@ -594,7 +594,7 @@ func (c *ClientJSON) Call(address []byte, data []byte) (*ctypes.ResponseCall, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error) {
|
func (c *ClientJSON) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["CallCode"],
|
Method: reverseFuncMap["CallCode"],
|
||||||
Params: []interface{}{code, data},
|
Params: []interface{}{code, data},
|
||||||
@ -621,7 +621,7 @@ func (c *ClientJSON) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
|
func (c *ClientJSON) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["DumpConsensusState"],
|
Method: reverseFuncMap["DumpConsensusState"],
|
||||||
Params: []interface{}{},
|
Params: []interface{}{},
|
||||||
@ -648,7 +648,7 @@ func (c *ClientJSON) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) {
|
func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["DumpStorage"],
|
Method: reverseFuncMap["DumpStorage"],
|
||||||
Params: []interface{}{address},
|
Params: []interface{}{address},
|
||||||
@ -675,7 +675,7 @@ func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["GenPrivAccount"],
|
Method: reverseFuncMap["GenPrivAccount"],
|
||||||
Params: []interface{}{},
|
Params: []interface{}{},
|
||||||
@ -702,7 +702,7 @@ func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
|
func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["GetAccount"],
|
Method: reverseFuncMap["GetAccount"],
|
||||||
Params: []interface{}{address},
|
Params: []interface{}{address},
|
||||||
@ -729,7 +729,7 @@ func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
|
func (c *ClientJSON) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["GetBlock"],
|
Method: reverseFuncMap["GetBlock"],
|
||||||
Params: []interface{}{height},
|
Params: []interface{}{height},
|
||||||
@ -756,7 +756,7 @@ func (c *ClientJSON) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) {
|
func (c *ClientJSON) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["GetStorage"],
|
Method: reverseFuncMap["GetStorage"],
|
||||||
Params: []interface{}{address, key},
|
Params: []interface{}{address, key},
|
||||||
@ -783,7 +783,7 @@ func (c *ClientJSON) GetStorage(address []byte, key []byte) (*ctypes.ResponseGet
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["ListAccounts"],
|
Method: reverseFuncMap["ListAccounts"],
|
||||||
Params: []interface{}{},
|
Params: []interface{}{},
|
||||||
@ -810,7 +810,7 @@ func (c *ClientJSON) ListAccounts() (*ctypes.ResponseListAccounts, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["ListUnconfirmedTxs"],
|
Method: reverseFuncMap["ListUnconfirmedTxs"],
|
||||||
Params: []interface{}{},
|
Params: []interface{}{},
|
||||||
@ -837,7 +837,7 @@ func (c *ClientJSON) ListUnconfirmedTxs() (*ctypes.ResponseListUnconfirmedTxs, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) {
|
func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["ListValidators"],
|
Method: reverseFuncMap["ListValidators"],
|
||||||
Params: []interface{}{},
|
Params: []interface{}{},
|
||||||
@ -864,7 +864,7 @@ func (c *ClientJSON) ListValidators() (*ctypes.ResponseListValidators, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["NetInfo"],
|
Method: reverseFuncMap["NetInfo"],
|
||||||
Params: []interface{}{},
|
Params: []interface{}{},
|
||||||
@ -891,7 +891,7 @@ func (c *ClientJSON) NetInfo() (*ctypes.ResponseNetInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error) {
|
func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*ctypes.ResponseSignTx, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["SignTx"],
|
Method: reverseFuncMap["SignTx"],
|
||||||
Params: []interface{}{tx, privAccounts},
|
Params: []interface{}{tx, privAccounts},
|
||||||
@ -918,7 +918,7 @@ func (c *ClientJSON) SignTx(tx types.Tx, privAccounts []*account.PrivAccount) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientJSON) Status() (*ctypes.ResponseStatus, error) {
|
func (c *ClientJSON) Status() (*ctypes.ResponseStatus, error) {
|
||||||
request := rpc.RPCRequest{
|
request := rpctypes.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: reverseFuncMap["Status"],
|
Method: reverseFuncMap["Status"],
|
||||||
Params: []interface{}{},
|
Params: []interface{}{},
|
||||||
|
@ -2,7 +2,7 @@ package core_client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/tendermint/tendermint/rpc"
|
rpctypes "github.com/tendermint/tendermint/rpc/types"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ func (wsc *WSClient) Dial() (*http.Response, error) {
|
|||||||
|
|
||||||
// subscribe to an event
|
// subscribe to an event
|
||||||
func (wsc *WSClient) Subscribe(eventid string) error {
|
func (wsc *WSClient) Subscribe(eventid string) error {
|
||||||
return wsc.conn.WriteJSON(rpc.WSRequest{
|
return wsc.conn.WriteJSON(rpctypes.WSRequest{
|
||||||
Type: "subscribe",
|
Type: "subscribe",
|
||||||
Event: eventid,
|
Event: eventid,
|
||||||
})
|
})
|
||||||
@ -40,7 +40,7 @@ func (wsc *WSClient) Subscribe(eventid string) error {
|
|||||||
|
|
||||||
// unsubscribe from an event
|
// unsubscribe from an event
|
||||||
func (wsc *WSClient) Unsubscribe(eventid string) error {
|
func (wsc *WSClient) Unsubscribe(eventid string) error {
|
||||||
return wsc.conn.WriteJSON(rpc.WSRequest{
|
return wsc.conn.WriteJSON(rpctypes.WSRequest{
|
||||||
Type: "unsubscribe",
|
Type: "unsubscribe",
|
||||||
Event: eventid,
|
Event: eventid,
|
||||||
})
|
})
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package rpc
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/tendermint/log15"
|
|
||||||
)
|
|
||||||
|
|
||||||
var log = log15.New("module", "rpc")
|
|
@ -1,4 +1,4 @@
|
|||||||
package rpc
|
package rpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
"github.com/tendermint/tendermint/events"
|
"github.com/tendermint/tendermint/events"
|
||||||
|
. "github.com/tendermint/tendermint/rpc/types"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -205,19 +206,6 @@ const (
|
|||||||
WriteChanBufferSize = 10
|
WriteChanBufferSize = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
// for requests coming in
|
|
||||||
type WSRequest struct {
|
|
||||||
Type string `json:"type"` // subscribe or unsubscribe
|
|
||||||
Event string `json:"event"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// for responses going out
|
|
||||||
type WSResponse struct {
|
|
||||||
Event string `json:"event"`
|
|
||||||
Data interface{} `json:"data"`
|
|
||||||
Error string `json:"error"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// a single websocket connection
|
// a single websocket connection
|
||||||
// contains listener id, underlying ws connection,
|
// contains listener id, underlying ws connection,
|
||||||
// and the event switch for subscribing to events
|
// and the event switch for subscribing to events
|
@ -1,4 +1,4 @@
|
|||||||
package rpc
|
package rpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
@ -6,6 +6,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
. "github.com/tendermint/tendermint/rpc/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
@ -1,5 +1,5 @@
|
|||||||
// Commons for HTTP handling
|
// Commons for HTTP handling
|
||||||
package rpc
|
package rpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/alert"
|
"github.com/tendermint/tendermint/alert"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
. "github.com/tendermint/tendermint/rpc/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartHTTPServer(listenAddr string, handler http.Handler) {
|
func StartHTTPServer(listenAddr string, handler http.Handler) {
|
7
rpc/server/log.go
Normal file
7
rpc/server/log.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package rpcserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tendermint/log15"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log = log15.New("module", "rpcserver")
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/tendermint/tendermint/account"
|
"github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
"github.com/tendermint/tendermint/rpc"
|
"github.com/tendermint/tendermint/rpc/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
@ -30,7 +30,7 @@ func newWSCon(t *testing.T) *websocket.Conn {
|
|||||||
|
|
||||||
// subscribe to an event
|
// subscribe to an event
|
||||||
func subscribe(t *testing.T, con *websocket.Conn, eventid string) {
|
func subscribe(t *testing.T, con *websocket.Conn, eventid string) {
|
||||||
err := con.WriteJSON(rpc.WSRequest{
|
err := con.WriteJSON(rpctypes.WSRequest{
|
||||||
Type: "subscribe",
|
Type: "subscribe",
|
||||||
Event: eventid,
|
Event: eventid,
|
||||||
})
|
})
|
||||||
@ -41,7 +41,7 @@ func subscribe(t *testing.T, con *websocket.Conn, eventid string) {
|
|||||||
|
|
||||||
// unsubscribe from an event
|
// unsubscribe from an event
|
||||||
func unsubscribe(t *testing.T, con *websocket.Conn, eventid string) {
|
func unsubscribe(t *testing.T, con *websocket.Conn, eventid string) {
|
||||||
err := con.WriteJSON(rpc.WSRequest{
|
err := con.WriteJSON(rpctypes.WSRequest{
|
||||||
Type: "unsubscribe",
|
Type: "unsubscribe",
|
||||||
Event: eventid,
|
Event: eventid,
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package rpc
|
package rpctypes
|
||||||
|
|
||||||
type RPCRequest struct {
|
type RPCRequest struct {
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
@ -25,3 +25,16 @@ func NewRPCResponse(res interface{}, err string) RPCResponse {
|
|||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for requests coming in
|
||||||
|
type WSRequest struct {
|
||||||
|
Type string `json:"type"` // subscribe or unsubscribe
|
||||||
|
Event string `json:"event"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// for responses going out
|
||||||
|
type WSResponse struct {
|
||||||
|
Event string `json:"event"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
Reference in New Issue
Block a user