Esempio n. 1
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))
Esempio n. 2
0
def _validate_depedencies(batches):
    """Validates the transaction dependencies for the transactions contained
    within the sequence of batches. Given that all the batches are expected to
    to be executed for the genesis blocks, it is assumed that any dependent
    transaction will proceed the depending transaction.
    """
    transaction_ids = set()
    for batch in batches:
        for txn in batch.transactions:
            txn_header = TransactionHeader()
            txn_header.ParseFromString(txn.header)

            if len(txn_header.dependencies) > 0:
                unsatisfied_deps = [id for id in txn_header.dependencies
                                    if id not in transaction_ids]
                if len(unsatisfied_deps) != 0:
                    raise CliException(
                        'Unsatisfied dependency in given transactions:'
                        ' {}'.format(unsatisfied_deps))

            transaction_ids.add(txn.header_signature)