Ejemplo n.º 1
0
    def apply(self, transaction, state):

        txn_header = TransactionHeader()
        txn_header.ParseFromString(transaction.header)
        pubkey = txn_header.signer_pubkey

        auth_type = _get_auth_type(state)
        auth_keys = _get_auth_keys(state)
        if len(auth_keys) > 0 and pubkey not in auth_keys:
            raise InvalidTransaction(
                '{} is not authorized to change settings'.format(pubkey))

        config_payload = ConfigPayload()
        config_payload.ParseFromString(transaction.payload)

        if auth_type == 'Ballot':
            return self._apply_ballot_config(pubkey, config_payload, auth_keys,
                                             state)
        elif auth_type == 'None':
            return self._apply_noauth_config(pubkey, config_payload, state)
        else:
            LOGGER.error('auth_type %s should not have been allowed',
                         auth_type)
            raise InternalError(
                'auth_type {} should not have been allowed'.format(auth_type))
Ejemplo n.º 2
0
    def apply(self, transaction, state):

        txn_header = TransactionHeader()
        txn_header.ParseFromString(transaction.header)
        pubkey = txn_header.signer_pubkey

        auth_keys = _get_auth_keys(state)
        if len(auth_keys) > 0 and pubkey not in auth_keys:
            raise InvalidTransaction(
                '{} is not authorized to change settings'.format(pubkey))

        config_payload = ConfigPayload()
        config_payload.ParseFromString(transaction.payload)

        if config_payload.action == ConfigPayload.PROPOSE:
            return self._apply_proposal(
                auth_keys, pubkey, config_payload.data, state)
        elif config_payload.action == ConfigPayload.VOTE:
            return self._apply_vote(pubkey, config_payload.data,
                                    auth_keys, state)
        else:
            raise InvalidTransaction(
                "'action' must be one of {PROPOSE, VOTE} in 'Ballot' mode")
Ejemplo n.º 3
0
    def create_vote_proposal(self, proposal_id, setting, vote):
        vote = ConfigVote(proposal_id=proposal_id, vote=vote)
        payload = ConfigPayload(action=ConfigPayload.VOTE,
                                data=vote.SerializeToString())

        return self._create_tp_process_request(setting, payload)
Ejemplo n.º 4
0
    def create_proposal_transaction(self, setting, value, nonce):
        proposal = ConfigProposal(setting=setting, value=value, nonce=nonce)
        payload = ConfigPayload(action=ConfigPayload.PROPOSE,
                                data=proposal.SerializeToString())

        return self._create_tp_process_request(setting, payload)