Skip to content

Commit

Permalink
consensus/clique: use blockNrOrHash in getSignerForBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Jun 4, 2021
1 parent 1983fc5 commit 890673a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions consensus/clique/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package clique

import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -177,13 +178,22 @@ func (api *API) Status() (*status, error) {
}, nil
}

func (api *API) GetSignerForBlock(number *rpc.BlockNumber) (common.Address, error) {
// GetSignerForBlock returns the signer for a specific clique block.
func (api *API) GetSignerForBlock(blockNrOrHash *rpc.BlockNumberOrHash) (common.Address, error) {
var header *types.Header
if number == nil || *number == rpc.LatestBlockNumber {
if blockNrOrHash == nil {
header = api.chain.CurrentHeader()
} else {
} else if hash, ok := blockNrOrHash.Hash(); ok {
header = api.chain.GetHeaderByHash(hash)
} else if number, ok := blockNrOrHash.Number(); ok {
header = api.chain.GetHeaderByNumber(uint64(number.Int64()))
}
if header == nil {
return common.Address{}, errors.New("could not find header")
}
if len(header.Extra)-extraSeal < 0 {
return common.Address{}, errors.New("invalid extra data in header")
}
signature := header.Extra[len(header.Extra)-extraSeal:]
// Recover the public key and the Ethereum address
pubkey, err := crypto.Ecrecover(SealHash(header).Bytes(), signature)
Expand Down

0 comments on commit 890673a

Please sign in to comment.