diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-04-01 22:49:07 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-04-01 22:49:07 +0800 |
commit | b6f0b400375dfe3ae1ada954f14fa15155163f1e (patch) | |
tree | dd5817266d5d4d027575a7e9b2db307039bd3d94 /rpc/responses.go | |
parent | 55b9689950dbb3f47e2d4720d04d2539243429bd (diff) | |
download | go-tangerine-b6f0b400375dfe3ae1ada954f14fa15155163f1e.tar go-tangerine-b6f0b400375dfe3ae1ada954f14fa15155163f1e.tar.gz go-tangerine-b6f0b400375dfe3ae1ada954f14fa15155163f1e.tar.bz2 go-tangerine-b6f0b400375dfe3ae1ada954f14fa15155163f1e.tar.lz go-tangerine-b6f0b400375dfe3ae1ada954f14fa15155163f1e.tar.xz go-tangerine-b6f0b400375dfe3ae1ada954f14fa15155163f1e.tar.zst go-tangerine-b6f0b400375dfe3ae1ada954f14fa15155163f1e.zip |
Respect fullTx option #614
Diffstat (limited to 'rpc/responses.go')
-rw-r--r-- | rpc/responses.go | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/rpc/responses.go b/rpc/responses.go index 41776a0be..172a0902f 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -1,6 +1,8 @@ package rpc import ( + "encoding/json" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" ) @@ -29,6 +31,99 @@ type BlockRes struct { Uncles []*hexdata `json:"uncles"` } +func (b *BlockRes) MarshalJSON() ([]byte, error) { + if b.fullTx { + var ext struct { + BlockNumber *hexnum `json:"number"` + BlockHash *hexdata `json:"hash"` + ParentHash *hexdata `json:"parentHash"` + Nonce *hexdata `json:"nonce"` + Sha3Uncles *hexdata `json:"sha3Uncles"` + LogsBloom *hexdata `json:"logsBloom"` + TransactionRoot *hexdata `json:"transactionRoot"` + StateRoot *hexdata `json:"stateRoot"` + Miner *hexdata `json:"miner"` + Difficulty *hexnum `json:"difficulty"` + TotalDifficulty *hexnum `json:"totalDifficulty"` + Size *hexnum `json:"size"` + ExtraData *hexdata `json:"extraData"` + GasLimit *hexnum `json:"gasLimit"` + MinGasPrice *hexnum `json:"minGasPrice"` + GasUsed *hexnum `json:"gasUsed"` + UnixTimestamp *hexnum `json:"timestamp"` + Transactions []*TransactionRes `json:"transactions"` + Uncles []*hexdata `json:"uncles"` + } + + ext.BlockNumber = b.BlockNumber + ext.BlockHash = b.BlockHash + ext.ParentHash = b.ParentHash + ext.Nonce = b.Nonce + ext.Sha3Uncles = b.Sha3Uncles + ext.LogsBloom = b.LogsBloom + ext.TransactionRoot = b.TransactionRoot + ext.StateRoot = b.StateRoot + ext.Miner = b.Miner + ext.Difficulty = b.Difficulty + ext.TotalDifficulty = b.TotalDifficulty + ext.Size = b.Size + ext.ExtraData = b.ExtraData + ext.GasLimit = b.GasLimit + ext.MinGasPrice = b.MinGasPrice + ext.GasUsed = b.GasUsed + ext.UnixTimestamp = b.UnixTimestamp + ext.Transactions = b.Transactions + ext.Uncles = b.Uncles + return json.Marshal(ext) + } else { + var ext struct { + BlockNumber *hexnum `json:"number"` + BlockHash *hexdata `json:"hash"` + ParentHash *hexdata `json:"parentHash"` + Nonce *hexdata `json:"nonce"` + Sha3Uncles *hexdata `json:"sha3Uncles"` + LogsBloom *hexdata `json:"logsBloom"` + TransactionRoot *hexdata `json:"transactionRoot"` + StateRoot *hexdata `json:"stateRoot"` + Miner *hexdata `json:"miner"` + Difficulty *hexnum `json:"difficulty"` + TotalDifficulty *hexnum `json:"totalDifficulty"` + Size *hexnum `json:"size"` + ExtraData *hexdata `json:"extraData"` + GasLimit *hexnum `json:"gasLimit"` + MinGasPrice *hexnum `json:"minGasPrice"` + GasUsed *hexnum `json:"gasUsed"` + UnixTimestamp *hexnum `json:"timestamp"` + Transactions []*hexdata `json:"transactions"` + Uncles []*hexdata `json:"uncles"` + } + + ext.BlockNumber = b.BlockNumber + ext.BlockHash = b.BlockHash + ext.ParentHash = b.ParentHash + ext.Nonce = b.Nonce + ext.Sha3Uncles = b.Sha3Uncles + ext.LogsBloom = b.LogsBloom + ext.TransactionRoot = b.TransactionRoot + ext.StateRoot = b.StateRoot + ext.Miner = b.Miner + ext.Difficulty = b.Difficulty + ext.TotalDifficulty = b.TotalDifficulty + ext.Size = b.Size + ext.ExtraData = b.ExtraData + ext.GasLimit = b.GasLimit + ext.MinGasPrice = b.MinGasPrice + ext.GasUsed = b.GasUsed + ext.UnixTimestamp = b.UnixTimestamp + ext.Transactions = make([]*hexdata, len(b.Transactions)) + for i, tx := range b.Transactions { + ext.Transactions[i] = tx.Hash + } + ext.Uncles = b.Uncles + return json.Marshal(ext) + } +} + func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { // TODO respect fullTx flag |