예제 #1
0
import sys
import asyncio

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

try:
    txid = sys.argv[1]
except:
    print("usage: txradar txid")
    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:
        peers = await network.get_peers()
        peers = filter_protocol(peers, 's')
        results = await network.send_multiple_requests(
            peers, 'blockchain.transaction.get', [txid])
        r1, r2 = [], []
        for k, v in results.items():
            (r1 if not isinstance(v, Exception) else r2).append(k)
        print(f"Received {len(results)} answers")
예제 #2
0
 def setUp(self):
     super().setUp()
     self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop(
     )
예제 #3
0
from electrum_ltc.network import Network
from electrum_ltc.util import print_msg, create_and_start_event_loop
from electrum_ltc.synchronizer import SynchronizerBase
from electrum_ltc.simple_config import SimpleConfig

try:
    addr = sys.argv[1]
except Exception:
    print("usage: watch_address <litecoin_address>")
    sys.exit(1)

config = SimpleConfig()

# start network
loop = create_and_start_event_loop()[0]
network = Network(config)
network.start()


class Notifier(SynchronizerBase):
    def __init__(self, network):
        SynchronizerBase.__init__(self, network)
        self.watched_addresses = set()
        self.watch_queue = asyncio.Queue()

    async def main(self):
        # resend existing subscriptions if we were restarted
        for addr in self.watched_addresses:
            await self._add_address(addr)
        # main loop
예제 #4
0
#!/usr/bin/env python3
import asyncio

from electrum_ltc.network import filter_protocol, Network
from electrum_ltc.util import create_and_start_event_loop, log_exceptions
from electrum_ltc.blockchain import hash_raw_header

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, 's')
        results = await network.send_multiple_requests(peers, 'blockchain.headers.subscribe', [])
        for server, header in sorted(results.items(), key=lambda x: x[1].get('height')):
            height = header.get('height')
            blockhash = hash_raw_header(header.get('hex'))
            print(server, height, blockhash)
    finally:
        stopping_fut.set_result(1)

asyncio.run_coroutine_threadsafe(f(), loop)
예제 #5
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})
예제 #6
0
 def setUp(self):
     super().setUp()
     self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop()
     self.alice_channel, self.bob_channel = create_test_channels()
예제 #7
0
import sys
import asyncio

from electrum_ltc.network import Network
from electrum_ltc.util import print_msg, create_and_start_event_loop
from electrum_ltc.synchronizer import SynchronizerBase


try:
    addr = sys.argv[1]
except Exception:
    print("usage: watch_address <litecoin_address>")
    sys.exit(1)

# start network
loop = create_and_start_event_loop()[0]
network = Network()
network.start()


class Notifier(SynchronizerBase):
    def __init__(self, network):
        SynchronizerBase.__init__(self, network)
        self.watched_addresses = set()
        self.watch_queue = asyncio.Queue()

    async def main(self):
        # resend existing subscriptions if we were restarted
        for addr in self.watched_addresses:
            await self._add_address(addr)
        # main loop