コード例 #1
0
ファイル: models.py プロジェクト: quantumgravity444/sentinel
    def is_valid(self, dashd):
        import dashlib
        import decimal

        # it's a string from the DB...
        addresses = self.payment_addresses.split('|')
        for addr in addresses:
            if not dashlib.is_valid_dash_address(addr, config.network):
                return False

        amounts = self.payment_amounts.split('|')
        for amt in amounts:
            if not misc.is_numeric(amt):
                return False

            # no negative or zero amounts allowed
            damt = decimal.Decimal(amt)
            if not damt > 0:
                return False

        # ensure number of payment addresses matches number of payments
        if len(addresses) != len(amounts):
            return False

        # ensure EBH is on-cycle
        if (self.event_block_height != dashd.next_superblock_height()):
            return False

        return True
コード例 #2
0
    def is_valid(self, dashd):
        import dashlib

        printdbg("In Proposal#is_valid, for Proposal: %s" % self.__dict__)

        # proposal name exists and is not null/whitespace
        if (len(self.name.strip()) == 0):
            printdbg("\tInvalid Proposal name [%s], returning False" %
                     self.name)
            return False

        # proposal name is normalized (something like "[a-zA-Z0-9-_]+")
        if not re.match(r'^[-_a-zA-Z0-9]+$', self.name):
            printdbg(
                "\tInvalid Proposal name [%s] (does not match regex), returning False"
                % self.name)
            return False

        # end date < start date
        if (self.end_epoch <= self.start_epoch):
            printdbg(
                "\tProposal end_epoch [%s] <= start_epoch [%s] , returning False"
                % (self.end_epoch, self.start_epoch))
            return False

        # budget check
        max_budget = dashd.next_superblock_max_budget()
        if (max_budget and (self.payment_amount > max_budget)):
            printdbg(
                "\tProposal amount [%s] is bigger than max_budget [%s], returning False"
                % (self.payment_amount, max_budget))
            return False

        # amount can't be negative or 0
        if (self.payment_amount <= 0):
            printdbg(
                "\tProposal amount [%s] is negative or zero, returning False" %
                self.payment_amount)
            return False

        # payment address is valid base58 dash addr, non-multisig
        if not dashlib.is_valid_dash_address(self.payment_address,
                                             config.network):
            printdbg(
                "\tPayment address [%s] not a valid Dash address for network [%s], returning False"
                % (self.payment_address, config.network))
            return False

        # URL
        if (len(self.url.strip()) < 4):
            printdbg("\tProposal URL [%s] too short, returning False" %
                     self.url)
            return False

        printdbg("Leaving Proposal#is_valid, Valid = True")
        return True
コード例 #3
0
ファイル: models.py プロジェクト: ksamuel/sentinel
    def is_valid(self):
        import dashlib

        printdbg("In Proposal#is_valid, for Proposal: %s" % self.__dict__)

        try:
            # proposal name exists and is not null/whitespace
            if (len(self.name.strip()) == 0):
                printdbg("\tInvalid Proposal name [%s], returning False" % self.name)
                return False

            # proposal name is normalized (something like "[a-zA-Z0-9-_]+")
            if not re.match(r'^[-_a-zA-Z0-9]+$', self.name):
                printdbg("\tInvalid Proposal name [%s] (does not match regex), returning False" % self.name)
                return False

            # end date < start date
            if (self.end_epoch <= self.start_epoch):
                printdbg("\tProposal end_epoch [%s] <= start_epoch [%s] , returning False" % (self.end_epoch, self.start_epoch))
                return False

            # amount must be numeric
            if misc.is_numeric(self.payment_amount) is False:
                printdbg("\tProposal amount [%s] is not valid, returning False" % self.payment_amount)
                return False

            # amount can't be negative or 0
            if (float(self.payment_amount) <= 0):
                printdbg("\tProposal amount [%s] is negative or zero, returning False" % self.payment_amount)
                return False

            # payment address is valid base58 dash addr, non-multisig
            if not dashlib.is_valid_dash_address(self.payment_address, config.network):
                printdbg("\tPayment address [%s] not a valid Dash address for network [%s], returning False" % (self.payment_address, config.network))
                return False

            # URL
            if (len(self.url.strip()) < 4):
                printdbg("\tProposal URL [%s] too short, returning False" % self.url)
                return False

            try:
                parsed = urlparse.urlparse(self.url)
            except Exception as e:
                printdbg("\tUnable to parse Proposal URL, marking invalid: %s" % e)
                return False

        except Exception as e:
            printdbg("Unable to validate in Proposal#is_valid, marking invalid: %s" % e.message)
            return False

        printdbg("Leaving Proposal#is_valid, Valid = True")
        return True
