Ejemplo n.º 1
0
def sign_verify(tx, txs, out,
                DB):  #check the validity of a transaction of type sign.
    a = tools.addr(tx)
    B = tx[
        'B']  #verify a proof that addr(tx) actually owned that much money long*2-medium ago.
    M = custom.all_money
    address = tools.addr(tx)
    block = tools.db_get(tx['on_block'])
    num = max(0, tx['on_block'] - (custom.long_time * 2 - custom.medium_time))
    election_block = tools.db_get(num)
    if not signature_check(tx):
        out[0] += 'signature check'
        return False
    if 'root_hash' not in election_block:
        out[0] += 'no root hash'
        return False
    v = tools.db_verify(election_block['root_hash'], address, tx['proof'])
    if v == False:
        tools.log('your address did not exist that long ago.')
        return False
    if v['amount'] != tx['B']:
        tools.log('that is not how much money you had that long ago')
        return False
    if 'secret_hash' not in tx:
        tools.log('need the hash of a secret')
        return False
    for t in txs:
        if tools.addr(t) == address and t['type'] == 'sign':
            #tools.log('can only have one sign tx per block')
            return False
    if len(tx['jackpots']) < 1:
        tools.log('insufficient jackpots')
        return False
    if not signature_check(tx):
        out[0] += 'signature check'
        return False
    length = tools.local_get('length')
    if int(tx['on_block']) != int(length + 1):
        out[0] += 'this tx is for the wrong block. have ' + str(
            length + 1) + ' need: ' + str(tx['on_block'])
        return False
    if tx['on_block'] > 0:
        if not tx['prev'] == tools.db_get(length)['block_hash']:
            tools.log('must give hash of previous block')
            return False
    ran = tools.det_random(tx['on_block'])
    for j in tx['jackpots']:
        if type(j) != int or j not in range(200):
            tools.log('bad jackpot')
            return False
        if len(filter(lambda x: x == j, tx['jackpots'])) != 1:
            tools.log('no repeated jackpots')
            return False
        if not tools.winner(B, M, ran, address, j):
            tools.log('that jackpot is not valid: ' + str(j))
            return False
    if tx['amount'] < custom.minimum_deposit:
        tools.log('you have to deposit more than that')
        return False
    return True
Ejemplo n.º 2
0
def sign_verify(tx, txs, out, DB):#check the validity of a transaction of type sign.
    a=tools.addr(tx)
    B=tx['B']#verify a proof that addr(tx) actually owned that much money long*2-medium ago.
    M=custom.all_money
    address=tools.addr(tx)
    block=tools.db_get(tx['on_block'])
    num=max(0,tx['on_block']-(custom.long_time*2-custom.medium_time))
    election_block=tools.db_get(num)
    if not signature_check(tx):
        out[0]+='signature check'
        return False
    if 'root_hash' not in election_block:
        out[0]+='no root hash'
        return False
    v=tools.db_verify(election_block['root_hash'], address, tx['proof'])
    if v==False:
        tools.log('your address did not exist that long ago.')
        return False
    if v['amount']!=tx['B']:
        tools.log('that is not how much money you had that long ago')
        return False
    if 'secret_hash' not in tx:
        tools.log('need the hash of a secret')
        return False
    for t in txs:
        if tools.addr(t)==address and t['type']=='sign':
            #tools.log('can only have one sign tx per block')
            return False
    if len(tx['jackpots'])<1: 
        tools.log('insufficient jackpots')
        return False
    if not signature_check(tx):
        out[0]+='signature check'
        return False
    length=tools.local_get('length')
    if int(tx['on_block'])!=int(length+1):
        out[0]+='this tx is for the wrong block. have '+str(length+1) +' need: ' +str(tx['on_block'])
        return False
    if tx['on_block']>0:
        if not tx['prev']==tools.db_get(length)['block_hash']:
            tools.log('must give hash of previous block')
            return False
    ran=tools.det_random(tx['on_block'])
    for j in tx['jackpots']:
        if type(j)!=int or j not in range(200):
               tools.log('bad jackpot')
               return False
        if len(filter(lambda x: x==j, tx['jackpots']))!=1:
               tools.log('no repeated jackpots')
               return False
        if not tools.winner(B, M, ran, address, j):
            tools.log('that jackpot is not valid: '+str(j))
            return False
    if tx['amount']<custom.minimum_deposit:
        tools.log('you have to deposit more than that')
        return False
    return True
