aboutsummaryrefslogtreecommitdiffstats
path: root/internal/ethapi/api.go
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2018-06-11 16:03:40 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-06-11 16:03:40 +0800
commiteac16f98243206bee99c3daaa8aef08695f5b69e (patch)
treeb309897f09113b703e2ddd2bdd55352522cb6f6a /internal/ethapi/api.go
parent69c52bde3f5e48a3b74264bf4854e9768ede75b2 (diff)
downloaddexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.gz
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.bz2
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.lz
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.xz
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.zst
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.zip
core: improve getBadBlocks to return full block rlp (#16902)
* core: improve getBadBlocks to return full block rlp * core, eth, ethapi: changes to getBadBlocks formatting * ethapi: address review concerns
Diffstat (limited to 'internal/ethapi/api.go')
-rw-r--r--internal/ethapi/api.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index 87eba7e1a..7a736bb76 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -792,10 +792,10 @@ func FormatLogs(logs []vm.StructLog) []StructLogRes {
return formatted
}
-// rpcOutputBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
+// RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
// transaction hashes.
-func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
+func RPCMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
head := b.Header() // copies the header once
fields := map[string]interface{}{
"number": (*hexutil.Big)(head.Number),
@@ -808,7 +808,6 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
"stateRoot": head.Root,
"miner": head.Coinbase,
"difficulty": (*hexutil.Big)(head.Difficulty),
- "totalDifficulty": (*hexutil.Big)(s.b.GetTd(b.Hash())),
"extraData": hexutil.Bytes(head.Extra),
"size": hexutil.Uint64(b.Size()),
"gasLimit": hexutil.Uint64(head.GasLimit),
@@ -822,17 +821,15 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
formatTx := func(tx *types.Transaction) (interface{}, error) {
return tx.Hash(), nil
}
-
if fullTx {
formatTx = func(tx *types.Transaction) (interface{}, error) {
return newRPCTransactionFromBlockHash(b, tx.Hash()), nil
}
}
-
txs := b.Transactions()
transactions := make([]interface{}, len(txs))
var err error
- for i, tx := range b.Transactions() {
+ for i, tx := range txs {
if transactions[i], err = formatTx(tx); err != nil {
return nil, err
}
@@ -850,6 +847,17 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
return fields, nil
}
+// rpcOutputBlock uses the generalized output filler, then adds the total difficulty field, which requires
+// a `PublicBlockchainAPI`.
+func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
+ fields, err := RPCMarshalBlock(b, inclTx, fullTx)
+ if err != nil {
+ return nil, err
+ }
+ fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(b.Hash()))
+ return fields, err
+}
+
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
type RPCTransaction struct {
BlockHash common.Hash `json:"blockHash"`