コード例 #4
0
def test_invalid_dash_address():
    from dashlib import is_valid_dash_address

    main = invalid_dash_address()
    test = invalid_dash_address('testnet')

    assert is_valid_dash_address(main) == False
    assert is_valid_dash_address(main, 'mainnet') == False
    assert is_valid_dash_address(main, 'testnet') == False

    assert is_valid_dash_address(test) == False
    assert is_valid_dash_address(test, 'mainnet') == False
    assert is_valid_dash_address(test, 'testnet') == False
コード例 #5
0
ファイル: models.py プロジェクト: fireice-uk/sentinel
    def is_valid(self):
        import dashlib
        import decimal

        printdbg("In Superblock#is_valid, for SB: %s" % self.__dict__)

        # it's a string from the DB...
        addresses = self.payment_addresses.split('|')
        for addr in addresses:
            if not dashlib.is_valid_dash_address(addr, config.network):
                printdbg("\tInvalid address [%s], returning False" % addr)
                return False

        amounts = self.payment_amounts.split('|')
        for amt in amounts:
            if not misc.is_numeric(amt):
                printdbg("\tAmount [%s] is not numeric, returning False" % amt)
                return False

            # no negative or zero amounts allowed
            damt = decimal.Decimal(amt)
            if not damt > 0:
                printdbg("\tAmount [%s] is zero or negative, returning False" %
                         damt)
                return False

        # verify proposal hashes correctly formatted...
        if len(self.proposal_hashes) > 0:
            hashes = self.proposal_hashes.split('|')
            for object_hash in hashes:
                if not misc.is_hash(object_hash):
                    printdbg("\tInvalid proposal hash [%s], returning False" %
                             object_hash)
                    return False

        # ensure number of payment addresses matches number of payments
        if len(addresses) != len(amounts):
            printdbg(
                "\tNumber of payment addresses [%s] != number of payment amounts [%s], returning False"
                % (len(addresses), len(amounts)))
            return False

        printdbg("Leaving Superblock#is_valid, Valid = True")
        return True
コード例 #6
0
ファイル: test_dashy_things.py プロジェクト: LusoDev/sentinel
def test_valid_dash_address():
    from dashlib import is_valid_dash_address

    main = valid_dash_address()
    test = valid_dash_address('testnet')

    assert is_valid_dash_address(main) is True
    assert is_valid_dash_address(main, 'mainnet') is True
    assert is_valid_dash_address(main, 'testnet') is False

    assert is_valid_dash_address(test) is False
    assert is_valid_dash_address(test, 'mainnet') is False
    assert is_valid_dash_address(test, 'testnet') is True
コード例 #7
0
ファイル: models.py プロジェクト: quantumgravity444/sentinel
    def is_valid(self, dashd):
        import dashlib
        now = misc.now()

        # proposal name exists and is not null/whitespace
        if (len(self.name.strip()) == 0):
            return False

        # proposal name is normalized (something like "[a-zA-Z0-9-_]+")
        if not re.match(r'^[-_a-zA-Z0-9]+$', self.name):
            return False

        # end date < start date
        if (self.end_epoch <= self.start_epoch):
            return False

        # end date < current date
        if (self.end_epoch <= now):
            return False

        # budget check
        max_budget = dashd.next_superblock_max_budget()
        if (max_budget and (self.payment_amount > max_budget)):
            return False

        # amount can't be negative or 0
        if (self.payment_amount <= 0):
            return False

        # payment address is valid base58 dash addr, non-multisig
        if not dashlib.is_valid_dash_address(self.payment_address,
                                             config.network):
            return False

        # URL
        if (len(self.url.strip()) < 4):
            return False

        return True