def __init__(self, name, config): """ Initializes new electrum wallet instance @param name: Name of the wallet @param config: Configuration dictionary e.g { 'server': 'localhost:7777:s', 'rpc_user': '******', 'rpc_pass_': 'pass', 'electrum_path': '/opt/var/data/electrum', 'seed': '....', 'fee': 10000, 'testnet': 1 } """ self._name = name self._config = config self._config['testnet'] = bool(self._config['testnet']) if self._config['testnet'] is True: constants.set_testnet() self._config['verbos'] = False self._electrum_config = SimpleConfig(self._config) self._wallet_path = os.path.join(self._electrum_config.path, 'wallets', self._name) self._storage = WalletStorage(path=self._wallet_path) if not self._storage.file_exists(): self._electrum_config.set_key('default_wallet_path', self._wallet_path) k = keystore.from_seed(self._config['seed'], self._config['passphrase'], False) k.update_password(None, self._config['password']) self._storage.put('keystore', k.dump()) self._storage.put('wallet_type', 'standard') self._storage.put('use_encryption', bool(self._config['password'])) self._storage.write() self._wallet = Wallet(self._storage) # self._server = daemon.get_server(self._electrum_config) self._network = Network(self._electrum_config) self._network.start() self._wallet.start_threads(self._network) self._wallet.synchronize() self._wallet.wait_until_synchronized() self._wallet.stop_threads() self._wallet.storage.write() else: self._network = None self._wallet = self._wallet = Wallet(self._storage) self._commands = Commands(config=self._electrum_config, wallet=self._wallet, network=self._network) self._init_commands()
from electrum import bitgesell from electrum.network import Network from electrum.util import json_encode, print_msg, create_and_start_event_loop, log_exceptions from electrum.simple_config import SimpleConfig try: addr = sys.argv[1] except Exception: print("usage: get_history <bitgesell_address>") sys.exit(1) config = SimpleConfig() loop, stopping_fut, loop_thread = create_and_start_event_loop() network = Network(config) network.start() @log_exceptions async def f(): try: sh = bitgesell.address_to_scripthash(addr) hist = await network.get_history_for_scripthash(sh) print_msg(json_encode(hist)) finally: stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop)
import sys import asyncio from electrum import bitcoin from electrum.network import Network from electrum.util import json_encode, print_msg, create_and_start_event_loop, log_exceptions try: addr = sys.argv[1] except Exception: print("usage: get_history <raycoin_address>") sys.exit(1) loop, stopping_fut, loop_thread = create_and_start_event_loop() network = Network() network.start() @log_exceptions async def f(): try: sh = bitcoin.address_to_scripthash(addr) hist = await network.get_history_for_scripthash(sh) print_msg(json_encode(hist)) finally: stopping_fut.set_result(1) asyncio.run_coroutine_threadsafe(f(), loop)
def __init__(self, nursery, config): self.network = Network(nursery, config) self.network.start() self.fx = FxThread(config, self.network) self.wallets = {}