Example #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)
Example #2
0
def easy_add_transaction(tx_orig, privkey, DB):
    tx = copy.deepcopy(tx_orig)
    pubkey = pt.privtopub(privkey)
    try:
        tx['count'] = blockchain.count(pubkey, DB)
    except:
        tx['count'] = 1
    tx['signature'] = pt.ecdsa_sign(tools.det_hash(tx), privkey)
    blockchain.add_tx(tx, DB)
Example #3
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)
Example #4
0
def privtopub(privkey): return pt.privtopub(privkey)
def hash_(x): return hashlib.sha384(x).hexdigest()[0:64]
Example #5
0
import pt
#This is for easy customization of new currencies.
database_name='DB.db'
listen_port=8900
gui_port=8700
version="VERSION"
block_reward=10**5
premine=5*10**6
fee=10**3
brainwallet='brain wallet'
privkey=pt.sha256(brainwallet)
pubkey=pt.privtopub(privkey)
peers=[['localhost', 8901],
       ['localhost', 8902],
       ['localhost', 8903],
       ['localhost', 8904],
       ['localhost', 8905]]
hashes_per_check=10**5

def blocktime(length):
    if length*block_reward<premine:
        return 30
    else:
        return 60

Example #6
0
def privtopub(privkey): return pt.privtopub(privkey)

def det_hash(x):#deterministically takes sha256 of dict, list, int, or string
Example #7
0
def privtopub(privkey):
    return pt.privtopub(privkey)
Example #8
0
def privtopub(privkey):
    return pt.privtopub(privkey)
Example #9
0
def privtopub(privkey): return pt.privtopub(privkey)
def hash_(x): return hashlib.sha384(x).hexdigest()[0:64]