aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go32
-rw-r--r--rpc/args.go68
-rw-r--r--rpc/args_test.go120
-rw-r--r--rpc/http.go14
-rw-r--r--rpc/jeth.go43
-rw-r--r--rpc/messages.go12
-rw-r--r--rpc/responses.go77
-rw-r--r--rpc/util.go9
8 files changed, 273 insertions, 102 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 1846e7db5..3c46684d1 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -9,11 +9,11 @@ import (
"sync"
"time"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/state"
@@ -371,6 +371,11 @@ func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error {
return nil
}
+// func (p *EthereumApi) RemoveWhisperIdentity(args *WhisperIdentityArgs, reply *interface{}) error {
+// *reply = p.xeth().Whisper().RemoveIdentity(args.Identity)
+// return nil
+// }
+
func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface{}) error {
var id int
opts := new(xeth.Options)
@@ -663,7 +668,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return NewValidationError("Index", "does not exist")
}
- uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false)
+ uncle, err := p.GetBlockByHash(v.Uncles[args.Index].Hex(), false)
if err != nil {
return err
}
@@ -682,7 +687,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return NewValidationError("Index", "does not exist")
}
- uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false)
+ uncle, err := p.GetBlockByHash(v.Uncles[args.Index].Hex(), false)
if err != nil {
return err
}
@@ -751,6 +756,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return p.WhisperPost(args, reply)
case "shh_newIdentity":
return p.NewWhisperIdentity(reply)
+ // case "shh_removeIdentity":
+ // args := new(WhisperIdentityArgs)
+ // if err := json.Unmarshal(req.Params, &args); err != nil {
+ // return err
+ // }
+ // return p.RemoveWhisperIdentity(args, reply)
case "shh_hasIdentity":
args := new(WhisperIdentityArgs)
if err := json.Unmarshal(req.Params, &args); err != nil {
@@ -821,12 +832,12 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
// Convert optional address slice/string to byte slice
if str, ok := options.Address.(string); ok {
- opts.Address = [][]byte{common.FromHex(str)}
+ opts.Address = []common.Address{common.HexToAddress(str)}
} else if slice, ok := options.Address.([]interface{}); ok {
- bslice := make([][]byte, len(slice))
+ bslice := make([]common.Address, len(slice))
for i, addr := range slice {
if saddr, ok := addr.(string); ok {
- bslice[i] = common.FromHex(saddr)
+ bslice[i] = common.HexToAddress(saddr)
}
}
opts.Address = bslice
@@ -835,16 +846,15 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
opts.Earliest = options.Earliest
opts.Latest = options.Latest
- topics := make([][][]byte, len(options.Topics))
+ topics := make([][]common.Hash, len(options.Topics))
for i, topicDat := range options.Topics {
if slice, ok := topicDat.([]interface{}); ok {
- topics[i] = make([][]byte, len(slice))
+ topics[i] = make([]common.Hash, len(slice))
for j, topic := range slice {
- topics[i][j] = common.FromHex(topic.(string))
+ topics[i][j] = common.HexToHash(topic.(string))
}
} else if str, ok := topicDat.(string); ok {
- topics[i] = make([][]byte, 1)
- topics[i][0] = common.FromHex(str)
+ topics[i] = []common.Hash{common.HexToHash(str)}
}
}
opts.Topics = topics
diff --git a/rpc/args.go b/rpc/args.go
index 7ed482c30..fee44c4e0 100644
--- a/rpc/args.go
+++ b/rpc/args.go
@@ -331,42 +331,6 @@ func (args *Sha3Args) UnmarshalJSON(b []byte) (err error) {
return nil
}
-// type FilterArgs struct {
-// FromBlock uint64
-// ToBlock uint64
-// Limit uint64
-// Offset uint64
-// Address string
-// Topics []string
-// }
-
-// func (args *FilterArgs) UnmarshalJSON(b []byte) (err error) {
-// var obj []struct {
-// FromBlock string `json:"fromBlock"`
-// ToBlock string `json:"toBlock"`
-// Limit string `json:"limit"`
-// Offset string `json:"offset"`
-// Address string `json:"address"`
-// Topics []string `json:"topics"`
-// }
-
-// if err = json.Unmarshal(b, &obj); err != nil {
-// return errDecodeArgs
-// }
-
-// if len(obj) < 1 {
-// return errArguments
-// }
-// args.FromBlock = uint64(common.Big(obj[0].FromBlock).Int64())
-// args.ToBlock = uint64(common.Big(obj[0].ToBlock).Int64())
-// args.Limit = uint64(common.Big(obj[0].Limit).Int64())
-// args.Offset = uint64(common.Big(obj[0].Offset).Int64())
-// args.Address = obj[0].Address
-// args.Topics = obj[0].Topics
-
-// return nil
-// }
-
type FilterOptions struct {
Earliest int64
Latest int64
@@ -378,8 +342,8 @@ type FilterOptions struct {
func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
var obj []struct {
- FromBlock string `json:"fromBlock"`
- ToBlock string `json:"toBlock"`
+ FromBlock interface{} `json:"fromBlock"`
+ ToBlock interface{} `json:"toBlock"`
Limit string `json:"limit"`
Offset string `json:"offset"`
Address string `json:"address"`
@@ -394,8 +358,32 @@ func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
return NewInsufficientParamsError(len(obj), 1)
}
- args.Earliest = int64(common.Big(obj[0].FromBlock).Int64())
- args.Latest = int64(common.Big(obj[0].ToBlock).Int64())
+ fromstr, ok := obj[0].FromBlock.(string)
+ if !ok {
+ return NewDecodeParamError("FromBlock is not a string")
+ }
+
+ switch fromstr {
+ case "latest":
+ args.Earliest = 0
+ default:
+ args.Earliest = int64(common.Big(obj[0].FromBlock.(string)).Int64())
+ }
+
+ tostr, ok := obj[0].ToBlock.(string)
+ if !ok {
+ return NewDecodeParamError("ToBlock is not a string")
+ }
+
+ switch tostr {
+ case "latest":
+ args.Latest = 0
+ case "pending":
+ args.Latest = -1
+ default:
+ args.Latest = int64(common.Big(obj[0].ToBlock.(string)).Int64())
+ }
+
args.Max = int(common.Big(obj[0].Limit).Int64())
args.Skip = int(common.Big(obj[0].Offset).Int64())
args.Address = obj[0].Address
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 47d79cc32..61b9dad25 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -74,6 +74,16 @@ func TestGetBlockByHashArgs(t *testing.T) {
}
}
+func TestGetBlockByHashEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(GetBlockByHashArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestGetBlockByNumberArgs(t *testing.T) {
input := `["0x1b4", false]`
expected := new(GetBlockByNumberArgs)
@@ -94,6 +104,16 @@ func TestGetBlockByNumberArgs(t *testing.T) {
}
}
+func TestGetBlockByNumberEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(GetBlockByNumberArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestNewTxArgs(t *testing.T) {
input := `[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f072445675",
@@ -139,6 +159,16 @@ func TestNewTxArgs(t *testing.T) {
}
}
+func TestNewTxArgsEmpty(t *testing.T) {
+ input := `[]`
+
+ args := new(NewTxArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestGetStorageArgs(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
expected := new(GetStorageArgs)
@@ -163,6 +193,16 @@ func TestGetStorageArgs(t *testing.T) {
}
}
+func TestGetStorageEmptyArgs(t *testing.T) {
+ input := `[]`
+
+ args := new(GetStorageArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestGetStorageAtArgs(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0", "0x2"]`
expected := new(GetStorageAtArgs)
@@ -192,6 +232,16 @@ func TestGetStorageAtArgs(t *testing.T) {
}
}
+func TestGetStorageAtEmptyArgs(t *testing.T) {
+ input := `[]`
+
+ args := new(GetStorageAtArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestGetTxCountArgs(t *testing.T) {
input := `["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"]`
expected := new(GetTxCountArgs)
@@ -216,6 +266,16 @@ func TestGetTxCountArgs(t *testing.T) {
}
}
+func TestGetTxCountEmptyArgs(t *testing.T) {
+ input := `[]`
+
+ args := new(GetTxCountArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestGetDataArgs(t *testing.T) {
input := `["0xd5677cf67b5aa051bb40496e68ad359eb97cfbf8", "latest"]`
expected := new(GetDataArgs)
@@ -240,6 +300,16 @@ func TestGetDataArgs(t *testing.T) {
}
}
+func TestGetDataEmptyArgs(t *testing.T) {
+ input := `[]`
+
+ args := new(GetDataArgs)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestFilterOptions(t *testing.T) {
input := `[{
"fromBlock": "0x1",
@@ -286,6 +356,56 @@ func TestFilterOptions(t *testing.T) {
// }
}
+func TestFilterOptionsWords(t *testing.T) {
+ input := `[{
+ "fromBlock": "latest",
+ "toBlock": "pending"
+ }]`
+ expected := new(FilterOptions)
+ expected.Earliest = 0
+ expected.Latest = -1
+
+ args := new(FilterOptions)
+ if err := json.Unmarshal([]byte(input), &args); err != nil {
+ t.Error(err)
+ }
+
+ if expected.Earliest != args.Earliest {
+ t.Errorf("Earliest shoud be %#v but is %#v", expected.Earliest, args.Earliest)
+ }
+
+ if expected.Latest != args.Latest {
+ t.Errorf("Latest shoud be %#v but is %#v", expected.Latest, args.Latest)
+ }
+}
+
+func TestFilterOptionsNums(t *testing.T) {
+ input := `[{
+ "fromBlock": 2,
+ "toBlock": 3
+ }]`
+
+ args := new(FilterOptions)
+ err := json.Unmarshal([]byte(input), &args)
+ switch err.(type) {
+ case *DecodeParamError:
+ break
+ default:
+ t.Errorf("Should have *DecodeParamError but instead have %T", err)
+ }
+
+}
+
+func TestFilterOptionsEmptyArgs(t *testing.T) {
+ input := `[]`
+
+ args := new(FilterOptions)
+ err := json.Unmarshal([]byte(input), &args)
+ if err == nil {
+ t.Error("Expected error but didn't get one")
+ }
+}
+
func TestDbArgs(t *testing.T) {
input := `["0x74657374","0x6b6579","0x6d79537472696e67"]`
expected := new(DbArgs)
diff --git a/rpc/http.go b/rpc/http.go
index 8dcd55ad1..b6edb7cd7 100644
--- a/rpc/http.go
+++ b/rpc/http.go
@@ -26,7 +26,7 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
if req.ContentLength > maxSizeReqLength {
jsonerr := &RpcErrorObject{-32700, "Request too large"}
- json.Send(w, &RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
+ json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
return
}
@@ -36,11 +36,11 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
break
case *DecodeParamError, *InsufficientParamsError, *ValidationError:
jsonerr := &RpcErrorObject{-32602, reqerr.Error()}
- json.Send(w, &RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
+ json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
return
default:
jsonerr := &RpcErrorObject{-32700, "Could not parse request"}
- json.Send(w, &RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
+ json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
return
}
@@ -51,19 +51,19 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
break
case *NotImplementedError:
jsonerr := &RpcErrorObject{-32601, reserr.Error()}
- json.Send(w, &RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr})
+ json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: reqParsed.Id, Error: jsonerr})
return
case *DecodeParamError, *InsufficientParamsError, *ValidationError:
jsonerr := &RpcErrorObject{-32602, reserr.Error()}
- json.Send(w, &RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr})
+ json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: reqParsed.Id, Error: jsonerr})
return
default:
jsonerr := &RpcErrorObject{-32603, reserr.Error()}
- json.Send(w, &RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr})
+ json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: reqParsed.Id, Error: jsonerr})
return
}
rpchttplogger.DebugDetailf("Generated response: %T %s", response, response)
- json.Send(w, &RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response})
+ json.Send(w, &RpcSuccessResponse{Jsonrpc: jsonrpcver, Id: reqParsed.Id, Result: response})
})
}
diff --git a/rpc/jeth.go b/rpc/jeth.go
new file mode 100644
index 000000000..11d4599c9
--- /dev/null
+++ b/rpc/jeth.go
@@ -0,0 +1,43 @@
+package rpc
+
+import (
+ "encoding/json"
+ // "fmt"
+ "github.com/obscuren/otto"
+)
+
+type Jeth struct {
+ ethApi *EthereumApi
+ toVal func(interface{}) otto.Value
+}
+
+func NewJeth(ethApi *EthereumApi, toVal func(interface{}) otto.Value) *Jeth {
+ return &Jeth{ethApi, toVal}
+}
+
+func (self *Jeth) err(code int, msg string, id interface{}) otto.Value {
+ rpcerr := &RpcErrorObject{code, msg}
+ rpcresponse := &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: id, Error: rpcerr}
+ return self.toVal(rpcresponse)
+}
+
+func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
+ reqif, err := call.Argument(0).Export()
+ if err != nil {
+ return self.err(-32700, err.Error(), nil)
+ }
+
+ jsonreq, err := json.Marshal(reqif)
+
+ var req RpcRequest
+ err = json.Unmarshal(jsonreq, &req)
+
+ var respif interface{}
+ err = self.ethApi.GetRequestReply(&req, &respif)
+ if err != nil {
+ return self.err(-32603, err.Error(), req.Id)
+ }
+ rpcresponse := &RpcSuccessResponse{Jsonrpc: jsonrpcver, Id: req.Id, Result: respif}
+ response = self.toVal(rpcresponse)
+ return
+}
diff --git a/rpc/messages.go b/rpc/messages.go
index 781394196..7f5ebab11 100644
--- a/rpc/messages.go
+++ b/rpc/messages.go
@@ -83,21 +83,21 @@ func NewValidationError(param string, msg string) error {
}
type RpcRequest struct {
- ID interface{} `json:"id"`
- JsonRpc string `json:"jsonrpc"`
+ Id interface{} `json:"id"`
+ Jsonrpc string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params"`
}
type RpcSuccessResponse struct {
- ID interface{} `json:"id"`
- JsonRpc string `json:"jsonrpc"`
+ Id interface{} `json:"id"`
+ Jsonrpc string `json:"jsonrpc"`
Result interface{} `json:"result"`
}
type RpcErrorResponse struct {
- ID interface{} `json:"id"`
- JsonRpc string `json:"jsonrpc"`
+ Id interface{} `json:"id"`
+ Jsonrpc string `json:"jsonrpc"`
Error *RpcErrorObject `json:"error"`
}
diff --git a/rpc/responses.go b/rpc/responses.go
index f41ce7b96..5b2b9d488 100644
--- a/rpc/responses.go
+++ b/rpc/responses.go
@@ -5,6 +5,7 @@ import (
// "fmt"
"math/big"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
@@ -12,14 +13,14 @@ type BlockRes struct {
fullTx bool
BlockNumber int64 `json:"number"`
- BlockHash []byte `json:"hash"`
- ParentHash []byte `json:"parentHash"`
- Nonce []byte `json:"nonce"`
- Sha3Uncles []byte `json:"sha3Uncles"`
- LogsBloom []byte `json:"logsBloom"`
- TransactionRoot []byte `json:"transactionRoot"`
- StateRoot []byte `json:"stateRoot"`
- Miner []byte `json:"miner"`
+ BlockHash common.Hash `json:"hash"`
+ ParentHash common.Hash `json:"parentHash"`
+ Nonce [8]byte `json:"nonce"`
+ Sha3Uncles common.Hash `json:"sha3Uncles"`
+ LogsBloom types.Bloom `json:"logsBloom"`
+ TransactionRoot common.Hash `json:"transactionRoot"`
+ StateRoot common.Hash `json:"stateRoot"`
+ Miner common.Address `json:"miner"`
Difficulty int64 `json:"difficulty"`
TotalDifficulty int64 `json:"totalDifficulty"`
Size int64 `json:"size"`
@@ -29,7 +30,7 @@ type BlockRes struct {
GasUsed int64 `json:"gasUsed"`
UnixTimestamp int64 `json:"timestamp"`
Transactions []*TransactionRes `json:"transactions"`
- Uncles [][]byte `json:"uncles"`
+ Uncles []common.Hash `json:"uncles"`
}
func (b *BlockRes) MarshalJSON() ([]byte, error) {
@@ -57,14 +58,14 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
// convert strict types to hexified strings
ext.BlockNumber = toHex(big.NewInt(b.BlockNumber).Bytes())
- ext.BlockHash = toHex(b.BlockHash)
- ext.ParentHash = toHex(b.ParentHash)
- ext.Nonce = toHex(b.Nonce)
- ext.Sha3Uncles = toHex(b.Sha3Uncles)
- ext.LogsBloom = toHex(b.LogsBloom)
- ext.TransactionRoot = toHex(b.TransactionRoot)
- ext.StateRoot = toHex(b.StateRoot)
- ext.Miner = toHex(b.Miner)
+ ext.BlockHash = b.BlockHash.Hex()
+ ext.ParentHash = b.ParentHash.Hex()
+ ext.Nonce = toHex(b.Nonce[:])
+ ext.Sha3Uncles = b.Sha3Uncles.Hex()
+ ext.LogsBloom = toHex(b.LogsBloom[:])
+ ext.TransactionRoot = b.TransactionRoot.Hex()
+ ext.StateRoot = b.StateRoot.Hex()
+ ext.Miner = b.Miner.Hex()
ext.Difficulty = toHex(big.NewInt(b.Difficulty).Bytes())
ext.TotalDifficulty = toHex(big.NewInt(b.TotalDifficulty).Bytes())
ext.Size = toHex(big.NewInt(b.Size).Bytes())
@@ -80,12 +81,12 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
}
} else {
for i, tx := range b.Transactions {
- ext.Transactions[i] = toHex(tx.Hash)
+ ext.Transactions[i] = tx.Hash.Hex()
}
}
ext.Uncles = make([]string, len(b.Uncles))
for i, v := range b.Uncles {
- ext.Uncles[i] = toHex(v)
+ ext.Uncles[i] = v.Hex()
}
return json.Marshal(ext)
@@ -124,7 +125,7 @@ func NewBlockRes(block *types.Block) *BlockRes {
v.TxIndex = int64(i)
res.Transactions[i] = v
}
- res.Uncles = make([][]byte, len(block.Uncles()))
+ res.Uncles = make([]common.Hash, len(block.Uncles()))
for i, uncle := range block.Uncles() {
res.Uncles[i] = uncle.Hash()
}
@@ -132,17 +133,17 @@ func NewBlockRes(block *types.Block) *BlockRes {
}
type TransactionRes struct {
- Hash []byte `json:"hash"`
- Nonce int64 `json:"nonce"`
- BlockHash []byte `json:"blockHash,omitempty"`
- BlockNumber int64 `json:"blockNumber,omitempty"`
- TxIndex int64 `json:"transactionIndex,omitempty"`
- From []byte `json:"from"`
- To []byte `json:"to"`
- Value int64 `json:"value"`
- Gas int64 `json:"gas"`
- GasPrice int64 `json:"gasPrice"`
- Input []byte `json:"input"`
+ Hash common.Hash `json:"hash"`
+ Nonce int64 `json:"nonce"`
+ BlockHash common.Hash `json:"blockHash,omitempty"`
+ BlockNumber int64 `json:"blockNumber,omitempty"`
+ TxIndex int64 `json:"transactionIndex,omitempty"`
+ From common.Address `json:"from"`
+ To *common.Address `json:"to"`
+ Value int64 `json:"value"`
+ Gas int64 `json:"gas"`
+ GasPrice int64 `json:"gasPrice"`
+ Input []byte `json:"input"`
}
func (t *TransactionRes) MarshalJSON() ([]byte, error) {
@@ -160,13 +161,17 @@ func (t *TransactionRes) MarshalJSON() ([]byte, error) {
Input string `json:"input"`
}
- ext.Hash = toHex(t.Hash)
+ ext.Hash = t.Hash.Hex()
ext.Nonce = toHex(big.NewInt(t.Nonce).Bytes())
- ext.BlockHash = toHex(t.BlockHash)
+ ext.BlockHash = t.BlockHash.Hex()
ext.BlockNumber = toHex(big.NewInt(t.BlockNumber).Bytes())
ext.TxIndex = toHex(big.NewInt(t.TxIndex).Bytes())
- ext.From = toHex(t.From)
- ext.To = toHex(t.To)
+ ext.From = t.From.Hex()
+ if t.To == nil {
+ ext.To = "0x00"
+ } else {
+ ext.To = t.To.Hex()
+ }
ext.Value = toHex(big.NewInt(t.Value).Bytes())
ext.Gas = toHex(big.NewInt(t.Gas).Bytes())
ext.GasPrice = toHex(big.NewInt(t.GasPrice).Bytes())
@@ -179,7 +184,7 @@ func NewTransactionRes(tx *types.Transaction) *TransactionRes {
var v = new(TransactionRes)
v.Hash = tx.Hash()
v.Nonce = int64(tx.Nonce())
- v.From = tx.From()
+ v.From, _ = tx.From()
v.To = tx.To()
v.Value = tx.Value().Int64()
v.Gas = tx.Gas().Int64()
diff --git a/rpc/util.go b/rpc/util.go
index 08f404c99..b9b0fa442 100644
--- a/rpc/util.go
+++ b/rpc/util.go
@@ -45,6 +45,11 @@ func UnmarshalRawMessages(b []byte, iface interface{}, number *int64) (err error
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
@@ -150,11 +155,11 @@ func toLogs(logs state.Logs) (ls []Log) {
for i, log := range logs {
var l Log
l.Topic = make([]string, len(log.Topics()))
- l.Address = toHex(log.Address())
+ l.Address = log.Address().Hex()
l.Data = toHex(log.Data())
l.Number = log.Number()
for j, topic := range log.Topics() {
- l.Topic[j] = toHex(topic)
+ l.Topic[j] = topic.Hex()
}
ls[i] = l
}