예제 #1
0
    def is_valid(self):
        import monoecilib
        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 monoecilib.is_valid_monoeci_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
예제 #2
0
def test_invalid_monoeci_address():
    from monoecilib import is_valid_monoeci_address

    main = invalid_monoeci_address()
    test = invalid_monoeci_address('testnet')

    assert is_valid_monoeci_address(main) is False
    assert is_valid_monoeci_address(main, 'mainnet') is False
    assert is_valid_monoeci_address(main, 'testnet') is False

    assert is_valid_monoeci_address(test) is False
    assert is_valid_monoeci_address(test, 'mainnet') is False
    assert is_valid_monoeci_address(test, 'testnet') is False
예제 #3
0
    def is_valid(self):
        import monoecilib

        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 monoeci addr, non-multisig
            if not monoecilib.is_valid_monoeci_address(self.payment_address,
                                                       config.network):
                printdbg(
                    "\tPayment address [%s] not a valid Monoeci 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