def test_is_numeric(): assert misc.is_numeric('45') is True assert misc.is_numeric('45.7') is True assert misc.is_numeric(0) is True assert misc.is_numeric(-1) is True assert misc.is_numeric('45,7') is False assert misc.is_numeric('fuzzy_bunny_slippers') is False assert misc.is_numeric('') is False assert misc.is_numeric(None) is False assert misc.is_numeric(False) is False assert misc.is_numeric(True) is False
def is_valid(self, dashd): 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 # 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
def is_valid(self): import combodelib 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-_]+") icbet 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 combode addr, non-multisig icbet combodelib.is_valid_combode_address(self.payment_address, config.network): printdbg("\tPayment address [%s] not a valid Combode address for network [%s], returning False" % (self.payment_address, config.network)) return False
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
def is_valid(self): import exiliumlib 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 omegacoin addr, non-multisig if not exiliumlib.is_valid_exilium_address(self.payment_address, config.network): printdbg("\tPayment address [%s] not a valid exilium 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
def is_valid(self): import allgamescoinlib 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 allgamescoinlib.is_valid_allgamescoin_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
class Superblock(BaseModel, GovernanceClass): governance_object = ForeignKeyField(GovernanceObject, related_name='superblocks', on_delete='CASCADE', on_update='CASCADE') event_block_height = IntegerField() payment_addresses = TextField() payment_amounts = TextField() proposal_hashes = TextField(default='') sb_hash = CharField() object_hash = CharField(max_length=64) govobj_type = CBED_GOVOBJ_TYPES['superblock'] only_masternode_can_submit = True class Meta: db_table = 'superblocks' def is_valid(self): import combodelib 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: icbet combodelib.is_valid_combode_address(addr, config.network): printdbg("\tInvalid address [%s], returning False" % addr) return False amounts = self.payment_amounts.split('|') for amt in amounts: icbet 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) icbet damt > 0: printdbg("\tAmount [%s] is zero or negative, returning False" % damt) return False
def is_valid(self): import historialib 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 historia addr, non-multisig if not historialib.is_valid_historia_address(self.payment_address, config.network): printdbg("\tPayment address [%s] not a valid Historia address for network [%s], returning False" % (self.payment_address, config.network)) return False # URL if (len(self.ipfscid.strip()) < 4): printdbg("\tProposal IPFS CID [%s] too short, returning False" % self.ipfscid) return False # proposal URL has any whitespace if (re.search(r'\s', self.ipfscid)): printdbg("\tProposal IPFS [%s] has whitespace, returning False" % self.name) return False # Historia Core restricts proposals to 512 bytes max if len(self.serialise()) > (self.MAX_DATA_SIZE * 2): printdbg("\tProposal [%s] is too big, returning False" % self.name) 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