mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
Support nil pointers for Binary.
If the thing does not already have a typebyte declared, a fake one will be given (0x01). A TypeByte of 0x00 is reserved for nil things. No nil-dogs.
This commit is contained in:
@@ -17,7 +17,7 @@ func GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
|
||||
if account == nil {
|
||||
account = &acm.Account{
|
||||
Address: address,
|
||||
PubKey: acm.PubKeyNil{},
|
||||
PubKey: nil,
|
||||
Sequence: 0,
|
||||
Balance: 0,
|
||||
Code: nil,
|
||||
|
||||
@@ -18,7 +18,7 @@ type Client interface {
|
||||
BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error)
|
||||
Call(address []byte, data []byte) (*ctypes.ResponseCall, error)
|
||||
CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error)
|
||||
DumpStorage(addr []byte) (*ctypes.ResponseDumpStorage, error)
|
||||
DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error)
|
||||
GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error)
|
||||
GetAccount(address []byte) (*ctypes.ResponseGetAccount, error)
|
||||
GetBlock(height uint) (*ctypes.ResponseGetBlock, error)
|
||||
@@ -150,8 +150,8 @@ func (c *ClientHTTP) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, e
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientHTTP) DumpStorage(addr []byte) (*ctypes.ResponseDumpStorage, error) {
|
||||
values, err := argsToURLValues([]string{"addr"}, addr)
|
||||
func (c *ClientHTTP) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) {
|
||||
values, err := argsToURLValues([]string{"address"}, address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -558,11 +558,11 @@ func (c *ClientJSON) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, e
|
||||
return response.Result, nil
|
||||
}
|
||||
|
||||
func (c *ClientJSON) DumpStorage(addr []byte) (*ctypes.ResponseDumpStorage, error) {
|
||||
func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) {
|
||||
request := rpc.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: reverseFuncMap["DumpStorage"],
|
||||
Params: []interface{}{addr},
|
||||
Params: []interface{}{address},
|
||||
Id: 0,
|
||||
}
|
||||
body, err := c.RequestResponse(request)
|
||||
|
||||
@@ -101,6 +101,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
returns := rpcFunc.f.Call(args)
|
||||
log.Debug("HTTPJSONRPC", "method", request.Method, "args", args, "returns", returns)
|
||||
response, err := unreflectResponse(returns)
|
||||
if err != nil {
|
||||
WriteRPCResponse(w, NewRPCResponse(nil, err.Error()))
|
||||
@@ -148,6 +149,7 @@ func makeHTTPHandler(rpcFunc *RPCFunc) func(http.ResponseWriter, *http.Request)
|
||||
return
|
||||
}
|
||||
returns := rpcFunc.f.Call(args)
|
||||
log.Debug("HTTPRestRPC", "method", r.URL.Path, "args", args, "returns", returns)
|
||||
response, err := unreflectResponse(returns)
|
||||
if err != nil {
|
||||
WriteRPCResponse(w, NewRPCResponse(nil, err.Error()))
|
||||
|
||||
+36
-3
@@ -4,6 +4,7 @@ package rpc
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
@@ -12,12 +13,12 @@ import (
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
)
|
||||
|
||||
func StartHTTPServer(listenAddr string, mux *http.ServeMux) {
|
||||
func StartHTTPServer(listenAddr string, handler http.Handler) {
|
||||
log.Info(Fmt("Starting RPC HTTP server on %s", listenAddr))
|
||||
go func() {
|
||||
res := http.ListenAndServe(
|
||||
listenAddr,
|
||||
RecoverAndLogHandler(mux),
|
||||
RecoverAndLogHandler(handler),
|
||||
)
|
||||
log.Crit("RPC HTTPServer stopped", "result", res)
|
||||
}()
|
||||
@@ -37,8 +38,40 @@ func WriteRPCResponse(w http.ResponseWriter, res RPCResponse) {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
func AuthenticateHandler(handler http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// from https://medium.com/@xoen/golang-read-from-an-io-readwriter-without-loosing-its-content-2c6911805361
|
||||
// Read the content
|
||||
var bodyBytes []byte
|
||||
if r.Body != nil {
|
||||
bodyBytes, _ = ioutil.ReadAll(r.Body)
|
||||
}
|
||||
// Restore the io.ReadCloser to its original state
|
||||
r.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
|
||||
// Get body string
|
||||
bodyString := string(bodyBytes)
|
||||
// Also read the path+"?"+query
|
||||
pathQuery := Fmt("%v?%v", r.URL.Path, r.URL.RawQuery)
|
||||
// Concatenate into tuple
|
||||
tuple := struct {
|
||||
Body string
|
||||
Path string
|
||||
}{bodyString, pathQuery}
|
||||
// Get sign bytes
|
||||
signBytes := binary.BinaryBytes(tuple)
|
||||
// Validate the sign bytes.
|
||||
// XXX
|
||||
log.Debug("Should sign", "bytes", signBytes)
|
||||
// If validation fails
|
||||
// XXX
|
||||
// If validation passes
|
||||
handler.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Wraps an HTTP handler, adding error logging.
|
||||
//
|
||||
// If the inner function panics, the outer function recovers, logs, sends an
|
||||
// HTTP 500 error response.
|
||||
func RecoverAndLogHandler(handler http.Handler) http.Handler {
|
||||
|
||||
+1
-1
@@ -258,7 +258,7 @@ func checkTx(t *testing.T, fromAddr []byte, priv *account.PrivAccount, tx *types
|
||||
}
|
||||
// Check signatures
|
||||
// acc := getAccount(t, byteAddr)
|
||||
// NOTE: using the acc here instead of the in fails; its PubKeyNil ... ?
|
||||
// NOTE: using the acc here instead of the in fails; it is nil.
|
||||
if !in.PubKey.VerifyBytes(signBytes, in.Signature) {
|
||||
t.Fatal(types.ErrTxInvalidSignature)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user