The following exceptions should be expected: FileNotFoundError: given wallet path does not exist StorageReadWriteError: given file is not readable/writable or containing folder is not writable InvalidPassword: wallet requires a password but no password or an invalid password was given WalletFileException: any internal wallet data issue. specific subclasses can be caught separately: - WalletRequiresSplit: wallet needs splitting (split_data passed in Exception) - WalletRequiresUpgrade: wallet needs upgrade, and no upgrade=True was passed to load_wallet - WalletUnfinished: wallet file contains an action and needs additional information to finalize. (WalletDB passed in exception) Removed qml/qewalletdb.py This patch also fixes load_wallet calls in electrum/scripts and adds a qml workaround for dialogs opening and closing so fast that the dialog opened==true property change is missed (which we need to manage the dialog/page stack)
48 lines
1.8 KiB
Python
Executable File
48 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import asyncio
|
|
|
|
from electrum.simple_config import SimpleConfig
|
|
from electrum import constants
|
|
from electrum.daemon import Daemon
|
|
from electrum.storage import WalletStorage
|
|
from electrum.wallet import Wallet, create_new_wallet
|
|
from electrum.wallet_db import WalletDB
|
|
from electrum.commands import Commands
|
|
from electrum.util import create_and_start_event_loop, log_exceptions
|
|
|
|
|
|
loop, stopping_fut, loop_thread = create_and_start_event_loop()
|
|
|
|
config = SimpleConfig({"testnet": True}) # to use ~/.electrum/testnet as datadir
|
|
constants.set_testnet() # to set testnet magic bytes
|
|
daemon = Daemon(config, listen_jsonrpc=False)
|
|
network = daemon.network
|
|
assert network.asyncio_loop.is_running()
|
|
|
|
# get wallet on disk
|
|
wallet_dir = os.path.dirname(config.get_wallet_path())
|
|
wallet_path = os.path.join(wallet_dir, "test_wallet")
|
|
if not os.path.exists(wallet_path):
|
|
create_new_wallet(path=wallet_path, config=config)
|
|
|
|
# open wallet
|
|
wallet = daemon.load_wallet(wallet_path, password=None, upgrade=True)
|
|
wallet.start_network(network)
|
|
|
|
# you can use ~CLI commands by accessing command_runner
|
|
command_runner = Commands(config=config, daemon=daemon, network=network)
|
|
print("balance", network.run_from_another_thread(command_runner.getbalance(wallet=wallet)))
|
|
print("addr", network.run_from_another_thread(command_runner.getunusedaddress(wallet=wallet)))
|
|
print("gettx", network.run_from_another_thread(
|
|
command_runner.gettransaction("bd3a700b2822e10a034d110c11a596ee7481732533eb6aca7f9ca02911c70a4f")))
|
|
|
|
|
|
# but you might as well interact with the underlying methods directly
|
|
print("balance", wallet.get_balance())
|
|
print("addr", wallet.get_unused_address())
|
|
print("gettx", network.run_from_another_thread(network.get_transaction("bd3a700b2822e10a034d110c11a596ee7481732533eb6aca7f9ca02911c70a4f")))
|
|
|
|
stopping_fut.set_result(1) # to stop event loop
|