diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-09-08 01:43:01 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-09-11 22:42:25 +0800 |
commit | cdc2662c4098d68a7b450b9b9ff2688acbffcee4 (patch) | |
tree | 2dfb3b7365895203132bd6d1aa650b5a239b01eb /rpc/api | |
parent | 2b339cbbd8bb475d2195d54a71dcced700003430 (diff) | |
download | go-tangerine-cdc2662c4098d68a7b450b9b9ff2688acbffcee4.tar.gz go-tangerine-cdc2662c4098d68a7b450b9b9ff2688acbffcee4.tar.zst go-tangerine-cdc2662c4098d68a7b450b9b9ff2688acbffcee4.zip |
core: split out TD from database and all internals
Diffstat (limited to 'rpc/api')
-rw-r--r-- | rpc/api/eth.go | 72 | ||||
-rw-r--r-- | rpc/api/parsing.go | 4 |
2 files changed, 36 insertions, 40 deletions
diff --git a/rpc/api/eth.go b/rpc/api/eth.go index ba87e86c6..a93e41157 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -204,7 +204,8 @@ func (self *ethApi) GetBlockTransactionCountByHash(req *shared.Request) (interfa return nil, shared.NewDecodeParamError(err.Error()) } - block := NewBlockRes(self.xeth.EthBlockByHash(args.Hash), false) + raw := self.xeth.EthBlockByHash(args.Hash) + block := NewBlockRes(raw, self.xeth.Td(raw.Hash()), false) if block == nil { return nil, nil } else { @@ -218,7 +219,8 @@ func (self *ethApi) GetBlockTransactionCountByNumber(req *shared.Request) (inter return nil, shared.NewDecodeParamError(err.Error()) } - block := NewBlockRes(self.xeth.EthBlockByNumber(args.BlockNumber), false) + raw := self.xeth.EthBlockByNumber(args.BlockNumber) + block := NewBlockRes(raw, self.xeth.Td(raw.Hash()), false) if block == nil { return nil, nil } else { @@ -232,12 +234,12 @@ func (self *ethApi) GetUncleCountByBlockHash(req *shared.Request) (interface{}, return nil, shared.NewDecodeParamError(err.Error()) } - block := self.xeth.EthBlockByHash(args.Hash) - br := NewBlockRes(block, false) - if br == nil { + raw := self.xeth.EthBlockByHash(args.Hash) + block := NewBlockRes(raw, self.xeth.Td(raw.Hash()), false) + if block == nil { return nil, nil } - return newHexNum(big.NewInt(int64(len(br.Uncles))).Bytes()), nil + return newHexNum(big.NewInt(int64(len(block.Uncles))).Bytes()), nil } func (self *ethApi) GetUncleCountByBlockNumber(req *shared.Request) (interface{}, error) { @@ -246,12 +248,12 @@ func (self *ethApi) GetUncleCountByBlockNumber(req *shared.Request) (interface{} return nil, shared.NewDecodeParamError(err.Error()) } - block := self.xeth.EthBlockByNumber(args.BlockNumber) - br := NewBlockRes(block, false) - if br == nil { + raw := self.xeth.EthBlockByNumber(args.BlockNumber) + block := NewBlockRes(raw, self.xeth.Td(raw.Hash()), false) + if block == nil { return nil, nil } - return newHexNum(big.NewInt(int64(len(br.Uncles))).Bytes()), nil + return newHexNum(big.NewInt(int64(len(block.Uncles))).Bytes()), nil } func (self *ethApi) GetData(req *shared.Request) (interface{}, error) { @@ -362,7 +364,7 @@ func (self *ethApi) GetBlockByHash(req *shared.Request) (interface{}, error) { } block := self.xeth.EthBlockByHash(args.BlockHash) - return NewBlockRes(block, args.IncludeTxs), nil + return NewBlockRes(block, self.xeth.Td(block.Hash()), args.IncludeTxs), nil } func (self *ethApi) GetBlockByNumber(req *shared.Request) (interface{}, error) { @@ -372,8 +374,7 @@ func (self *ethApi) GetBlockByNumber(req *shared.Request) (interface{}, error) { } block := self.xeth.EthBlockByNumber(args.BlockNumber) - br := NewBlockRes(block, args.IncludeTxs) - return br, nil + return NewBlockRes(block, self.xeth.Td(block.Hash()), args.IncludeTxs), nil } func (self *ethApi) GetTransactionByHash(req *shared.Request) (interface{}, error) { @@ -402,16 +403,15 @@ func (self *ethApi) GetTransactionByBlockHashAndIndex(req *shared.Request) (inte return nil, shared.NewDecodeParamError(err.Error()) } - block := self.xeth.EthBlockByHash(args.Hash) - br := NewBlockRes(block, true) - if br == nil { + raw := self.xeth.EthBlockByHash(args.Hash) + block := NewBlockRes(raw, self.xeth.Td(raw.Hash()), true) + if block == nil { return nil, nil } - - if args.Index >= int64(len(br.Transactions)) || args.Index < 0 { + if args.Index >= int64(len(block.Transactions)) || args.Index < 0 { return nil, nil } else { - return br.Transactions[args.Index], nil + return block.Transactions[args.Index], nil } } @@ -421,17 +421,16 @@ func (self *ethApi) GetTransactionByBlockNumberAndIndex(req *shared.Request) (in return nil, shared.NewDecodeParamError(err.Error()) } - block := self.xeth.EthBlockByNumber(args.BlockNumber) - v := NewBlockRes(block, true) - if v == nil { + raw := self.xeth.EthBlockByNumber(args.BlockNumber) + block := NewBlockRes(raw, self.xeth.Td(raw.Hash()), true) + if block == nil { return nil, nil } - - if args.Index >= int64(len(v.Transactions)) || args.Index < 0 { + if args.Index >= int64(len(block.Transactions)) || args.Index < 0 { // return NewValidationError("Index", "does not exist") return nil, nil } - return v.Transactions[args.Index], nil + return block.Transactions[args.Index], nil } func (self *ethApi) GetUncleByBlockHashAndIndex(req *shared.Request) (interface{}, error) { @@ -440,17 +439,16 @@ func (self *ethApi) GetUncleByBlockHashAndIndex(req *shared.Request) (interface{ return nil, shared.NewDecodeParamError(err.Error()) } - br := NewBlockRes(self.xeth.EthBlockByHash(args.Hash), false) - if br == nil { + raw := self.xeth.EthBlockByHash(args.Hash) + block := NewBlockRes(raw, self.xeth.Td(raw.Hash()), false) + if block == nil { return nil, nil } - - if args.Index >= int64(len(br.Uncles)) || args.Index < 0 { + if args.Index >= int64(len(block.Uncles)) || args.Index < 0 { // return NewValidationError("Index", "does not exist") return nil, nil } - - return br.Uncles[args.Index], nil + return block.Uncles[args.Index], nil } func (self *ethApi) GetUncleByBlockNumberAndIndex(req *shared.Request) (interface{}, error) { @@ -459,17 +457,15 @@ func (self *ethApi) GetUncleByBlockNumberAndIndex(req *shared.Request) (interfac return nil, shared.NewDecodeParamError(err.Error()) } - block := self.xeth.EthBlockByNumber(args.BlockNumber) - v := NewBlockRes(block, true) - - if v == nil { + raw := self.xeth.EthBlockByNumber(args.BlockNumber) + block := NewBlockRes(raw, self.xeth.Td(raw.Hash()), true) + if block == nil { return nil, nil } - - if args.Index >= int64(len(v.Uncles)) || args.Index < 0 { + if args.Index >= int64(len(block.Uncles)) || args.Index < 0 { return nil, nil } else { - return v.Uncles[args.Index], nil + return block.Uncles[args.Index], nil } } diff --git a/rpc/api/parsing.go b/rpc/api/parsing.go index 5858bc136..cdfaa0ed1 100644 --- a/rpc/api/parsing.go +++ b/rpc/api/parsing.go @@ -281,7 +281,7 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) { } } -func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { +func NewBlockRes(block *types.Block, td *big.Int, fullTx bool) *BlockRes { if block == nil { return nil } @@ -299,7 +299,7 @@ func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { res.ReceiptRoot = newHexData(block.ReceiptHash()) res.Miner = newHexData(block.Coinbase()) res.Difficulty = newHexNum(block.Difficulty()) - res.TotalDifficulty = newHexNum(block.Td) + res.TotalDifficulty = newHexNum(td) res.Size = newHexNum(block.Size().Int64()) res.ExtraData = newHexData(block.Extra()) res.GasLimit = newHexNum(block.GasLimit()) |