# Path: hydrachain/utils.py
# def sha3(seed):
#     return sha3_256(bytes(seed)).digest()
# 
# def phx(x):
#     return x.encode('hex')[:8]


from collections import Counter
from bitcoin.main import encode_privkey
from ethereum.blocks import Block
from ethereum.utils import big_endian_to_int, zpad, int_to_32bytearray
from bitcoin import encode_pubkey, N, P
from rlp.sedes import big_endian_int, binary
from rlp.sedes import CountableList
from rlp.utils import encode_hex
from ethereum.blocks import BlockHeader
from ethereum.transactions import Transaction
from secp256k1 import PrivateKey, PublicKey, ALL_FLAGS
from hydrachain.utils import sha3, phx
import rlp
        if round > 0 and not round_lockset:
            raise InvalidProposalError('R>0 needs a round lockset')
        if round == 0 and round_lockset:
            raise InvalidProposalError('R0 must not have a round lockset')
        self.height = height
        self.round = round
        self.block = block
        self.signing_lockset = signing_lockset
        self.round_lockset = round_lockset or LockSet(0)

        super(BlockProposal, self).__init__(height, round, block, signing_lockset,
                                            self.round_lockset, v, r, s)

        if block.header.number != self.height:
            raise InvalidProposalError('lockset.height / block.number mismatch')
        if self.round_lockset and height != self.round_lockset.height:
            raise InvalidProposalError('height mismatch')
        if not (round > 0 or self.lockset.has_quorum):
            raise InvalidProposalError('R0 lockset == signing lockset needs quorum')
        if not (round > 0 or self.lockset.height == block.header.number - 1):
            raise InvalidProposalError('R0 round lockset must be from previous height')
        if not (round == 0 or round == self.lockset.round + 1):
            raise InvalidProposalError('Rn round lockset must be from previous round')
        if not self.signing_lockset.has_quorum:
            raise InvalidProposalError('signing lockset needs quorum')
        if not (self.signing_lockset.height == self.height - 1):
            raise InvalidProposalError('signing lockset height mismatch')
        if self.round_lockset and not round_lockset.has_noquorum:
            raise InvalidProposalError('at R>0 can only propose if there is a NoQuorum for R-1')


# Path: hydrachain/utils.py
# def sha3(seed):
#     return sha3_256(bytes(seed)).digest()
# 
# def phx(x):
#     return x.encode('hex')[:8]


# Path: hydrachain/consensus/base.py
from collections import Counter
from bitcoin.main import encode_privkey
from ethereum.blocks import Block
from ethereum.utils import big_endian_to_int, zpad, int_to_32bytearray
from bitcoin import encode_pubkey, N, P
from rlp.sedes import big_endian_int, binary
from rlp.sedes import CountableList
from rlp.utils import encode_hex
from ethereum.blocks import BlockHeader
from ethereum.transactions import Transaction
from secp256k1 import PrivateKey, PublicKey, ALL_FLAGS
from hydrachain.utils import sha3, phx
import rlp

        if round > 0 and not round_lockset:
            raise InvalidProposalError('R>0 needs a round lockset')
        if round == 0 and round_lockset:
            raise InvalidProposalError('R0 must not have a round lockset')
        self.height = height
        self.round = round
        self.block = block
        self.signing_lockset = signing_lockset
        self.round_lockset = round_lockset or LockSet(0)

        super(BlockProposal, self).__init__(height, round, block, signing_lockset,
                                            self.round_lockset, v, r, s)

        if block.header.number != self.height:
            raise InvalidProposalError('lockset.height / block.number mismatch')
        if self.round_lockset and height != self.round_lockset.height:
            raise InvalidProposalError('height mismatch')
        if not (round > 0 or self.lockset.has_quorum):
            raise InvalidProposalError('R0 lockset == signing lockset needs quorum')
        if not (round > 0 or self.lockset.height == block.header.number - 1):
            raise InvalidProposalError('R0 round lockset must be from previous height')
        if not (round == 0 or round == self.lockset.round + 1):
            raise InvalidProposalError('Rn round lockset must be from previous round')
        if not self.signing_lockset.has_quorum:
            raise InvalidProposalError('signing lockset needs quorum')
        if not (self.signing_lockset.height == self.height - 1):
            raise InvalidProposalError('signing lockset height mismatch')
        if self.round_lockset and not round_lockset.has_noquorum:
            raise InvalidProposalError('at R>0 can only propose if there is a NoQuorum for R-1')


        self.rawhash = sha3(rlp.encode(self, self.__class__.exclude(['v', 'r', 's'])))