Example #1
0
 def clean_state():
     transactions=blockchain.load_transactions()
     state=state_library.current_state()
     a=blockchain.verify_transactions(transactions, state)
     if a['bool']:
         return a['newstate']
     else:
         print('EEROR###33####3')
         time.sleep(1)
Example #2
0
 def clean_state():
     transactions = blockchain.load_transactions()
     state = state_library.current_state()
     a = blockchain.verify_transactions(transactions, state)
     print('a: ' + str(a))
     print('transactions: ' + str(transactions))
     try:
         return a['newstate']
     except:
         blockchain.reset_transactions()
Example #3
0
 def clean_state():
     transactions=blockchain.load_transactions()
     state=state_library.current_state()
     a=blockchain.verify_transactions(transactions, state)
     print('a: ' +str(a))
     print('transactions: ' +str(transactions))
     try:
         return a['newstate']
     except:
         blockchain.reset_transactions()
Example #4
0
 def clean_state():
     transactions=blockchain.load_transactions()
     state=state_library.current_state()
     return blockchain.verify_transactions(transactions, state)['newstate']
Example #5
0
 def clean_state():
     transactions=blockchain.load_transactions()
     state=state_library.current_state()
     a=blockchain.verify_transactions(transactions, state)
     print('a: ' +str(a))
     return a['newstate']
Example #6
0
 def clean_state():
     transactions = blockchain.load_transactions()
     state = state_library.current_state()
     return blockchain.verify_transactions(transactions, state)['newstate']
Example #7
0
def home(dic):
    print (dic)
    if "BrainWallet" in dic:
        dic["privkey"] = pt.sha256(dic["BrainWallet"])
    privkey = dic["privkey"]
    print ("priv: " + str(dic["privkey"]))
    pubkey = pt.privtopub(dic["privkey"])
    if "do" in dic.keys():
        if dic["do"] == "newGame":
            try:
                a = newgame(dic["partner"], dic["game"], pubkey, privkey, int(dic["size"]), dic["amount"])
            except:
                a = newgame(dic["partner"], dic["game"], pubkey, privkey, 19, dic["amount"])
            active_games.append(dic["game"])
        if dic["do"] == "winGame":
            wingame(dic["game"], pubkey, privkey)
        if dic["do"] == "joinGame":
            active_games.append(dic["game"])
        if dic["do"] == "deleteGame":
            active_games.remove(dic["game"])
    if "move" in dic.keys():
        string = dic["move"].split(",")
        i = int(string[0])
        j = int(string[1])
        move(dic["game"], [i, j], pubkey, privkey)
    fs = fs_load()
    out = empty_page
    out = out.format("<p>your address is: " + str(pubkey) + "</p>{}")
    state = state_library.current_state()
    out = out.format("<p>current block is: " + str(state["length"]) + "</p>{}")
    transactions = blockchain.load_transactions()
    a = blockchain.verify_transactions(transactions, state)
    if a["bool"]:
        state = a["newstate"]
    else:
        pass
        print (a)
        print (transactions)
        print ("ERROR")
    if pubkey not in state:
        state[pubkey] = {"amount": 0}
    if "amount" not in state[pubkey]:
        state[pubkey]["amount"] = 0
    out = out.format("<p>current balance is: " + str(state[pubkey]["amount"] / 100000.0) + "</p>{}")
    for game in active_games:
        out = out.format("<h1>" + str(game) + "</h1>{}")
        if game in state:
            out = out.format(
                "<h1>Timer: " + str(state[game]["last_move_time"] + state[game]["time"] - state["length"]) + " </h1>{}"
            )
        if game in state.keys():
            in_last_block = state[game]
            out = board(out, state, game, privkey)
            out = out.format(
                easyForm(
                    "/home",
                    "win this game",
                    """
            <input type="hidden" name="do" value="winGame">
            <input type="hidden" name="privkey" value="{}">
            <input type="hidden" name="game"  value="{}">""".format(
                        privkey, game
                    ),
                )
            )
            out = out.format(
                easyForm(
                    "/home",
                    "leave this game",
                    """
            <input type="hidden" name="do" value="deleteGame">
            <input type="hidden" name="privkey" value="{}">
            <input type="hidden" name="game"  value="{}">""".format(
                        privkey, game
                    ),
                )
            )
        else:
            out = out.format("<p>this game does not yet exist</p>{}")
            out = out.format(
                easyForm(
                    "/home",
                    "delete this game",
                    """
            <input type="hidden" name="do" value="deleteGame">
            <input type="hidden" name="privkey" value="{}">
            <input type="hidden" name="game"  value="{}">""".format(
                        privkey, game
                    ),
                )
            )
    out = out.format(
        easyForm(
            "/home",
            "Refresh boards",
            """
    <input type="hidden" name="privkey" value="{}">
    """.format(
                privkey
            ),
        )
    )
    out = out.format(
        easyForm(
            "/home",
            "Join Game",
            """
    <input type="hidden" name="do" value="joinGame">
    <input type="hidden" name="privkey" value="{}">
    <input type="text" name="game" value="unique game name">
    """.format(
                privkey
            ),
        )
    )
    out = out.format(
        easyForm(
            "/home",
            "New Game",
            """
    <input type="hidden" name="do" value="newGame">
    <input type="hidden" name="privkey" value="{}">
    <input type="text" name="game" value="unique game name">
    <input type="text" name="partner" value="put your partners address here.">
    <input type="text" name="size" value="board size (9, 13, 19 are popular)">
    <input type="text" name="amount" value="0">
    """.format(
                privkey
            ),
        )
    )
    return out
