mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
internal/ethapi: remove td field from block
This commit is contained in:
parent
922eb033d3
commit
29d3d62fa0
5 changed files with 10 additions and 44 deletions
|
|
@ -1934,7 +1934,7 @@ func SetDNSDiscoveryDefaults(cfg *ethconfig.Config, genesis common.Hash) {
|
||||||
|
|
||||||
// RegisterEthService adds an Ethereum client to the stack.
|
// RegisterEthService adds an Ethereum client to the stack.
|
||||||
// The second return value is the full node instance.
|
// The second return value is the full node instance.
|
||||||
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend, *eth.Ethereum) {
|
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (*eth.EthAPIBackend, *eth.Ethereum) {
|
||||||
backend, err := eth.New(stack, cfg)
|
backend, err := eth.New(stack, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Failed to register the Ethereum service: %v", err)
|
Fatalf("Failed to register the Ethereum service: %v", err)
|
||||||
|
|
@ -1944,7 +1944,7 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterEthStatsService configures the Ethereum Stats daemon and adds it to the node.
|
// RegisterEthStatsService configures the Ethereum Stats daemon and adds it to the node.
|
||||||
func RegisterEthStatsService(stack *node.Node, backend ethapi.Backend, url string) {
|
func RegisterEthStatsService(stack *node.Node, backend *eth.EthAPIBackend, url string) {
|
||||||
if err := ethstats.New(stack, backend, backend.Engine(), url); err != nil {
|
if err := ethstats.New(stack, backend, backend.Engine(), url); err != nil {
|
||||||
Fatalf("Failed to register the Ethereum Stats service: %v", err)
|
Fatalf("Failed to register the Ethereum Stats service: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -906,18 +906,6 @@ func (b *Block) LogsBloom(ctx context.Context) (hexutil.Bytes, error) {
|
||||||
return header.Bloom.Bytes(), nil
|
return header.Bloom.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Block) TotalDifficulty(ctx context.Context) (hexutil.Big, error) {
|
|
||||||
hash, err := b.Hash(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return hexutil.Big{}, err
|
|
||||||
}
|
|
||||||
td := b.r.backend.GetTd(ctx, hash)
|
|
||||||
if td == nil {
|
|
||||||
return hexutil.Big{}, fmt.Errorf("total difficulty not found %x", hash)
|
|
||||||
}
|
|
||||||
return hexutil.Big(*td), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *Block) RawHeader(ctx context.Context) (hexutil.Bytes, error) {
|
func (b *Block) RawHeader(ctx context.Context) (hexutil.Bytes, error) {
|
||||||
header, err := b.resolveHeader(ctx)
|
header, err := b.resolveHeader(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -232,9 +232,6 @@ const schema string = `
|
||||||
mixHash: Bytes32!
|
mixHash: Bytes32!
|
||||||
# Difficulty is a measure of the difficulty of mining this block.
|
# Difficulty is a measure of the difficulty of mining this block.
|
||||||
difficulty: BigInt!
|
difficulty: BigInt!
|
||||||
# TotalDifficulty is the sum of all difficulty values up to and including
|
|
||||||
# this block.
|
|
||||||
totalDifficulty: BigInt!
|
|
||||||
# OmmerCount is the number of ommers (AKA uncles) associated with this
|
# OmmerCount is the number of ommers (AKA uncles) associated with this
|
||||||
# block. If ommers are unavailable, this field will be null.
|
# block. If ommers are unavailable, this field will be null.
|
||||||
ommerCount: Long
|
ommerCount: Long
|
||||||
|
|
|
||||||
|
|
@ -806,7 +806,7 @@ func decodeHash(s string) (h common.Hash, inputLength int, err error) {
|
||||||
func (api *BlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (map[string]interface{}, error) {
|
func (api *BlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (map[string]interface{}, error) {
|
||||||
header, err := api.b.HeaderByNumber(ctx, number)
|
header, err := api.b.HeaderByNumber(ctx, number)
|
||||||
if header != nil && err == nil {
|
if header != nil && err == nil {
|
||||||
response := api.rpcMarshalHeader(ctx, header)
|
response := RPCMarshalHeader(header)
|
||||||
if number == rpc.PendingBlockNumber {
|
if number == rpc.PendingBlockNumber {
|
||||||
// Pending header need to nil out a few fields
|
// Pending header need to nil out a few fields
|
||||||
for _, field := range []string{"hash", "nonce", "miner"} {
|
for _, field := range []string{"hash", "nonce", "miner"} {
|
||||||
|
|
@ -822,7 +822,7 @@ func (api *BlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.Bloc
|
||||||
func (api *BlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.Hash) map[string]interface{} {
|
func (api *BlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.Hash) map[string]interface{} {
|
||||||
header, _ := api.b.HeaderByHash(ctx, hash)
|
header, _ := api.b.HeaderByHash(ctx, hash)
|
||||||
if header != nil {
|
if header != nil {
|
||||||
return api.rpcMarshalHeader(ctx, header)
|
return RPCMarshalHeader(header)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -837,14 +837,14 @@ func (api *BlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.Hash)
|
||||||
func (api *BlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
|
func (api *BlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
|
||||||
block, err := api.b.BlockByNumber(ctx, number)
|
block, err := api.b.BlockByNumber(ctx, number)
|
||||||
if block != nil && err == nil {
|
if block != nil && err == nil {
|
||||||
response, err := api.rpcMarshalBlock(ctx, block, true, fullTx)
|
response := RPCMarshalBlock(block, true, fullTx, api.b.ChainConfig())
|
||||||
if err == nil && number == rpc.PendingBlockNumber {
|
if number == rpc.PendingBlockNumber {
|
||||||
// Pending blocks need to nil out a few fields
|
// Pending blocks need to nil out a few fields
|
||||||
for _, field := range []string{"hash", "nonce", "miner"} {
|
for _, field := range []string{"hash", "nonce", "miner"} {
|
||||||
response[field] = nil
|
response[field] = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response, err
|
return response, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -854,7 +854,7 @@ func (api *BlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.Block
|
||||||
func (api *BlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error) {
|
func (api *BlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error) {
|
||||||
block, err := api.b.BlockByHash(ctx, hash)
|
block, err := api.b.BlockByHash(ctx, hash)
|
||||||
if block != nil {
|
if block != nil {
|
||||||
return api.rpcMarshalBlock(ctx, block, true, fullTx)
|
return RPCMarshalBlock(block, true, fullTx, api.b.ChainConfig()), nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -869,7 +869,7 @@ func (api *BlockChainAPI) GetUncleByBlockNumberAndIndex(ctx context.Context, blo
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
block = types.NewBlockWithHeader(uncles[index])
|
block = types.NewBlockWithHeader(uncles[index])
|
||||||
return api.rpcMarshalBlock(ctx, block, false, false)
|
return RPCMarshalBlock(block, false, false, api.b.ChainConfig()), nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -884,7 +884,7 @@ func (api *BlockChainAPI) GetUncleByBlockHashAndIndex(ctx context.Context, block
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
block = types.NewBlockWithHeader(uncles[index])
|
block = types.NewBlockWithHeader(uncles[index])
|
||||||
return api.rpcMarshalBlock(ctx, block, false, false)
|
return RPCMarshalBlock(block, false, false, api.b.ChainConfig()), nil
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -1306,24 +1306,6 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
|
||||||
return fields
|
return fields
|
||||||
}
|
}
|
||||||
|
|
||||||
// rpcMarshalHeader uses the generalized output filler, then adds the total difficulty field, which requires
|
|
||||||
// a `BlockchainAPI`.
|
|
||||||
func (api *BlockChainAPI) rpcMarshalHeader(ctx context.Context, header *types.Header) map[string]interface{} {
|
|
||||||
fields := RPCMarshalHeader(header)
|
|
||||||
fields["totalDifficulty"] = (*hexutil.Big)(api.b.GetTd(ctx, header.Hash()))
|
|
||||||
return fields
|
|
||||||
}
|
|
||||||
|
|
||||||
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
|
|
||||||
// a `BlockchainAPI`.
|
|
||||||
func (api *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
|
|
||||||
fields := RPCMarshalBlock(b, inclTx, fullTx, api.b.ChainConfig())
|
|
||||||
if inclTx {
|
|
||||||
fields["totalDifficulty"] = (*hexutil.Big)(api.b.GetTd(ctx, b.Hash()))
|
|
||||||
}
|
|
||||||
return fields, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
|
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
|
||||||
type RPCTransaction struct {
|
type RPCTransaction struct {
|
||||||
BlockHash *common.Hash `json:"blockHash"`
|
BlockHash *common.Hash `json:"blockHash"`
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,6 @@ type Backend interface {
|
||||||
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
|
StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
|
||||||
Pending() (*types.Block, types.Receipts, *state.StateDB)
|
Pending() (*types.Block, types.Receipts, *state.StateDB)
|
||||||
GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
|
GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error)
|
||||||
GetTd(ctx context.Context, hash common.Hash) *big.Int
|
|
||||||
GetEVM(ctx context.Context, msg *core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM
|
GetEVM(ctx context.Context, msg *core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM
|
||||||
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
|
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
|
||||||
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
|
SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue