Commit 7e3875b5 authored by Taylor Gerring's avatar Taylor Gerring

Remove custom MarshalJSON methods

Now formats based on underlying hexdata or hexnum type. Fields directly
with respective constructors that cover from native types
parent a2501ecf
...@@ -244,7 +244,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err ...@@ -244,7 +244,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
} }
uhash := br.Uncles[args.Index] uhash := br.Uncles[args.Index]
uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.Hex())) uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()))
*reply = uncle *reply = uncle
case "eth_getUncleByBlockNumberAndIndex": case "eth_getUncleByBlockNumberAndIndex":
...@@ -262,7 +262,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err ...@@ -262,7 +262,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
} }
uhash := v.Uncles[args.Index] uhash := v.Uncles[args.Index]
uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.Hex())) uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()))
*reply = uncle *reply = uncle
case "eth_getCompilers": case "eth_getCompilers":
......
This diff is collapsed.
package rpc package rpc
import ( import (
"encoding/json" // "encoding/json"
"math/big" // "math/big"
"testing" // "testing"
"github.com/ethereum/go-ethereum/common" // "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state" // "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" // "github.com/ethereum/go-ethereum/core/types"
) )
func TestNewBlockRes(t *testing.T) { // func TestNewBlockRes(t *testing.T) {
parentHash := common.HexToHash("0x01") // parentHash := common.HexToHash("0x01")
coinbase := common.HexToAddress("0x01") // coinbase := common.HexToAddress("0x01")
root := common.HexToHash("0x01") // root := common.HexToHash("0x01")
difficulty := common.Big1 // difficulty := common.Big1
nonce := uint64(1) // nonce := uint64(1)
extra := "" // extra := ""
block := types.NewBlock(parentHash, coinbase, root, difficulty, nonce, extra) // block := types.NewBlock(parentHash, coinbase, root, difficulty, nonce, extra)
_ = NewBlockRes(block) // _ = NewBlockRes(block)
} // }
func TestBlockRes(t *testing.T) { // func TestBlockRes(t *testing.T) {
v := &BlockRes{ // v := &BlockRes{
BlockNumber: big.NewInt(0), // BlockNumber: big.NewInt(0),
BlockHash: common.HexToHash("0x0"), // BlockHash: common.HexToHash("0x0"),
ParentHash: common.HexToHash("0x0"), // ParentHash: common.HexToHash("0x0"),
Nonce: [8]byte{0, 0, 0, 0, 0, 0, 0, 0}, // Nonce: [8]byte{0, 0, 0, 0, 0, 0, 0, 0},
Sha3Uncles: common.HexToHash("0x0"), // Sha3Uncles: common.HexToHash("0x0"),
LogsBloom: types.BytesToBloom([]byte{0}), // LogsBloom: types.BytesToBloom([]byte{0}),
TransactionRoot: common.HexToHash("0x0"), // TransactionRoot: common.HexToHash("0x0"),
StateRoot: common.HexToHash("0x0"), // StateRoot: common.HexToHash("0x0"),
Miner: common.HexToAddress("0x0"), // Miner: common.HexToAddress("0x0"),
Difficulty: big.NewInt(0), // Difficulty: big.NewInt(0),
TotalDifficulty: big.NewInt(0), // TotalDifficulty: big.NewInt(0),
Size: big.NewInt(0), // Size: big.NewInt(0),
ExtraData: []byte{}, // ExtraData: []byte{},
GasLimit: big.NewInt(0), // GasLimit: big.NewInt(0),
MinGasPrice: int64(0), // MinGasPrice: int64(0),
GasUsed: big.NewInt(0), // GasUsed: big.NewInt(0),
UnixTimestamp: int64(0), // UnixTimestamp: int64(0),
// Transactions []*TransactionRes `json:"transactions"` // // Transactions []*TransactionRes `json:"transactions"`
// Uncles []common.Hash `json:"uncles"` // // Uncles []common.Hash `json:"uncles"`
} // }
_, _ = json.Marshal(v) // _, _ = json.Marshal(v)
// fmt.Println(string(j)) // // fmt.Println(string(j))
} // }
func TestTransactionRes(t *testing.T) { // func TestTransactionRes(t *testing.T) {
a := common.HexToAddress("0x0") // a := common.HexToAddress("0x0")
v := &TransactionRes{ // v := &TransactionRes{
Hash: common.HexToHash("0x0"), // Hash: common.HexToHash("0x0"),
Nonce: uint64(0), // Nonce: uint64(0),
BlockHash: common.HexToHash("0x0"), // BlockHash: common.HexToHash("0x0"),
BlockNumber: int64(0), // BlockNumber: int64(0),
TxIndex: int64(0), // TxIndex: int64(0),
From: common.HexToAddress("0x0"), // From: common.HexToAddress("0x0"),
To: &a, // To: &a,
Value: big.NewInt(0), // Value: big.NewInt(0),
Gas: big.NewInt(0), // Gas: big.NewInt(0),
GasPrice: big.NewInt(0), // GasPrice: big.NewInt(0),
Input: []byte{0}, // Input: []byte{0},
} // }
_, _ = json.Marshal(v) // _, _ = json.Marshal(v)
} // }
func TestNewTransactionRes(t *testing.T) { // func TestNewTransactionRes(t *testing.T) {
to := common.HexToAddress("0x02") // to := common.HexToAddress("0x02")
amount := big.NewInt(1) // amount := big.NewInt(1)
gasAmount := big.NewInt(1) // gasAmount := big.NewInt(1)
gasPrice := big.NewInt(1) // gasPrice := big.NewInt(1)
data := []byte{1, 2, 3} // data := []byte{1, 2, 3}
tx := types.NewTransactionMessage(to, amount, gasAmount, gasPrice, data) // tx := types.NewTransactionMessage(to, amount, gasAmount, gasPrice, data)
_ = NewTransactionRes(tx) // _ = NewTransactionRes(tx)
} // }
func TestLogRes(t *testing.T) { // func TestLogRes(t *testing.T) {
topics := make([]common.Hash, 3) // topics := make([]common.Hash, 3)
topics = append(topics, common.HexToHash("0x00")) // topics = append(topics, common.HexToHash("0x00"))
topics = append(topics, common.HexToHash("0x10")) // topics = append(topics, common.HexToHash("0x10"))
topics = append(topics, common.HexToHash("0x20")) // topics = append(topics, common.HexToHash("0x20"))
v := &LogRes{ // v := &LogRes{
Topics: topics, // Topics: topics,
Address: common.HexToAddress("0x0"), // Address: common.HexToAddress("0x0"),
Data: []byte{1, 2, 3}, // Data: []byte{1, 2, 3},
BlockNumber: uint64(5), // BlockNumber: uint64(5),
} // }
_, _ = json.Marshal(v) // _, _ = json.Marshal(v)
} // }
func MakeStateLog(num int) state.Log { // func MakeStateLog(num int) state.Log {
address := common.HexToAddress("0x0") // address := common.HexToAddress("0x0")
data := []byte{1, 2, 3} // data := []byte{1, 2, 3}
number := uint64(num) // number := uint64(num)
topics := make([]common.Hash, 3) // topics := make([]common.Hash, 3)
topics = append(topics, common.HexToHash("0x00")) // topics = append(topics, common.HexToHash("0x00"))
topics = append(topics, common.HexToHash("0x10")) // topics = append(topics, common.HexToHash("0x10"))
topics = append(topics, common.HexToHash("0x20")) // topics = append(topics, common.HexToHash("0x20"))
log := state.NewLog(address, topics, data, number) // log := state.NewLog(address, topics, data, number)
return log // return log
} // }
func TestNewLogRes(t *testing.T) { // func TestNewLogRes(t *testing.T) {
log := MakeStateLog(0) // log := MakeStateLog(0)
_ = NewLogRes(log) // _ = NewLogRes(log)
} // }
func TestNewLogsRes(t *testing.T) { // func TestNewLogsRes(t *testing.T) {
logs := make([]state.Log, 3) // logs := make([]state.Log, 3)
logs[0] = MakeStateLog(1) // logs[0] = MakeStateLog(1)
logs[1] = MakeStateLog(2) // logs[1] = MakeStateLog(2)
logs[2] = MakeStateLog(3) // logs[2] = MakeStateLog(3)
_ = NewLogsRes(logs) // _ = NewLogsRes(logs)
} // }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment