aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-04-02 23:55:42 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-04-02 23:55:42 +0800
commit1d74086b4240f61d73e8fbf446f6234ab914ddce (patch)
tree9fac3584c0e7e37314c6fbc7a445c19d3075db8c /rpc
parent9bdf0b655de64c0c31d81da00ff2daec79359d89 (diff)
downloaddexon-1d74086b4240f61d73e8fbf446f6234ab914ddce.tar
dexon-1d74086b4240f61d73e8fbf446f6234ab914ddce.tar.gz
dexon-1d74086b4240f61d73e8fbf446f6234ab914ddce.tar.bz2
dexon-1d74086b4240f61d73e8fbf446f6234ab914ddce.tar.lz
dexon-1d74086b4240f61d73e8fbf446f6234ab914ddce.tar.xz
dexon-1d74086b4240f61d73e8fbf446f6234ab914ddce.tar.zst
dexon-1d74086b4240f61d73e8fbf446f6234ab914ddce.zip
New UncleRes type
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go8
-rw-r--r--rpc/responses.go59
2 files changed, 56 insertions, 11 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 872290eef..b8207ea0d 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -256,9 +256,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
// return NewValidationError("Index", "does not exist")
*reply = nil
} else {
- uhash := br.Uncles[args.Index]
- uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()), true)
- *reply = uncle
+ *reply = br.Uncles[args.Index]
}
case "eth_getUncleByBlockNumberAndIndex":
args := new(BlockNumIndexArgs)
@@ -278,9 +276,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
// return NewValidationError("Index", "does not exist")
*reply = nil
} else {
- uhash := v.Uncles[args.Index]
- uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()), false)
- *reply = uncle
+ *reply = v.Uncles[args.Index]
}
case "eth_getCompilers":
c := []string{""}
diff --git a/rpc/responses.go b/rpc/responses.go
index 079ee8765..52a2f714c 100644
--- a/rpc/responses.go
+++ b/rpc/responses.go
@@ -28,7 +28,7 @@ type BlockRes struct {
GasUsed *hexnum `json:"gasUsed"`
UnixTimestamp *hexnum `json:"timestamp"`
Transactions []*TransactionRes `json:"transactions"`
- Uncles []*hexdata `json:"uncles"`
+ Uncles []*UncleRes `json:"uncles"`
}
func (b *BlockRes) MarshalJSON() ([]byte, error) {
@@ -73,7 +73,10 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
ext.GasUsed = b.GasUsed
ext.UnixTimestamp = b.UnixTimestamp
ext.Transactions = b.Transactions
- ext.Uncles = b.Uncles
+ ext.Uncles = make([]*hexdata, len(b.Uncles))
+ for i, u := range b.Uncles {
+ ext.Uncles[i] = u.BlockHash
+ }
return json.Marshal(ext)
} else {
var ext struct {
@@ -119,7 +122,10 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
for i, tx := range b.Transactions {
ext.Transactions[i] = tx.Hash
}
- ext.Uncles = b.Uncles
+ ext.Uncles = make([]*hexdata, len(b.Uncles))
+ for i, u := range b.Uncles {
+ ext.Uncles[i] = u.BlockHash
+ }
return json.Marshal(ext)
}
}
@@ -157,9 +163,9 @@ func NewBlockRes(block *types.Block, fullTx bool) *BlockRes {
res.Transactions[i].TxIndex = newHexNum(i)
}
- res.Uncles = make([]*hexdata, len(block.Uncles()))
+ res.Uncles = make([]*UncleRes, len(block.Uncles()))
for i, uncle := range block.Uncles() {
- res.Uncles[i] = newHexData(uncle.Hash())
+ res.Uncles[i] = NewUncleRes(uncle)
}
return res
@@ -200,6 +206,49 @@ func NewTransactionRes(tx *types.Transaction) *TransactionRes {
return v
}
+type UncleRes struct {
+ BlockNumber *hexnum `json:"number"`
+ BlockHash *hexdata `json:"hash"`
+ ParentHash *hexdata `json:"parentHash"`
+ Nonce *hexdata `json:"nonce"`
+ Sha3Uncles *hexdata `json:"sha3Uncles"`
+ ReceiptHash *hexdata `json:"receiptHash"`
+ LogsBloom *hexdata `json:"logsBloom"`
+ TransactionRoot *hexdata `json:"transactionsRoot"`
+ StateRoot *hexdata `json:"stateRoot"`
+ Miner *hexdata `json:"miner"`
+ Difficulty *hexnum `json:"difficulty"`
+ ExtraData *hexdata `json:"extraData"`
+ GasLimit *hexnum `json:"gasLimit"`
+ GasUsed *hexnum `json:"gasUsed"`
+ UnixTimestamp *hexnum `json:"timestamp"`
+}
+
+func NewUncleRes(h *types.Header) *UncleRes {
+ if h == nil {
+ return nil
+ }
+
+ var v = new(UncleRes)
+ v.BlockNumber = newHexNum(h.Number)
+ v.BlockHash = newHexData(h.Hash())
+ v.ParentHash = newHexData(h.ParentHash)
+ v.Sha3Uncles = newHexData(h.UncleHash)
+ v.Nonce = newHexData(h.Nonce[:])
+ v.LogsBloom = newHexData(h.Bloom)
+ v.TransactionRoot = newHexData(h.TxHash)
+ v.StateRoot = newHexData(h.Root)
+ v.Miner = newHexData(h.Coinbase)
+ v.Difficulty = newHexNum(h.Difficulty)
+ v.ExtraData = newHexData(h.Extra)
+ v.GasLimit = newHexNum(h.GasLimit)
+ v.GasUsed = newHexNum(h.GasUsed)
+ v.UnixTimestamp = newHexNum(h.Time)
+ v.ReceiptHash = newHexData(h.ReceiptHash)
+
+ return v
+}
+
// type FilterLogRes struct {
// Hash string `json:"hash"`
// Address string `json:"address"`