class ClientPoolUpgradeOperation(MessageValidator): schema = ( (TXN_TYPE, ConstantField(POOL_UPGRADE)), (ACTION, ChooseField(values=( START, CANCEL, ))), (VERSION, VersionField(components_number=( 2, 3, ), max_length=VERSION_FIELD_LIMIT)), # TODO replace actual checks (idr, datetime) (SCHEDULE, MapField(IdentifierField(), NonEmptyStringField(), optional=True)), (SHA256, Sha256HexField()), (TIMEOUT, NonNegativeNumberField(optional=True)), (JUSTIFICATION, LimitedLengthStringField(max_length=JUSTIFICATION_MAX_SIZE, optional=True, nullable=True)), (NAME, LimitedLengthStringField(max_length=NAME_FIELD_LIMIT)), (FORCE, BooleanField(optional=True)), (REINSTALL, BooleanField(optional=True)), )
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.SIGS.nm, MapField(IdentifierField(), SignatureField(max_length=SIGNATURE_FIELD_LIMIT), optional=True, nullable=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) if not (dct.get(f.IDENTIFIER.nm) or dct.get(f.SIGS.nm)): self._raise_invalid_message( 'Missing both signatures and identifier')
def _transform_field(self, field, old_field_type, new_field_type): if isinstance(field, old_field_type): return new_field_type() elif self.__is_iterable_and_contains_type(field, old_field_type): return IterableField(new_field_type()) elif isinstance(field, MapField): key = field.key_field val = field.value_field if isinstance(field.key_field, old_field_type): key = new_field_type() if isinstance(field.value_field, old_field_type): val = new_field_type() return MapField(key, val) return field
class Commit(MessageBase): typename = COMMIT schema = ( (f.INST_ID.nm, NonNegativeNumberField()), (f.VIEW_NO.nm, NonNegativeNumberField()), (f.PP_SEQ_NO.nm, NonNegativeNumberField()), (f.BLS_SIG.nm, LimitedLengthStringField(max_length=BLS_SIG_LIMIT, optional=True)), (f.BLS_SIGS.nm, MapField(optional=True, key_field=StringifiedNonNegativeNumberField(), value_field=LimitedLengthStringField(max_length=BLS_SIG_LIMIT))), # PLUGIN_FIELDS is not used in Commit as of now but adding for # consistency (f.PLUGIN_FIELDS.nm, AnyMapField(optional=True, nullable=True)), )
class Message4(MessageBase): typename = 'Message4' schema = ( ('a', NonNegativeNumberField()), ('b', MapField(HexField(), HexField())), )
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')