54 lines
1.7 KiB
Go
54 lines
1.7 KiB
Go
// Copyright 2017 AMIS Technologies
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package container
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/consensus/istanbul"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/crypto/sha3"
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
|
|
"github.com/getamis/istanbul-tools/cmd/istanbul/extra"
|
|
)
|
|
|
|
func sigHash(header *types.Header) (hash common.Hash) {
|
|
hasher := sha3.NewKeccak256()
|
|
|
|
// Clean seal is required for calculating proposer seal.
|
|
rlp.Encode(hasher, types.IstanbulFilteredHeader(header, false))
|
|
hasher.Sum(hash[:0])
|
|
return hash
|
|
}
|
|
|
|
func GetProposer(header *types.Header) common.Address {
|
|
if header == nil {
|
|
return common.Address{}
|
|
}
|
|
|
|
_, istanbulExtra, err := extra.Decode(common.ToHex(header.Extra))
|
|
if err != nil {
|
|
return common.Address{}
|
|
}
|
|
|
|
addr, err := istanbul.GetSignatureAddress(sigHash(header).Bytes(), istanbulExtra.Seal)
|
|
if err != nil {
|
|
return common.Address{}
|
|
}
|
|
return addr
|
|
}
|