diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-19 19:17:43 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-19 19:17:43 +0800 |
commit | e13c6739804604849c7e43d27b073e68fba58191 (patch) | |
tree | b3471931b63210a4d107875dffd6572bcd96239e /rpc/util.go | |
parent | 965c9babe336cfa8d5c740d5356acbc5f9ba4a72 (diff) | |
parent | 5f35e6778f10d9e2c6418beff7ed201be80448c4 (diff) | |
download | go-tangerine-e13c6739804604849c7e43d27b073e68fba58191.tar go-tangerine-e13c6739804604849c7e43d27b073e68fba58191.tar.gz go-tangerine-e13c6739804604849c7e43d27b073e68fba58191.tar.bz2 go-tangerine-e13c6739804604849c7e43d27b073e68fba58191.tar.lz go-tangerine-e13c6739804604849c7e43d27b073e68fba58191.tar.xz go-tangerine-e13c6739804604849c7e43d27b073e68fba58191.tar.zst go-tangerine-e13c6739804604849c7e43d27b073e68fba58191.zip |
Merge remote-tracking branch 'ethereum/conversion' into conversion
Diffstat (limited to 'rpc/util.go')
-rw-r--r-- | rpc/util.go | 47 |
1 files changed, 2 insertions, 45 deletions
diff --git a/rpc/util.go b/rpc/util.go index b9b0fa442..b3d83409f 100644 --- a/rpc/util.go +++ b/rpc/util.go @@ -19,9 +19,7 @@ package rpc import ( "encoding/json" "fmt" - "io" "math/big" - "net/http" "reflect" "time" @@ -33,8 +31,6 @@ import ( var rpclogger = logger.NewLogger("RPC") -type JsonWrapper struct{} - // Unmarshal state is a helper method which has the ability to decode messsages // that use the `defaultBlock` (https://github.com/ethereum/wiki/wiki/JSON-RPC#the-default-block-parameter) // For example a `call`: [{to: "0x....", data:"0x..."}, "latest"]. The first argument is the transaction @@ -94,47 +90,8 @@ func UnmarshalRawMessages(b []byte, iface interface{}, number *int64) (err error return nil } -func (self JsonWrapper) Send(writer io.Writer, v interface{}) (n int, err error) { - var payload []byte - payload, err = json.MarshalIndent(v, "", "\t") - if err != nil { - rpclogger.Fatalln("Error marshalling JSON", err) - return 0, err - } - rpclogger.DebugDetailf("Sending payload: %s", payload) - - return writer.Write(payload) -} - -func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error) { - var reqParsed RpcRequest - - // Convert JSON to native types - d := json.NewDecoder(req.Body) - defer req.Body.Close() - err := d.Decode(&reqParsed) - - if err != nil { - rpclogger.Errorln("Error decoding JSON: ", err) - return reqParsed, err - } - - rpclogger.DebugDetailf("Parsed request: %s", reqParsed) - - return reqParsed, nil -} - -func toHex(b []byte) string { - hex := common.Bytes2Hex(b) - // Prefer output of "0x0" instead of "0x" - if len(hex) == 0 { - hex = "0" - } - return "0x" + hex -} - func i2hex(n int) string { - return toHex(big.NewInt(int64(n)).Bytes()) + return common.ToHex(big.NewInt(int64(n)).Bytes()) } type RpcServer interface { @@ -156,7 +113,7 @@ func toLogs(logs state.Logs) (ls []Log) { var l Log l.Topic = make([]string, len(log.Topics())) l.Address = log.Address().Hex() - l.Data = toHex(log.Data()) + l.Data = common.ToHex(log.Data()) l.Number = log.Number() for j, topic := range log.Topics() { l.Topic[j] = topic.Hex() |