def load_wallets(self): """Load existing wallets from disk.""" count = 0 for path in glob("webwallet_*.wallet"): w = Wallet.load_keys(path) self.wallets[path] = w count += 1 logging.debug(f"Successfully loaded {count} wallets from disk")
def do_wallet_show(args): """Display wallet information.""" print("Showing wallet") w = Wallet.load_keys(args.wallet) addr = w.get_address() balance = args.api.get_balance(addr) print(f"Address: {addr}") print(f"Balance: {balance}")
def do_mine(args): """Mine a block.""" w = Wallet.load_keys(args.wallet) magic = args.api.get_magic() coinbase = transaction.Transaction("0", w.get_address(), 1, magic=magic) print("Mining block...") b = mine(coinbase, args.api) print("Pushing block...") args.api.push_block(b) print("Successfully mined block.")
def do_transaction(args): """Perform a transaction.""" w = Wallet.load_keys(args.wallet) magic = args.api.get_magic() tx = transaction.Transaction(w.get_address(), args.destination, args.amount, magic=magic) w.sign_transaction(tx) if args.api.push_transaction(tx): print("Transaction successfully broadcasted.") else: print("[Error] Failed to broadcast transaction.")
def test_save_and_load_key(self): # Create a temporary directory self.test_dir = tempfile.mkdtemp() self.test_file = path.join(self.test_dir, "test.pem") t = Wallet() t.create_keys() t.save_key(self.test_file) t2 = Wallet.load_keys(self.test_file) self.assertIsNotNone(t.get_address()) self.assertIsNotNone(t2.get_address()) self.assertEqual(t2.get_address(), t.get_address()) shutil.rmtree(self.test_dir)