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

from electrum_xzc.network import filter_protocol, Network
from electrum_xzc.util import create_and_start_event_loop, log_exceptions


loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network()
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)

asyncio.run_coroutine_threadsafe(f(), loop)
Beispiel #2
0
#!/usr/bin/env python3
import json
import asyncio

from electrum_xzc.simple_config import SimpleConfig
from electrum_xzc.network import filter_version, Network
from electrum_xzc.util import create_and_start_event_loop, log_exceptions
from electrum_xzc 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)