diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-19 23:59:13 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-19 23:59:13 +0800 |
commit | b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1 (patch) | |
tree | 9d94b69006029e91d7cdf2d0eb9d6d457d238671 /rpc/util.go | |
parent | ce063e8d9c2d26dd283a43b097903628225179ea (diff) | |
parent | e540a75030de611ca8cf0a70621421b6aa3fbebf (diff) | |
download | go-tangerine-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.tar go-tangerine-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.tar.gz go-tangerine-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.tar.bz2 go-tangerine-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.tar.lz go-tangerine-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.tar.xz go-tangerine-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.tar.zst go-tangerine-b5a71d955cacec0c8f81fbcf36b6f3d6d60b4bb1.zip |
merge
Diffstat (limited to 'rpc/util.go')
-rw-r--r-- | rpc/util.go | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/rpc/util.go b/rpc/util.go index b3d83409f..724c8b503 100644 --- a/rpc/util.go +++ b/rpc/util.go @@ -17,10 +17,6 @@ package rpc import ( - "encoding/json" - "fmt" - "math/big" - "reflect" "time" "github.com/ethereum/go-ethereum/common" @@ -31,74 +27,6 @@ import ( var rpclogger = logger.NewLogger("RPC") -// 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 -// message and the second one refers to the block height (or state) to which to apply this `call`. -func UnmarshalRawMessages(b []byte, iface interface{}, number *int64) (err error) { - var data []json.RawMessage - if err = json.Unmarshal(b, &data); err != nil && len(data) == 0 { - return NewDecodeParamError(err.Error()) - } - - // Hrm... Occurs when no params - if len(data) == 0 { - return NewDecodeParamError("No data") - } - - // Number index determines the index in the array for a possible block number - numberIndex := 0 - - value := reflect.ValueOf(iface) - rvalue := reflect.Indirect(value) - - switch rvalue.Kind() { - case reflect.Slice: - // This is a bit of a cheat, but `data` is expected to be larger than 2 if iface is a slice - if number != nil { - numberIndex = len(data) - 1 - } else { - numberIndex = len(data) - } - - slice := reflect.MakeSlice(rvalue.Type(), numberIndex, numberIndex) - for i, raw := range data[0:numberIndex] { - v := slice.Index(i).Interface() - if err = json.Unmarshal(raw, &v); err != nil { - fmt.Println(err, v) - return err - } - slice.Index(i).Set(reflect.ValueOf(v)) - } - reflect.Indirect(rvalue).Set(slice) //value.Set(slice) - case reflect.Struct: - fallthrough - default: - if err = json.Unmarshal(data[0], iface); err != nil { - return NewDecodeParamError(err.Error()) - } - numberIndex = 1 - } - - // <0 index means out of bound for block number - if numberIndex >= 0 && len(data) > numberIndex { - if err = blockNumber(data[numberIndex], number); err != nil { - return NewDecodeParamError(err.Error()) - } - } - - return nil -} - -func i2hex(n int) string { - return common.ToHex(big.NewInt(int64(n)).Bytes()) -} - -type RpcServer interface { - Start() - Stop() -} - type Log struct { Address string `json:"address"` Topic []string `json:"topic"` |