Example #8
0
File: gui.py Project: Aeium/go-coin
def home(dic):
    print(dic)
    if 'BrainWallet' in dic:
        dic['privkey']=pt.sha256(dic['BrainWallet'])
    privkey=dic['privkey']
    print('priv: ' +str(dic['privkey']))
    pubkey=pt.privtopub(dic['privkey'])
    if 'do' in dic.keys():
        if dic['do']=='newGame':
            try:
                a=newgame(dic['partner'], dic['game'], pubkey, privkey, int(dic['size']), dic['amount'])
            except:
                a=newgame(dic['partner'], dic['game'], pubkey, privkey, 19, dic['amount'])
            active_games.append(dic['game'])
        if dic['do']=='winGame':
            wingame(dic['game'], pubkey, privkey)
        if dic['do']=='joinGame':
            active_games.append(dic['game'])
        if dic['do']=='deleteGame':
            active_games.remove(dic['game'])
    if 'move' in dic.keys():
        string=dic['move'].split(',')
        i=int(string[0])
        j=int(string[1])
        move(dic['game'], [i, j], pubkey, privkey)
    fs=fs_load()
    out=empty_page
    out=out.format('<p>your address is: ' +str(pubkey)+'</p>{}')
    state=state_library.current_state()
    out=out.format('<p>current block is: ' +str(state['length'])+'</p>{}')
    transactions=blockchain.load_transactions()
    a=blockchain.verify_transactions(transactions, state)
    if a['bool']:
        state=a['newstate']
    else:
        pass
        print(a)
        print(transactions)
        print('ERROR')
    if pubkey not in state:
        state[pubkey]={'amount':0}
    if 'amount' not in state[pubkey]:
        state[pubkey]['amount']=0
    out=out.format('<p>current balance is: ' +str(state[pubkey]['amount']/100000.0)+'</p>{}')        
    for game in active_games:
        out=out.format("<h1>"+str(game)+"</h1>{}")
        if game in state:
            out=out.format('<h1>Timer: ' + str(state[game]['last_move_time']+state[game]['time']-state['length'])+' </h1>{}')
        if game in state.keys():
            in_last_block=state[game]
            out=board(out, state, game, privkey)
            out=out.format(easyForm('/home', 'win this game', '''
            <input type="hidden" name="do" value="winGame">
            <input type="hidden" name="privkey" value="{}">
            <input type="hidden" name="game"  value="{}">'''.format(privkey, game)))
            out=out.format(easyForm('/home', 'leave this game', '''
            <input type="hidden" name="do" value="deleteGame">
            <input type="hidden" name="privkey" value="{}">
            <input type="hidden" name="game"  value="{}">'''.format(privkey, game)))
        else:
            out=out.format("<p>this game does not yet exist</p>{}")
            out=out.format(easyForm('/home', 'delete this game', '''
            <input type="hidden" name="do" value="deleteGame">
            <input type="hidden" name="privkey" value="{}">
            <input type="hidden" name="game"  value="{}">'''.format(privkey,game)))
    out=out.format(easyForm('/home', 'Refresh boards', '''
    <input type="hidden" name="privkey" value="{}">
    '''.format(privkey)))    
    out=out.format(easyForm('/home', 'Join Game', '''
    <input type="hidden" name="do" value="joinGame">
    <input type="hidden" name="privkey" value="{}">
    <input type="text" name="game" value="unique game name">
    '''.format(privkey)))
    out=out.format(easyForm('/home', 'New Game', '''
    <input type="hidden" name="do" value="newGame">
    <input type="hidden" name="privkey" value="{}">
    <input type="text" name="game" value="unique game name">
    <input type="text" name="partner" value="put your partners address here.">
    <input type="text" name="size" value="board size (9, 13, 19 are popular)">
    <input type="text" name="amount" value="0">
    '''.format(privkey)))
    return out