Merge pull request #14548 from karalabe/ethstats-no-txs

ethstats: don't report transaction content, only hash
This commit is contained in:
Péter Szilágyi 2017-05-30 12:54:00 +03:00 committed by GitHub
commit e96f2981e2
1 changed files with 10 additions and 12 deletions

View File

@ -427,21 +427,15 @@ type blockStats struct {
GasLimit *big.Int `json:"gasLimit"` GasLimit *big.Int `json:"gasLimit"`
Diff string `json:"difficulty"` Diff string `json:"difficulty"`
TotalDiff string `json:"totalDifficulty"` TotalDiff string `json:"totalDifficulty"`
Txs txStats `json:"transactions"` Txs []txStats `json:"transactions"`
TxHash common.Hash `json:"transactionsRoot"` TxHash common.Hash `json:"transactionsRoot"`
Root common.Hash `json:"stateRoot"` Root common.Hash `json:"stateRoot"`
Uncles uncleStats `json:"uncles"` Uncles uncleStats `json:"uncles"`
} }
// txStats is a custom wrapper around a transaction array to force serializing // txStats is the information to report about individual transactions.
// empty arrays instead of returning null for them. type txStats struct {
type txStats []*types.Transaction Hash common.Hash `json:"hash"`
func (s txStats) MarshalJSON() ([]byte, error) {
if txs := ([]*types.Transaction)(s); len(txs) > 0 {
return json.Marshal(txs)
}
return []byte("[]"), nil
} }
// uncleStats is a custom wrapper around an uncle array to force serializing // uncleStats is a custom wrapper around an uncle array to force serializing
@ -480,7 +474,7 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
var ( var (
header *types.Header header *types.Header
td *big.Int td *big.Int
txs []*types.Transaction txs []txStats
uncles []*types.Header uncles []*types.Header
) )
if s.eth != nil { if s.eth != nil {
@ -491,7 +485,10 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
header = block.Header() header = block.Header()
td = s.eth.BlockChain().GetTd(header.Hash(), header.Number.Uint64()) td = s.eth.BlockChain().GetTd(header.Hash(), header.Number.Uint64())
txs = block.Transactions() txs = make([]txStats, len(block.Transactions()))
for i, tx := range block.Transactions() {
txs[i].Hash = tx.Hash()
}
uncles = block.Uncles() uncles = block.Uncles()
} else { } else {
// Light nodes would need on-demand lookups for transactions/uncles, skip // Light nodes would need on-demand lookups for transactions/uncles, skip
@ -501,6 +498,7 @@ func (s *Service) assembleBlockStats(block *types.Block) *blockStats {
header = s.les.BlockChain().CurrentHeader() header = s.les.BlockChain().CurrentHeader()
} }
td = s.les.BlockChain().GetTd(header.Hash(), header.Number.Uint64()) td = s.les.BlockChain().GetTd(header.Hash(), header.Number.Uint64())
txs = []txStats{}
} }
// Assemble and return the block stats // Assemble and return the block stats
author, _ := s.engine.Author(header) author, _ := s.engine.Author(header)