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)
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)
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
def sha256(x): return pt.sha256(x) def sign(msg, privkey): pt.ecdsa_sign(msg, privkey)