github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/consensus/cbft/api.go (about) 1 package cbft 2 3 import ( 4 "github.com/PlatONnetwork/PlatON-Go/common" 5 "github.com/PlatONnetwork/PlatON-Go/consensus" 6 "github.com/PlatONnetwork/PlatON-Go/core/types" 7 "github.com/PlatONnetwork/PlatON-Go/crypto" 8 "github.com/PlatONnetwork/PlatON-Go/rpc" 9 ) 10 11 type API struct { 12 chain consensus.ChainReader 13 cbft *Cbft 14 } 15 16 // Get the block address 17 func (api *API) GetProducer(number *rpc.BlockNumber) (common.Address, error) { 18 // Retrieve the requested block number (or current if none requested) 19 var header *types.Header 20 if number == nil || *number == rpc.LatestBlockNumber { 21 header = api.chain.CurrentHeader() 22 } else { 23 header = api.chain.GetHeaderByNumber(uint64(number.Int64())) 24 } 25 // Ensure we have an actually valid block and return the signers from its snapshot 26 if header == nil { 27 return common.Address{}, errUnknownBlock 28 } 29 nodeID, _, err := ecrecover(header) 30 31 if err != nil { 32 return common.Address{}, err 33 } 34 35 var signer common.Address 36 copy(signer[:], crypto.Keccak256(nodeID.Bytes()[1:])[12:]) 37 38 return signer, nil 39 }