Пример #1
0
    def _create_proposal(self, block_header, pbft_enclave_module):
        """
        proposal request
        """
        public_key_hash = hashlib.sha256(block_header.signer_public_key.encode()).hexdigest()
        nonce = SignupInfo.block_id_to_nonce(block_header.previous_block_id)

        setting = 'sawtooth.consensus.pbft.max_log_size'
        if False:
            # try to set pbft params
            
            proposal = SettingProposal(
                 setting=setting,
                 value='1003',
                 nonce=nonce)
            payload = SettingsPayload(data=proposal.SerializeToString(),action=SettingsPayload.PROPOSE)
            serialized = payload.SerializeToString()
            input_addresses = _config_inputs(setting) 
            output_addresses = _config_outputs(setting)

            header = txn_pb.TransactionHeader(
                signer_public_key=block_header.signer_public_key,
                family_name='sawtooth_settings',
                family_version='1.0',
                inputs=input_addresses,
                outputs=output_addresses,
                dependencies=[],
                payload_sha512=hashlib.sha512(serialized).hexdigest(),
                batcher_public_key=block_header.signer_public_key,
                nonce=hex(random.randint(0, 2**64))).SerializeToString()

            signature = self._batch_publisher.identity_signer.sign(header)

            transaction = txn_pb.Transaction(
                    header=header,
                    payload=serialized,
                    header_signature=signature)

            LOGGER.info('payload action=%s nonce=%s',
                payload.action,
                nonce)

            self._batch_publisher.send([transaction])
        else:
            # get setting
            pass
Пример #2
0
    def apply(self, transaction, context):

        txn_header = transaction.header
        public_key = txn_header.signer_public_key

        auth_keys = _get_auth_keys(context)
        if auth_keys and public_key not in auth_keys:
            raise InvalidTransaction(
                '{} is not authorized to change settings'.format(public_key))

        settings_payload = SettingsPayload()
        settings_payload.ParseFromString(transaction.payload)

        if settings_payload.action == SettingsPayload.PROPOSE:
            return self._apply_proposal(
                auth_keys, public_key, settings_payload.data, context)
        if settings_payload.action == SettingsPayload.VOTE:
            return self._apply_vote(public_key, settings_payload.data,
                                    auth_keys, context)

        raise InvalidTransaction(
            "'action' must be one of {PROPOSE, VOTE} in 'Ballot' mode")
    def create_vote_proposal(self, proposal_id, setting, vote):
        vote = SettingVote(proposal_id=proposal_id, vote=vote)
        payload = SettingsPayload(action=SettingsPayload.VOTE,
                                  data=vote.SerializeToString())

        return self._create_tp_process_request(setting, payload)
    def create_proposal_transaction(self, setting, value, nonce):
        proposal = SettingProposal(setting=setting, value=value, nonce=nonce)
        payload = SettingsPayload(action=SettingsPayload.PROPOSE,
                                  data=proposal.SerializeToString())

        return self._create_tp_process_request(setting, payload)