aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-18 20:00:01 +0800
committerobscuren <geffobscura@gmail.com>2015-03-18 20:00:01 +0800
commit0a1eeca41e6ba5920ba65d9b41654768299bc7e3 (patch)
tree0c286872355608c317f9e0ec1897bb79386ae94f /rpc
parent942980609fb8a36873689bd3bd0a15488f327d56 (diff)
downloaddexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.gz
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.bz2
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.lz
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.xz
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.tar.zst
dexon-0a1eeca41e6ba5920ba65d9b41654768299bc7e3.zip
conversions. -compilable-
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go19
-rw-r--r--rpc/responses.go77
-rw-r--r--rpc/util.go4
3 files changed, 52 insertions, 48 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 079347192..3c46684d1 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -668,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
}
@@ -687,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
}
@@ -832,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
@@ -846,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/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 e5610dc2c..b9b0fa442 100644
--- a/rpc/util.go
+++ b/rpc/util.go
@@ -155,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
}