Esempio n. 1
0
#!/usr/bin/env python3
import json
import asyncio
from statistics import median
from numbers import Number

from electrum_onion.network import filter_protocol, Network
from electrum_onion.util import create_and_start_event_loop, log_exceptions
from electrum_onion.simple_config import SimpleConfig

config = SimpleConfig()

loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network(config)
network.start()


@log_exceptions
async def f():
    try:
        peers = await network.get_peers()
        peers = filter_protocol(peers)
        results = await network.send_multiple_requests(
            peers, 'blockchain.estimatefee', [2])
        print(json.dumps(results, indent=4))
        feerate_estimates = filter(lambda x: isinstance(x, Number),
                                   results.values())
        print(f"median feerate: {median(feerate_estimates)}")
    finally:
        stopping_fut.set_result(1)
Esempio n. 2
0
 def setUp(self):
     super().setUp()
     self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop(
     )
     self.config = SimpleConfig({'electrum_path': self.electrum_path})
Esempio n. 3
0
 def setUp(self):
     super().setUp()
     self.config = SimpleConfig({'electrum_path': self.electrum_path})
     self.interface = MockInterface(self.config)
Esempio n. 4
0
import os
import asyncio

from electrum_onion.simple_config import SimpleConfig
from electrum_onion import constants
from electrum_onion.daemon import Daemon
from electrum_onion.storage import WalletStorage
from electrum_onion.wallet import Wallet, create_new_wallet
from electrum_onion.wallet_db import WalletDB
from electrum_onion.commands import Commands
from electrum_onion.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-onion/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, manual_upgrades=False)
wallet.start_network(network)
Esempio n. 5
0
from electrum_onion.lnutil import LnFeatures

logger = get_logger(__name__)


# Configuration parameters
IS_TESTNET = False
TIMEOUT = 5  # for Lightning peer connections
WORKERS = 30  # number of workers that concurrently fetch results for feature comparison
NODES_PER_WORKER = 50
VERBOSITY = ''  # for debugging set '*', otherwise ''
FLAG = LnFeatures.OPTION_UPFRONT_SHUTDOWN_SCRIPT_OPT  # chose the 'opt' flag
PRESYNC = False  # should we sync the graph or take it from an already synced database?


config = SimpleConfig({"testnet": IS_TESTNET, "verbosity": VERBOSITY})
configure_logging(config)

loop, stopping_fut, loop_thread = create_and_start_event_loop()
# avoid race condition when starting network, in debug starting the asyncio loop
# takes some time
time.sleep(2)

if IS_TESTNET:
    constants.set_testnet()
daemon = Daemon(config, listen_jsonrpc=False)
network = daemon.network
assert network.asyncio_loop.is_running()

# create empty wallet
wallet_dir = os.path.dirname(config.get_wallet_path())
Esempio n. 6
0
 def setUp(self):
     super().setUp()
     self.data_dir = self.electrum_path
     make_dir(os.path.join(self.data_dir, 'forks'))
     self.config = SimpleConfig({'electrum_path': self.data_dir})
     blockchain.blockchains = {}
Esempio n. 7
0
#!/usr/bin/env python3
import json
import asyncio

from electrum_onion.simple_config import SimpleConfig
from electrum_onion.network import filter_version, Network
from electrum_onion.util import create_and_start_event_loop, log_exceptions
from electrum_onion import constants

# testnet?
#constants.set_testnet()
config = SimpleConfig({'testnet': False})

loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network(config)
network.start()


@log_exceptions
async def f():
    try:
        peers = await network.get_peers()
        peers = filter_version(peers)
        print(json.dumps(peers, sort_keys=True, indent=4))
    finally:
        stopping_fut.set_result(1)


asyncio.run_coroutine_threadsafe(f(), loop)