diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-11 08:10:58 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-11 08:10:58 +0800 |
commit | 64933321fb58ab92cf505a4519fe93ae69e1c71d (patch) | |
tree | ccdb638c5fa636b6b88cd39994a470aebd3815e3 /rpc | |
parent | 7e0ccc9de53e788ddc1879248bceb33a9ccdbae0 (diff) | |
parent | 499f816e3034c3e781f8ad35da070c9989cf6e3c (diff) | |
download | dexon-64933321fb58ab92cf505a4519fe93ae69e1c71d.tar dexon-64933321fb58ab92cf505a4519fe93ae69e1c71d.tar.gz dexon-64933321fb58ab92cf505a4519fe93ae69e1c71d.tar.bz2 dexon-64933321fb58ab92cf505a4519fe93ae69e1c71d.tar.lz dexon-64933321fb58ab92cf505a4519fe93ae69e1c71d.tar.xz dexon-64933321fb58ab92cf505a4519fe93ae69e1c71d.tar.zst dexon-64933321fb58ab92cf505a4519fe93ae69e1c71d.zip |
Merge branch 'rpcfrontier' of github.com-obscure:ethereum/go-ethereum into rpcfrontier
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/api.go | 2 | ||||
-rw-r--r-- | rpc/responses.go | 65 | ||||
-rw-r--r-- | rpc/util.go | 6 | ||||
-rw-r--r-- | rpc/util_test.go | 25 |
4 files changed, 64 insertions, 34 deletions
diff --git a/rpc/api.go b/rpc/api.go index 04492f27c..5c399a844 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -459,7 +459,7 @@ func (p *EthereumApi) GetBlockUncleCountByNumber(blocknum int64) (int64, error) func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC - rpclogger.Infof("%s %s", req.Method, req.Params) + rpclogger.Debugf("%s %s", req.Method, req.Params) switch req.Method { case "web3_sha3": args := new(Sha3Args) diff --git a/rpc/responses.go b/rpc/responses.go index 06d2ffef7..f5db285e1 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -5,7 +5,6 @@ import ( "math/big" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethutil" ) type BlockRes struct { @@ -56,23 +55,23 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) { } // convert strict types to hexified strings - ext.BlockNumber = ethutil.Bytes2Hex(big.NewInt(b.BlockNumber).Bytes()) - ext.BlockHash = ethutil.Bytes2Hex(b.BlockHash) - ext.ParentHash = ethutil.Bytes2Hex(b.ParentHash) - ext.Nonce = ethutil.Bytes2Hex(b.Nonce) - ext.Sha3Uncles = ethutil.Bytes2Hex(b.Sha3Uncles) - ext.LogsBloom = ethutil.Bytes2Hex(b.LogsBloom) - ext.TransactionRoot = ethutil.Bytes2Hex(b.TransactionRoot) - ext.StateRoot = ethutil.Bytes2Hex(b.StateRoot) - ext.Miner = ethutil.Bytes2Hex(b.Miner) - ext.Difficulty = ethutil.Bytes2Hex(big.NewInt(b.Difficulty).Bytes()) - ext.TotalDifficulty = ethutil.Bytes2Hex(big.NewInt(b.TotalDifficulty).Bytes()) - ext.Size = ethutil.Bytes2Hex(big.NewInt(b.Size).Bytes()) - ext.ExtraData = ethutil.Bytes2Hex(b.ExtraData) - ext.GasLimit = ethutil.Bytes2Hex(big.NewInt(b.GasLimit).Bytes()) - ext.MinGasPrice = ethutil.Bytes2Hex(big.NewInt(b.MinGasPrice).Bytes()) - ext.GasUsed = ethutil.Bytes2Hex(big.NewInt(b.GasUsed).Bytes()) - ext.UnixTimestamp = ethutil.Bytes2Hex(big.NewInt(b.UnixTimestamp).Bytes()) + 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.Difficulty = toHex(big.NewInt(b.Difficulty).Bytes()) + ext.TotalDifficulty = toHex(big.NewInt(b.TotalDifficulty).Bytes()) + ext.Size = toHex(big.NewInt(b.Size).Bytes()) + // ext.ExtraData = toHex(b.ExtraData) + ext.GasLimit = toHex(big.NewInt(b.GasLimit).Bytes()) + // ext.MinGasPrice = toHex(big.NewInt(b.MinGasPrice).Bytes()) + ext.GasUsed = toHex(big.NewInt(b.GasUsed).Bytes()) + ext.UnixTimestamp = toHex(big.NewInt(b.UnixTimestamp).Bytes()) ext.Transactions = make([]interface{}, len(b.Transactions)) if b.fullTx { for i, tx := range b.Transactions { @@ -80,12 +79,12 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) { } } else { for i, tx := range b.Transactions { - ext.Transactions[i] = ethutil.Bytes2Hex(tx.Hash) + ext.Transactions[i] = toHex(tx.Hash) } } ext.Uncles = make([]string, len(b.Uncles)) for i, v := range b.Uncles { - ext.Uncles[i] = ethutil.Bytes2Hex(v) + ext.Uncles[i] = toHex(v) } return json.Marshal(ext) @@ -103,7 +102,9 @@ func NewBlockRes(block *types.Block) *BlockRes { res.StateRoot = block.Root() res.Miner = block.Header().Coinbase res.Difficulty = block.Difficulty().Int64() - res.TotalDifficulty = block.Td.Int64() + if block.Td != nil { + res.TotalDifficulty = block.Td.Int64() + } res.Size = int64(block.Size()) // res.ExtraData = res.GasLimit = block.GasLimit().Int64() @@ -154,17 +155,17 @@ func (t *TransactionRes) MarshalJSON() ([]byte, error) { Input string `json:"input"` } - ext.Hash = ethutil.Bytes2Hex(t.Hash) - ext.Nonce = ethutil.Bytes2Hex(big.NewInt(t.Nonce).Bytes()) - ext.BlockHash = ethutil.Bytes2Hex(t.BlockHash) - ext.BlockNumber = ethutil.Bytes2Hex(big.NewInt(t.BlockNumber).Bytes()) - ext.TxIndex = ethutil.Bytes2Hex(big.NewInt(t.TxIndex).Bytes()) - ext.From = ethutil.Bytes2Hex(t.From) - ext.To = ethutil.Bytes2Hex(t.To) - ext.Value = ethutil.Bytes2Hex(big.NewInt(t.Value).Bytes()) - ext.Gas = ethutil.Bytes2Hex(big.NewInt(t.Gas).Bytes()) - ext.GasPrice = ethutil.Bytes2Hex(big.NewInt(t.GasPrice).Bytes()) - ext.Input = ethutil.Bytes2Hex(t.Input) + ext.Hash = toHex(t.Hash) + ext.Nonce = toHex(big.NewInt(t.Nonce).Bytes()) + ext.BlockHash = toHex(t.BlockHash) + 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.Value = toHex(big.NewInt(t.Value).Bytes()) + ext.Gas = toHex(big.NewInt(t.Gas).Bytes()) + ext.GasPrice = toHex(big.NewInt(t.GasPrice).Bytes()) + ext.Input = toHex(t.Input) return json.Marshal(ext) } diff --git a/rpc/util.go b/rpc/util.go index fb4efdb45..8ff3c6d31 100644 --- a/rpc/util.go +++ b/rpc/util.go @@ -91,7 +91,7 @@ func UnmarshalRawMessages(b []byte, iface interface{}, number *int64) (err error func (self JsonWrapper) Send(writer io.Writer, v interface{}) (n int, err error) { var payload []byte - payload, err = json.Marshal(v) + payload, err = json.MarshalIndent(v, "", "\t") if err != nil { rpclogger.Fatalln("Error marshalling JSON", err) return 0, err @@ -127,11 +127,15 @@ func toHex(b []byte) string { } return "0x" + hex } + func fromHex(s string) []byte { if len(s) > 1 { if s[0:2] == "0x" { s = s[2:] } + if len(s)%2 == 1 { + s = "0" + s + } return ethutil.Hex2Bytes(s) } return nil diff --git a/rpc/util_test.go b/rpc/util_test.go new file mode 100644 index 000000000..b0a4979b5 --- /dev/null +++ b/rpc/util_test.go @@ -0,0 +1,25 @@ +package rpc + +import ( + "bytes" + "testing" +) + +//fromHex +func TestFromHex(t *testing.T) { + input := "0x01" + expected := []byte{1} + result := fromHex(input) + if bytes.Compare(expected, result) != 0 { + t.Errorf("Expected % x got % x", expected, result) + } +} + +func TestFromHexOddLength(t *testing.T) { + input := "0x1" + expected := []byte{1} + result := fromHex(input) + if bytes.Compare(expected, result) != 0 { + t.Errorf("Expected % x got % x", expected, result) + } +} |