Esempio n. 1
0
    def validate(self, data):
        """
        Validate signature
        Validate Tx recipients are unique
        Validate account_number (the sender) is not included as a Tx recipient
        """

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

        verify_signature(message=sort_and_encode(message),
                         signature=signature,
                         verify_key=account_number)

        recipient_list = [tx['recipient'] for tx in txs]
        recipient_set = set(recipient_list)

        if len(recipient_list) != len(recipient_set):
            raise serializers.ValidationError('Tx recipients must be unique')

        if account_number in recipient_set:
            raise serializers.ValidationError(
                'Block account_number not allowed as Tx recipient')

        validate_keys(self, data)

        return data
Esempio n. 2
0
    def validate(self, data):
        """Validate Txs exist"""
        if not data['txs']:
            raise serializers.ValidationError('Invalid Txs')

        validate_keys(self, data)

        return data
    def validate(self, data):
        """
        Check that there are no additional keys included in the data
        """

        validate_keys(self, data)

        return data
Esempio n. 4
0
    def validate(self, data):
        """Validate signature, unique Tx recipients, unique Tx fees and account_number not included as a Tx recipient"""
        account_number = data['account_number']
        message = data['message']
        txs = message['txs']
        signature = data['signature']

        verify_signature(message=sort_and_encode(message),
                         signature=signature,
                         verify_key=account_number)

        recipient_list = [tx['recipient'] for tx in txs]
        recipient_set = set(recipient_list)

        if len(recipient_list) != len(recipient_set):
            raise serializers.ValidationError('Tx recipients must be unique')

        if account_number in recipient_set:
            raise serializers.ValidationError(
                'Block account_number not allowed as Tx recipient')

        bank_fee_exists = False
        primary_validator_fee_exists = False

        for tx in txs:
            fee = tx.get('fee', None)

            if fee is None:
                continue

            if fee == BANK:

                if bank_fee_exists:
                    raise serializers.ValidationError(
                        'Multiple bank fees not allowed')
                else:
                    bank_fee_exists = True

            if fee == PRIMARY_VALIDATOR:

                if primary_validator_fee_exists:
                    raise serializers.ValidationError(
                        'Multiple primary validator fees not allowed')
                else:
                    primary_validator_fee_exists = True

        validate_keys(self, data)

        return data