Example #1
0
 def _savetargetHandler(self, *args):
     ''' need to validate the target name - off to skyx and be sure it
     exists, check the values are sane in the other fields then add to
     the list.
     '''
     if self.tname.get() and self.texposure.get() and self.tnumexp.get():
         # If it already exists delete it
         # Really should work out how to edit it in place to not screw
         # up the order
         index = 'end'
         for item in self.ttree.get_children():
             if self.ttree.item(item)['values'][0] == self.tname.get():
                 index = self.ttree.index(item)
                 self.ttree.delete(item)
         try:
             t = [x for x in self.neoobj.neocplist if x.tmpdesig == self.tname.get()][0]
             t.exposure = self.texposure.get()
             t.nexposures = self.tnumexp.get()
             self.ttree.insert('', index, values=t.imglist())
         except IndexError:
             # It wasn't on the list
             mp = target.target(self.tname.get(), ttype="fixed", nexposures=self.tnumexp.get(), exposure=self.texposure.get())
             self.neoobj.neocplist.append(mp)
             self.ttree.insert('', index, values=mp.imglist())
             
     else:
         tkMessageBox.showinfo(message="Invalid Data Supplied")
     self._clear()
Example #2
0
 def block_check(block, DB):
     def log_(txt): pass #return tools.log(txt)
     def tx_check(txs):
         start = copy.deepcopy(txs)
         out = []
         start_copy = []
         while start != start_copy:
             if start == []:
                 return False  # Block passes this test
             start_copy = copy.deepcopy(start)
             if transactions.tx_check[start[-1]['type']](start[-1], out, [''], DB):
                 out.append(start.pop())
             else:
                 return True  # Block is invalid
         return True  # Block is invalid
     if not isinstance(block, dict): return False
     if 'error' in block: return False
     if not tools.E_check(block, 'length', [int]):
         log_('no length')
         return False
     length = DB['length']
     if int(block['length']) != int(length) + 1:
         log_('wrong longth')
         return False
     if block['diffLength'] != hexSum(DB['diffLength'],
                                      hexInvert(block['target'])):
         log_('diflength error')
         return False
     if length >= 0:
         if tools.det_hash(tools.db_get(length, DB)) != block['prevHash']:
             log_('det hash error')
             return False
     a = copy.deepcopy(block)
     a.pop('nonce')
     if u'target' not in block.keys():
         log_('target error')
         return False
     half_way = {u'nonce': block['nonce'], u'halfHash': tools.det_hash(a)}
     if tools.det_hash(half_way) > block['target']:
         log_('det hash error 2')
         return False
     if block['target'] != target.target(DB, block['length']):
         log_('wrong target')
         return False
     earliest = median(recent_blockthings('times', DB, custom.mmm))
     if 'time' not in block: 
         log_('no time')
         return False
     if block['time'] > time.time()+60*6: 
         log_('too late')
         return False
     if block['time'] < earliest: 
         log_('too early')
         return False
     if tx_check(block['txs']): 
         log_('tx check')
         return False
     return True
Example #3
0
def genesis(pubkey, DB):
    target_ = target.target()
    out = {'version': custom.version,
           'length': 0,
           'time': time.time(),
           'target': target_,
           'diffLength': blockchain.hexInvert(target_),
           'txs': [make_mint(pubkey, DB)]}
    out = tools.unpackage(tools.package(out))
    return out
Example #4
0
def make_block(prev_block, txs, pubkey, DB):
    leng = int(prev_block['length']) + 1
    target_ = target.target(leng)
    diffLength = blockchain.hexSum(prev_block['diffLength'],
                                   blockchain.hexInvert(target_))
    out = {'version': custom.version,
           'txs': txs + [make_mint(pubkey, DB)],
           'length': leng,
           'time': time.time(),
           'diffLength': diffLength,
           'target': target_,
           'prevHash': tools.det_hash(prev_block)}
    out = tools.unpackage(tools.package(out))
    return out
Example #5
0
 def get_neocp(self):
     ''' Get the NEOCP data
     '''
     data = urllib2.urlopen(self.neocp)
     regex = re.compile("^(.{7}) (.{3}) (.{12}) (.{8}) (.{8}) (.{4})" +
                        " (.{22}) (.{7}) (.{3})  (.{5}) (.{4})")
     my_neos = []
     for line in data:
         res = regex.match(line)
         my_neo = target.target(res.group(1).strip())
         my_neo.addneoprops(res.group(2), res.group(3),
                            res.group(4), res.group(5), res.group(6),
                            res.group(7), res.group(8), res.group(9),
                            res.group(10), res.group(11))
         my_neos.append(my_neo)
     return my_neos
Example #6
0
 def get_crits(self):
     ''' Get the Critial List data.
     '''
     data = urllib2.urlopen(self.crits)
     regex = re.compile("^(.{21})\|(.{14})\|(.{10})\|(.{8})\|(.{8})\|(.{9})\|(.{9})\|(.{5})\|(.{10})\|(.{5})\|(.{5})")
     crits = []
     for line in data:
         res = regex.match(line)
         logger.debug(line)
         logger.debug(res.group(2))
         crit = target.target(res.group(1).strip(), ttype="mp")
         logger.debug(res.group(2) + " " + res.group(3) + " " +
                      res.group(4) + " " + res.group(5) + " " +
                      res.group(6) + " " + res.group(7) + " " +
                      res.group(9) + " " + res.group(10) + " " +
                      res.group(11))
         crit.addcritprops(res.group(2), res.group(3), res.group(4),
                           res.group(5), res.group(6), res.group(7),
                           res.group(9), res.group(10), res.group(11))
         crits.append(crit)
     return crits
Example #7
0
def difficulty(DB, args): return(target.target(DB))
def my_balance(DB, args, address='default'): 
Example #8
0
    def block_check(block, DB):
        def log_(txt): pass #return tools.log(txt)
        def tx_check(txs):
            start = copy.deepcopy(txs)
            out = []
            start_copy = []
            error_msg=['']
            while True:
                if start == []: return False  # Block passes this test
                if transactions.tx_check[start[-1]['type']](start[-1], out, error_msg, DB):
                    out.append(start.pop())
                else:
                    log_('bad block: ' +str(txs))
                    log_('error message: ' +str(error_msg))
                    return True  # Block is invalid
        if not isinstance(block, dict): return False
        if 'error' in block: return False
        if not tools.E_check(block, 'length', [int]):
            log_('no length')
            return False
        length =tools.db_get('length')
        if type(block['length'])!=type(1): 
            log_('wrong length type')
            return False
        if int(block['length']) != int(length) + 1:
            log_('wrong longth')
            return False
        if block['diffLength'] != hexSum(tools.db_get('diffLength'),
                                         hexInvert(block['target'])):
            log_('diflength error')
            return False
        if length >= 0:
            if tools.det_hash(tools.db_get(length, DB)) != block['prevHash']:
                log_('det hash error')
                return False
        if u'target' not in block.keys():
            log_('target error')
            return False
        half_way=tools.make_half_way(block)
        if tools.det_hash(half_way) > block['target']:
            log_('det hash error 2')

            return False
        if block['target'] != target.target(block['length']):
            log_('block: ' +str(block))
            log_('target: ' +str(target.target(block['length'])))
            log_('wrong target')
            return False
        earliest = median(recent_blockthings('times', custom.mmm))
        if 'time' not in block: 
            log_('no time')
            return False
        if block['time'] > time.time()+60*6: 
            log_('too late')
            return False
        if block['time'] < earliest: 
            log_('too early')
            return False
        if tx_check(block['txs']): 
            log_('tx check')
            return False
        return True