Example #1
0
    def validate(self, data):
        """
        Verify that correct payment exist for both Bank and Validator
        """

        data = super(BlockSerializerCreate, self).validate(data)

        account_number = data['account_number']
        message = data['message']
        txs = message['txs']

        self_configuration = get_self_configuration(exception_class=RuntimeError)
        primary_validator = get_primary_validator()

        if account_number != self_configuration.account_number:
            validate_transaction_exists(
                amount=self_configuration.default_transaction_fee,
                error=serializers.ValidationError,
                recipient=self_configuration.account_number,
                txs=txs
            )

        if account_number != primary_validator.account_number:
            validate_transaction_exists(
                amount=primary_validator.default_transaction_fee,
                error=serializers.ValidationError,
                recipient=primary_validator.account_number,
                txs=txs
            )

        return data
Example #2
0
    def validate_message(message):
        """
        Check that Txs exist
        Verify that correct payment exist for both Bank and Validator
        """

        self_configuration = get_self_configuration(exception_class=RuntimeError)
        primary_validator = get_primary_validator()

        bank_default_transaction_fee = self_configuration.default_transaction_fee
        validator_transaction_fee = primary_validator.default_transaction_fee

        txs = message['txs']

        if not txs:
            raise serializers.ValidationError('Invalid Txs')

        validate_transaction_exists(
            amount=bank_default_transaction_fee,
            error=serializers.ValidationError,
            recipient=self_configuration.account_number,
            txs=txs
        )
        validate_transaction_exists(
            amount=validator_transaction_fee,
            error=serializers.ValidationError,
            recipient=primary_validator.account_number,
            txs=txs
        )

        return txs
Example #3
0
    def validate_primary_validator_node_identifier(primary_validator_node_identifier):
        """Validate that primary_validator_node_identifier belongs to primary validator"""
        primary_validator = get_primary_validator()

        if primary_validator_node_identifier != primary_validator.node_identifier:
            raise serializers.ValidationError(
                'The primary_validator_node_identifier does not belong to the primary validator'
            )

        return primary_validator
Example #4
0
def invalid_block_data(block_data, signing_key, invalid_block_fake_data):
    yield generate_signed_request(data={
        'block':
        block_data,
        'block_identifier':
        invalid_block_fake_data['block_identifier'],
        'primary_validator_node_identifier':
        get_primary_validator().node_identifier,
    },
                                  nid_signing_key=signing_key)
Example #5
0
    def inner(request, *args, **kwargs):
        message = request.data.get('message')
        node_identifier = request.data.get('node_identifier')
        signature = request.data.get('signature')

        primary_validator = get_primary_validator()

        if node_identifier != primary_validator.node_identifier:
            return Response(status=status.HTTP_401_UNAUTHORIZED)

        try:
            verify_signature(message=sort_and_encode(message),
                             signature=signature,
                             verify_key=node_identifier)
        except BadSignatureError as e:
            logger.exception(e)
            return Response({ERROR: BAD_SIGNATURE},
                            status=status.HTTP_401_UNAUTHORIZED)
        except Exception as e:
            logger.exception(e)
            return Response({ERROR: UNKNOWN},
                            status=status.HTTP_401_UNAUTHORIZED)

        return func(request, *args, **kwargs)