Пример #1
0
class OldViewPrePrepareRequest(MessageBase):
    typename = OLD_VIEW_PREPREPARE_REQ
    schema = (
        (f.INST_ID.nm, NonNegativeNumberField()),
        (f.BATCH_IDS.nm, IterableField(BatchIDField())),
    )
Пример #2
0
 def __init__(self, **kwargs):
     super().__init__(NonEmptyStringField(), NonNegativeNumberField(),
                      **kwargs)
Пример #3
0
class ClientMessageValidator(MessageValidator):
    schema = (
        (f.IDENTIFIER.nm, IdentifierField(optional=True, nullable=True)),
        (f.REQ_ID.nm, NonNegativeNumberField()),
        (OPERATION, ClientOperationField()),
        (f.SIG.nm,
         SignatureField(max_length=SIGNATURE_FIELD_LIMIT, optional=True)),
        (f.DIGEST.nm,
         LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT,
                                  optional=True)),
        (f.PROTOCOL_VERSION.nm, ProtocolVersionField()),
        (f.TAA_ACCEPTANCE.nm, ClientTAAAcceptance(optional=True)),
        (f.SIGS.nm,
         MapField(IdentifierField(),
                  SignatureField(max_length=SIGNATURE_FIELD_LIMIT),
                  optional=True,
                  nullable=True)),
        (f.ENDORSER.nm, IdentifierField(optional=True)),
    )

    def __init__(self, operation_schema_is_strict, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Following code is for support of non-strict schema
        # TODO: refactor this
        # TODO: this (and all related functionality) can be removed when
        # when fixed problem with transaction serialization (INDY-338)
        # Adding fields from enabled plugins to schema.
        self.schema = self.schema + tuple(PLUGIN_CLIENT_REQUEST_FIELDS.items())
        if operation_schema_is_strict:
            operation_field_index = 2
            op = ClientOperationField(
                schema_is_strict=operation_schema_is_strict)
            schema = list(self.schema)
            schema[operation_field_index] = (OPERATION, op)
            self.schema = tuple(schema)

    def validate(self, dct):
        super().validate(dct)
        identifier = dct.get(f.IDENTIFIER.nm, None)
        signatures = dct.get(f.SIGS.nm, None)
        signature = dct.get(f.SIG.nm, None)
        endorser = dct.get(f.ENDORSER.nm, None)
        if signatures and signature:
            self._raise_invalid_message(
                'Request can not contain both fields "signatures" and "signature"'
            )
        if endorser is not None:
            if not signatures or endorser not in signatures:
                self._raise_invalid_message("Endorser must sign the request")
            if identifier is None:
                self._raise_invalid_message(
                    "Author's Identifier must be present when sending via Endorser"
                )
            if not signatures or identifier not in signatures:
                self._raise_invalid_message(
                    "Author must sign the request when sending via Endorser")
        if identifier and signatures and identifier not in signatures:
            self._raise_invalid_message(
                'The identifier is not contained in signatures')
        if not (identifier or signatures):
            self._raise_invalid_message(
                'Missing both signatures and identifier')
 class ANewMessageClass(MessageBase):
     typename = 'NewMessage'
     schema = (('a', NonNegativeNumberField()), )
Пример #5
0
class ClientGetTxnAuthorAgreementAMLOperation(MessageValidator):
    schema = ((TXN_TYPE, ConstantField(GET_TXN_AUTHOR_AGREEMENT_AML)),
              (GET_TXN_AUTHOR_AGREEMENT_AML_VERSION,
               NonEmptyStringField(optional=True)),
              (GET_TXN_AUTHOR_AGREEMENT_AML_TIMESTAMP,
               NonNegativeNumberField(optional=True)))