Exemplo n.º 1
0
def home(DB, dic):
    if 'BrainWallet' in dic:
        dic['privkey'] = pt.sha256(dic['BrainWallet'])
    elif 'privkey' not in dic:
        return "<p>You didn't type in your brain wallet.</p>"
    privkey = dic['privkey']
    pubkey = pt.privtopub(dic['privkey'])
    if 'do' in dic.keys():
        if dic['do'] == 'spend':
            spend(float(dic['amount']), pubkey, privkey, dic['to'], DB)
    out = empty_page
    out = out.format('<p>your address: ' + str(tools.pub2addr(pubkey)) + '</p>{}')
    out = out.format('<p>current block: ' + str(DB['length']) + '</p>{}')
    try:
        balance = blockchain.db_get(pubkey, DB)
        balance = balance['amount']
    except:
        balance = 0
    for tx in DB['txs']:
        if tx['type'] == 'spend' and tx['to'] == tools.pub2addr(pubkey):
            balance += tx['amount']
        if tx['type'] == 'spend' and tx['id'] == pubkey:
            balance -= tx['amount']
    out = out.format('<p>current balance is: ' + str(balance / 100000.0) + '</p>{}')
    if balance > 0:
        out = out.format(easyForm('/home', 'spend money', '''
        <input type="hidden" name="do" value="spend">
        <input type="text" name="to" value="address to give to">
        <input type="text" name="amount" value="amount to spend">
        <input type="hidden" name="privkey" value="{}">'''.format(privkey)))    
    txt = '''    <input type="hidden" name="privkey" value="{}">'''
    s = easyForm('/home', 'Refresh', txt.format(privkey))
    return out.format(s)
Exemplo n.º 2
0
def db_get (n, DB): 
    n=str(n)
    if len(n)==130: n=tools.pub2addr(n)
    try:
        a=DB['db'].Get(n)
    except:
        error('here')
    return tools.unpackage(a)
Exemplo n.º 3
0
def db_get(n, DB): 
    n=str(n)
    if len(n)==130: 
        n=tools.pub2addr(n)
        try:
            a=DB['db'].Get(n)
        except:
            db_put(n, {'count':0, 'amount':0}, DB)#everyone defaults with having zero money, and having broadcast zero transcations.
            return db_get(n, DB)
    return tools.unpackage(DB['db'].Get(n))
Exemplo n.º 4
0
def home(DB, dic):
    if "BrainWallet" in dic:
        dic["privkey"] = pt.sha256(dic["BrainWallet"])
    elif "privkey" not in dic:
        return "<p>You didn't type in your brain wallet.</p>"
    privkey = dic["privkey"]
    pubkey = pt.privtopub(dic["privkey"])
    if "do" in dic.keys():
        if dic["do"] == "spend":
            spend(float(dic["amount"]), pubkey, privkey, dic["to"], DB)
    out = empty_page
    out = out.format("<p>your address is: " + str(tools.pub2addr(pubkey)) + "</p>{}")
    out = out.format("<p>current block is: " + str(DB["length"]) + "</p>{}")
    try:
        balance = blockchain.db_get(pubkey, DB)
        balance = balance["amount"]
    except:
        balance = 0
    for tx in DB["txs"]:
        if tx["type"] == "spend" and tx["to"] == tools.pub2addr(pubkey):
            balance += tx["amount"]
        if tx["type"] == "spend" and tx["id"] == pubkey:
            balance -= tx["amount"]
    out = out.format("<p>current balance is: " + str(balance / 100000.0) + "</p>{}")
    if balance > 0:
        out = out.format(
            easyForm(
                "/home",
                "spend money",
                """
        <input type="hidden" name="do" value="spend">
        <input type="text" name="to" value="address to give to">
        <input type="text" name="amount" value="amount to spend">
        <input type="hidden" name="privkey" value="{}">""".format(
                    privkey
                ),
            )
        )
    s = easyForm("/home", "Refresh", """    <input type="hidden" name="privkey" value="{}">""".format(privkey))
    return out.format(s)
Exemplo n.º 5
0
def db_put(key, dic, DB):  
    key=str(key)
    if len(key)==130: key=tools.pub2addr(key)#store by pubkey hash instead of 
    #pubkey to defend against theoretical quantum computing attack.
    return DB['db'].Put(key, tools.package(dic))
Exemplo n.º 6
0
def db_put(key, dic, DB):  
    key=str(key)
    if len(key)==130: key=tools.pub2addr(key)
    return DB['db'].Put(key, tools.package(dic))