Ejemplo n.º 3
0
def sign_verify(tx, txs, out, DB):  # check the validity of a transaction of type sign.
    a = tools.addr(tx)
    acc = tools.db_get(a)
    if a["amount"] < tx["B"]:
        tools.log("you do not have that much money")
    B = tx["B"]
    M = custom.all_money
    address = tools.addr(tx)
    block = tools.db_get(tx["on_block"])
    num = max(0, tx["on_block"] - (custom.long_time * 2 - custom.medium_time))
    election_block = tools.db_get(num)
    if "root_hash" not in election_block:
        out[0] += "no root hash"
        return False
    v = tools.db_verify(election_block["root_hash"], address, tx["proof"])
    if v == False:
        tools.log("your address did not exist that long ago.")
        return False
    if v["amount"] != tx["B"]:
        tools.log("that is not how much money you had that long ago")
        return False
    if "secret_hash" not in tx:
        tools.log("need the hash of a secret")
        return False
    for t in txs:
        if tools.addr(t) == address and t["type"] == "sign":
            # tools.log('can only have one sign tx per block')
            return False
    if len(tx["jackpots"]) < 1:
        tools.log("insufficient jackpots")
        return False
    length = tools.local_get("length")
    if int(tx["on_block"]) != int(length + 1):
        out[0] += "this tx is for the wrong block. have " + str(length + 1) + " need: " + str(tx["on_block"])
        return False
    if tx["on_block"] > 0:
        if not tx["prev"] == tools.db_get(length)["block_hash"]:
            tools.log("must give hash of previous block")
            return False
    ran = tools.det_random(tx["on_block"])
    for j in tx["jackpots"]:
        if type(j) != int or j not in range(200):
            tools.log("bad jackpot")
            return False
        if len(filter(lambda x: x == j, tx["jackpots"])) != 1:
            tools.log("no repeated jackpots")
            return False
        if not tools.winner(B, M, ran, address, j):
            tools.log("that jackpot is not valid: " + str(j))
            return False
    if tx["amount"] < custom.minimum_deposit:
        tools.log("you have to deposit more than that")
        return False
    return True
Ejemplo n.º 4
0
def create_sign_tx():
    on_block=tools.local_get('length')+1
    if on_block==0:
        time.sleep(1)
        return{'error':'not ready'}
    r=tools.det_random(on_block)
    jackpots=[]
    address=tools.local_get('address')
    l=max(-1, on_block-1-(custom.long_time*2-custom.medium_time))
    election_block=tools.db_get(l+1)
    proof=tools.local_get('balance_proofs'+str(l))
    if 'root_hash' not in election_block:
        return({'error':'database changed'})
    a=tools.db_verify(election_block['root_hash'], address, proof)
    if a==False:
        #tools.log('election block: ' +str(election_block))
        #tools.log('proof: ' +str(proof))
        return({'error':'not valid proof'})
    old_balance=a['amount']
    M=custom.all_money
    for j in range(custom.jackpot_nonces):
        if tools.winner(old_balance, M, r, address, j):
            jackpots.append(j)
    if len(jackpots)>0:
        tx={'on_block':on_block, 'jackpots':jackpots, 'type':'sign', 'amount':M/3000/3}
        tx['B']=old_balance
        tx['proof']=proof
        if proof=='empty':
            time.sleep(1)
            return {'error':'not ready'}
        secrets=tools.local_get('secrets')
        if str(on_block) in secrets:
            secret=secrets[str(on_block)]
        else:
            secret=tools.unpackage(tools.package({'salt':str(random.random())+str(random.random()), 'entropy':random.randint(0,1)}))
            secrets[str(on_block)]=secret
            tools.local_put('secrets', secrets)
        tx['secret_hash']=tools.det_hash(secret)
        if on_block>0:
            block=tools.db_get(on_block-1)
            if 'amount' in block and block['amount']==0:
                return({'error':'database changed'})
            #tools.log('on_block: ' +str(a))
            tx['prev']=block['block_hash']
    else:
        tx= {'error':'no jackpots'}
    return tx