mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
Merge pull request #435 from maticnetwork/POS-553
Adding correct miner address on API at the RPC level (POS-553)
This commit is contained in:
commit
657d262def
1 changed files with 25 additions and 0 deletions
|
|
@ -814,6 +814,20 @@ func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.H
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getAuthor: returns the author of the Block
|
||||||
|
func (s *PublicBlockChainAPI) getAuthor(head *types.Header) *common.Address {
|
||||||
|
// get author using Author() function from: /consensus/clique/clique.go
|
||||||
|
// In Production: get author using Author() function from: /consensus/bor/bor.go
|
||||||
|
author, err := s.b.Engine().Author(head)
|
||||||
|
// make sure we don't send error to the user, return 0x0 instead
|
||||||
|
if err != nil {
|
||||||
|
add := common.HexToAddress("0x0000000000000000000000000000000000000000")
|
||||||
|
return &add
|
||||||
|
}
|
||||||
|
// change the coinbase (0x0) with the miner address
|
||||||
|
return &author
|
||||||
|
}
|
||||||
|
|
||||||
// GetBlockByNumber returns the requested canonical block.
|
// GetBlockByNumber returns the requested canonical block.
|
||||||
// * When blockNr is -1 the chain head is returned.
|
// * When blockNr is -1 the chain head is returned.
|
||||||
// * When blockNr is -2 the pending chain head is returned.
|
// * When blockNr is -2 the pending chain head is returned.
|
||||||
|
|
@ -822,6 +836,7 @@ func (s *PublicBlockChainAPI) GetHeaderByHash(ctx context.Context, hash common.H
|
||||||
func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
|
func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
|
||||||
block, err := s.b.BlockByNumber(ctx, number)
|
block, err := s.b.BlockByNumber(ctx, number)
|
||||||
if block != nil && err == nil {
|
if block != nil && err == nil {
|
||||||
|
|
||||||
response, err := s.rpcMarshalBlock(ctx, block, true, fullTx)
|
response, err := s.rpcMarshalBlock(ctx, block, true, fullTx)
|
||||||
if err == nil && number == rpc.PendingBlockNumber {
|
if err == nil && number == rpc.PendingBlockNumber {
|
||||||
// Pending blocks need to nil out a few fields
|
// Pending blocks need to nil out a few fields
|
||||||
|
|
@ -830,6 +845,12 @@ func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.B
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err == nil && number != rpc.PendingBlockNumber {
|
||||||
|
author := s.getAuthor(block.Header())
|
||||||
|
|
||||||
|
response["miner"] = author
|
||||||
|
}
|
||||||
|
|
||||||
// append marshalled bor transaction
|
// append marshalled bor transaction
|
||||||
if err == nil && response != nil {
|
if err == nil && response != nil {
|
||||||
response = s.appendRPCMarshalBorTransaction(ctx, block, response, fullTx)
|
response = s.appendRPCMarshalBorTransaction(ctx, block, response, fullTx)
|
||||||
|
|
@ -848,6 +869,10 @@ func (s *PublicBlockChainAPI) GetBlockByHash(ctx context.Context, hash common.Ha
|
||||||
response, err := s.rpcMarshalBlock(ctx, block, true, fullTx)
|
response, err := s.rpcMarshalBlock(ctx, block, true, fullTx)
|
||||||
// append marshalled bor transaction
|
// append marshalled bor transaction
|
||||||
if err == nil && response != nil {
|
if err == nil && response != nil {
|
||||||
|
author := s.getAuthor(block.Header())
|
||||||
|
|
||||||
|
response["miner"] = author
|
||||||
|
|
||||||
return s.appendRPCMarshalBorTransaction(ctx, block, response, fullTx), err
|
return s.appendRPCMarshalBorTransaction(ctx, block, response, fullTx), err
|
||||||
}
|
}
|
||||||
return response, err
|
return response, err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue