Пример #1
0
 def get_all_awaiting_pubkey_for(address):
     cps = ConsensusProtocol.get_all()
     cps = filter(lambda cp: cp.data is not None, cps)
     cps = filter(lambda cp: cp.data.type == ConsensusData.DATA_TYPE_VOTING,
                  cps)
     cps = filter(lambda cp: address in cp.data.addresses, cps)
     return cps
Пример #2
0
    def compute_and_cast_vote(consensus_id, fromaddress, answerNo,
                              previous_vote_hash):
        """
        Generates the answer message with linkable ring signature and posts
        it using ConsensusProtocol.post_message(message).
        
        This method should be invoked by
        shared.workerQueue.put( ("castVote", ( consensus_id, fromaddress, answerNo, previous_vote_hash ) ) ) 
        """
        log_debug("compute_and_cast_vote(%d, %s, %d)" %
                  (consensus_id, fromaddress, answerNo))
        cp = ConsensusProtocol.read_from_id(consensus_id)
        if cp is None:
            return None
        cp.update_status_bar("Computing vote...")

        # We can allow votes to be cast up until the commitment phase started.
        # It can happen that a user queues the vote in the work queue just before
        # the deadline, and the posting window closes in the meantime.
        # We still want the vote to be sent.
        if cp.get_status() > ConsensusProtocol.STATUS_COMMITMENT_PHASE:
            return None

        if answerNo < 0 or answerNo >= len(cp.data.answers):
            raise Exception('Invalid answer number: %d' % answerNo)

        if fromaddress not in cp.data.addresses:
            raise Exception(
                'Vote casting address not in list of voter addresses! (%s)' %
                fromaddress)

        privSigningKey = helper_keys.getPrivateSigningKey(fromaddress)
        if privSigningKey is None:
            raise Exception(
                "Vote: We don't have the private keys for address %s" %
                fromaddress)
        privSigningKey = arithmetic.decode(privSigningKey, 256)

        signer_index = cp.data.addresses.index(fromaddress)

        message = VotingData.encode_vote(answerNo, previous_vote_hash)

        rs = RingSignature.sign_message(message, cp.data.signing_keys,
                                        privSigningKey, signer_index)
        c0, ss, Y_tilde = rs

        data = VotingData.encode_ring_signature(message, c0, ss, Y_tilde)
        message_hash = cp.post_message(data)
        cp.update_status_bar('')
        cp.data.settings_set_already_voted_address(fromaddress, message_hash)
        cp.refresh_ui()
    def compute_and_cast_vote(consensus_id, fromaddress, answerNo, previous_vote_hash):
        """
        Generates the answer message with linkable ring signature and posts
        it using ConsensusProtocol.post_message(message).
        
        This method should be invoked by
        shared.workerQueue.put( ("castVote", ( consensus_id, fromaddress, answerNo, previous_vote_hash ) ) ) 
        """
        log_debug("compute_and_cast_vote(%d, %s, %d)" % ( consensus_id, fromaddress, answerNo ) )
        cp = ConsensusProtocol.read_from_id( consensus_id )
        if cp is None:
            return None
        cp.update_status_bar( "Computing vote..." )
        
        # We can allow votes to be cast up until the commitment phase started.
        # It can happen that a user queues the vote in the work queue just before
        # the deadline, and the posting window closes in the meantime.
        # We still want the vote to be sent.
        if cp.get_status() > ConsensusProtocol.STATUS_COMMITMENT_PHASE:
            return None
        
        if answerNo < 0 or answerNo >= len( cp.data.answers ):
            raise Exception( 'Invalid answer number: %d' % answerNo )
        
        if fromaddress not in cp.data.addresses:
            raise Exception( 'Vote casting address not in list of voter addresses! (%s)' % fromaddress )

        privSigningKey = helper_keys.getPrivateSigningKey( fromaddress )
        if privSigningKey is None:
            raise Exception( "Vote: We don't have the private keys for address %s" % fromaddress )
        privSigningKey = arithmetic.decode( privSigningKey, 256 )
        
        signer_index = cp.data.addresses.index( fromaddress )
        
        message = VotingData.encode_vote( answerNo, previous_vote_hash )

        rs = RingSignature.sign_message(message, cp.data.signing_keys, privSigningKey, signer_index)
        c0, ss, Y_tilde = rs
        
        data = VotingData.encode_ring_signature( message, c0, ss, Y_tilde)
        message_hash = cp.post_message( data )
        cp.update_status_bar( '' )
        cp.data.settings_set_already_voted_address( fromaddress, message_hash )
        cp.refresh_ui()
 def get_all_awaiting_pubkey_for( address ):
     cps = ConsensusProtocol.get_all()
     cps = filter( lambda cp: cp.data is not None, cps )
     cps = filter( lambda cp: cp.data.type == ConsensusData.DATA_TYPE_VOTING, cps )
     cps = filter( lambda cp: address in cp.data.addresses, cps )
     return cps