Exemple #1
0
def _create_propose_txn(public_key, signing_key, setting_key_value):
    """Creates an individual sawtooth_settings transaction for the given key and
    value.
    """
    setting_key, setting_value = setting_key_value
    nonce = str(datetime.datetime.utcnow().timestamp())
    proposal = SettingProposal(setting=setting_key,
                               value=setting_value,
                               nonce=nonce)
    payload = SettingsPayload(data=proposal.SerializeToString(),
                              action=SettingsPayload.PROPOSE)

    return _make_txn(public_key, signing_key, setting_key, payload)
Exemple #2
0
def _create_propose_txn(signer, setting_key_value):
    """Creates an individual sawtooth_settings transaction for the given
    key and value.
    """
    setting_key, setting_value = setting_key_value
    nonce = hex(random.randint(0, 2**64))
    proposal = SettingProposal(setting=setting_key,
                               value=setting_value,
                               nonce=nonce)
    payload = SettingsPayload(data=proposal.SerializeToString(),
                              action=SettingsPayload.PROPOSE)

    return _make_txn(signer, setting_key, payload)
Exemple #3
0
def _check_required_settings(batches):
    """Ensure that all settings required at genesis are set."""
    required_settings = REQUIRED_SETTINGS.copy()
    for batch in batches:
        for txn in batch.transactions:
            txn_header = TransactionHeader()
            txn_header.ParseFromString(txn.header)
            if txn_header.family_name == 'sawtooth_settings':
                settings_payload = SettingsPayload()
                settings_payload.ParseFromString(txn.payload)
                if settings_payload.action == SettingsPayload.PROPOSE:
                    proposal = SettingProposal()
                    proposal.ParseFromString(settings_payload.data)
                    if proposal.setting in required_settings:
                        required_settings.remove(proposal.setting)

    if required_settings:
        raise CliException(
            'The following setting(s) are required at genesis, but were not '
            'included in the genesis batches: {}'.format(required_settings))
Exemple #4
0
    def setUp(self):
        self._temp_dir = tempfile.mkdtemp()
        self._temp_data_dir = tempfile.mkdtemp()

        parent_parser = argparse.ArgumentParser(prog='test_genesis',
                                                add_help=False)

        self._parser = argparse.ArgumentParser(add_help=False)
        subparsers = self._parser.add_subparsers(title='subcommands',
                                                 dest='command')

        genesis.add_genesis_parser(subparsers, parent_parser)

        required_settings = ['sawtooth.consensus.algorithm.name',
                             'sawtooth.consensus.algorithm.version']

        setting_proposals = []
        for setting in required_settings:
            proposal = SettingProposal()
            proposal.setting = setting
            setting_proposals.append(proposal)

        setting_payloads = []
        for proposal in setting_proposals:
            payload = SettingsPayload()
            payload.action = SettingsPayload.PROPOSE
            payload.data = proposal.SerializeToString()
            setting_payloads.append(payload)

        setting_transactions = [
            transaction(
                'setting{}'.format(idx),
                [],
                family_name='sawtooth_settings',
                payload=payload.SerializeToString())
            for idx, payload in enumerate(setting_payloads)]

        self._required_settings_batch = self.make_batch(
            'required_settings', *setting_transactions)