Esempio n. 1
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 = []
         invalid_because = ['']
         while start != start_copy:
             if start == []:
                 return False  # Block passes this test
             start_copy = copy.deepcopy(start)
             if transactions.tx_check[start[0]['type']](start[0], out, invalid_because, DB):
                 out.append(start.pop())
             else:
                 tools.log('invalid tx: '+str(invalid_because[0]))
                 return True  # Block is invalid
         tools.log('block invalid because it has no txs')
         return True  # Block is invalid
     if 'error' in block: 
         log_('error in block')
         return False
     length =tools.local_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
     block_creator_address=tools.addr(block)
     mint_address=tools.addr(filter(lambda t: t['type']=='mint', block['txs'])[0])
     if block_creator_address!=mint_address:
         log_('bad mint')
         return False
     if block['root_hash']!=tools.db_root():
         log_('bad root, have: '+str(tools.db_root())+'  need ' +str(block['root_hash']))
         return False
     txs=filter(lambda x: x['type']=='mint', block['txs'])
     if len(txs)!=1:
         log_('wrong number of mint txs')
         return False
     txs=filter(lambda x: x['type']=='sign', block['txs'])
     txs=map(lambda x: len(x['jackpots']), txs)
     if sum(txs)<custom.signers*2/3 and length>-1:
         log_('not enough signatures')
         return False
     if length >= 0:
         prev_block=tools.db_get(length)
         to_hash={'prev_hash':prev_block['block_hash'], 'txs':block['txs']}
         if not block['block_hash']==tools.det_hash(to_hash):
             log_('det hash error')
             return False
     #total money spent must be less than the total amount of money in signed deposits for this block.
     if tx_check(block['txs']): 
         log_('tx check')
         return False
     return True
Esempio n. 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 = []
         invalid_because = ['']
         while start != start_copy:
             if start == []:
                 return False  # Block passes this test
             start_copy = copy.deepcopy(start)
             if transactions.tx_check[start[0]['type']](start[0], out, invalid_because, DB):
                 out.append(start.pop())
             else:
                 tools.log('invalid tx: '+str(invalid_because[0]))
                 return True  # Block is invalid
         tools.log('block invalid because it has no txs')
         return True  # Block is invalid
     if 'error' in block: 
         log_('error in block')
         return False
     length =tools.local_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
     block_creator_address=tools.addr(block)
     mint_address=tools.addr(filter(lambda t: t['type']=='mint', block['txs'])[0])
     if block_creator_address!=mint_address:
         log_('bad mint')
         return False
     if block['root_hash']!=tools.db_root():
         log_('bad root, have: '+str(tools.db_root())+'  need ' +str(block['root_hash']))
         return False
     txs=filter(lambda x: x['type']=='mint', block['txs'])
     if len(txs)!=1:
         log_('wrong number of mint txs')
         return False
     txs=filter(lambda x: x['type']=='sign', block['txs'])
     txs=map(lambda x: len(x['jackpots']), txs)
     if sum(txs)<custom.signers*2/3 and length>-1:
         log_('not enough signatures')
         return False
     if length >= 0:
         prev_block=tools.db_get(length)
         to_hash={'prev_hash':prev_block['block_hash'], 'txs':block['txs']}
         if not block['block_hash']==tools.det_hash(to_hash):
             log_('det hash error')
             return False
     #total money spent must be less than the total amount of money in signed deposits for this block.
     if tx_check(block['txs']): 
         log_('tx check')
         return False
     return True
Esempio n. 3
0
def buy_block(DB, args):
    gap=1#this should be an argument. 
    #we should also let the user delete as many blocks first as they want, to build a fork from a point in history.
    length=tools.local_get('length')
    prev_block=tools.db_get(length)
    txs=tools.local_get('txs')
    privkey=tools.local_get('privkey')
    height=tools.local_get('height')
    block=default_block(length+1, height+gap, txs+[sign(mint_tx(gap), privkey)])
    to_hash=''
    if length>-1: to_hash={'prev_hash':prev_block['block_hash'], 'txs':block['txs']}
    block['block_hash']=tools.det_hash(to_hash)
    block['root_hash']=tools.db_root()
    block=sign(block, privkey)
    block = tools.unpackage(tools.package(block))
    DB['suggested_blocks'].put(block)
    return block
Esempio n. 4
0
def buy_block(DB, args):
    gap = 1  # this should be an argument.
    # we should also let the user delete as many blocks first as they want, to build a fork from a point in history.
    length = tools.local_get("length")
    prev_block = tools.db_get(length)
    txs = tools.local_get("txs")
    privkey = tools.local_get("privkey")
    height = tools.local_get("height")
    block = default_block(length + 1, height + gap, txs + [sign(mint_tx(gap), privkey)])
    to_hash = ""
    if length > -1:
        to_hash = {"prev_hash": prev_block["block_hash"], "txs": block["txs"]}
    block["block_hash"] = tools.det_hash(to_hash)
    block["root_hash"] = tools.db_root()
    block = sign(block, privkey)
    block = tools.unpackage(tools.package(block))
    DB["suggested_blocks"].put(block)
    return block
Esempio n. 5
0
def buy_block(DB, args):
    gap = 1  #this should be an argument.
    #we should also let the user delete as many blocks first as they want, to build a fork from a point in history.
    length = tools.local_get('length')
    prev_block = tools.db_get(length)
    txs = tools.local_get('txs')
    privkey = tools.local_get('privkey')
    height = tools.local_get('height')
    block = default_block(length + 1, height + gap,
                          txs + [sign(mint_tx(gap), privkey)])
    to_hash = ''
    if length > -1:
        to_hash = {'prev_hash': prev_block['block_hash'], 'txs': block['txs']}
    block['block_hash'] = tools.det_hash(to_hash)
    block['root_hash'] = tools.db_root()
    block = sign(block, privkey)
    block = tools.unpackage(tools.package(block))
    DB['suggested_blocks'].put(block)
    return block