示例#1
0
def test_save_nonce():
    w = wallet.generate_new_wallet()
    wallet_database.save_wallet(w)
    assert wallet_database.load_wallet().get_nonce() == 0
    wallet_database.save_nonce(10)
    assert wallet_database.load_wallet().get_nonce() == 10
    assert wallet_database.get_nonce() == 10
示例#2
0
def test_save_load_wallet():
    # saving and loading wallet
    w1 = wallet.generate_new_wallet()
    wallet_database.save_wallet(w1)
    w2 = wallet_database.load_wallet()
    assert w1.get_address() == w2.get_address()
    assert w1.get_private_key().to_der() == w2.get_private_key().to_der()
    assert w1.get_nonce() == w2.get_nonce()
示例#3
0
 def __init__(self, block: Block):
     threading.Thread.__init__(self)
     self.stop = threading.Event()
     self.wallet = wallet_database.load_wallet()
     self.event_manager = EventManager()
     self.peer = p2p_api.create_a_peer(role="myself",
                                       name=self.wallet.get_address(),
                                       host=("0.0.0.0", 8000))
     self.pool = Pool()
     self.start()
 def gen_wallet(self):
     # we only want to generate a new wallet if there is none
     # (todo make it better, if input throws an exception the old wallet is gone)
     try:
         wallet_database.load_wallet()
         y = input(
             "There is already a wallet with address:\n " +
             wallet_database.get_address() +
             "\nGenerating a new wallet would override Your old wallet.\n\n"
             +
             "You would loose access to the old wallet.\n\nAre You Sure? (y/N)"
         )
         if y == "y" or y == "Y":
             wallet_database.save_wallet(wallet.generate_new_wallet())
             print("\nGenerated wallet with address:\n" +
                   wallet_database.get_address())
     except:
         wallet_database.save_wallet(wallet.generate_new_wallet())
         print("generated wallet with address:" +
               wallet_database.get_address())
 def run(self):
     if self.options["get"]:
         print("todo")
     elif self.options["publish"]:
         print("todo")
     elif self.options["verify"]:
         try:
             from_json_string(self.options["<json_string>"]).verify()
             print(True)
         except:
             print(False)
     elif self.options["sign"]:
         w = wallet_database.load_wallet()
         t = from_json_string(self.options["<json_string>"])
         t.sender_address = w.get_address()
         w.sign_transaction(t)
         wallet_database.save_nonce(w.get_nonce())
         print("Hash:\n" + t.hash())
         print("Raw:\n" + t.string())