コード例 #1
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})
コード例 #2
0
#!/usr/bin/env python3

# A simple script that connects to a server and displays block headers

import time
import asyncio

from electrum_grlc.network import Network
from electrum_grlc.util import print_msg, json_encode, create_and_start_event_loop, log_exceptions
from electrum_grlc.simple_config import SimpleConfig

config = SimpleConfig()

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

# wait until connected
while not network.is_connected():
    time.sleep(1)
    print_msg("waiting for network to get connected...")

header_queue = asyncio.Queue()

@log_exceptions
async def f():
    try:
        await network.interface.session.subscribe('blockchain.headers.subscribe', [], header_queue)
        # 3. wait for results
        while network.is_connected():
コード例 #3
0
from electrum_grlc.wallet import create_new_wallet
from electrum_grlc.util import create_and_start_event_loop, log_exceptions, bh2u, bfh
from electrum_grlc.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())
コード例 #4
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 = {}
コード例 #5
0
 def setUp(self):
     super().setUp()
     self.config = SimpleConfig({'electrum_path': self.electrum_path})
     self.interface = MockInterface(self.config)
コード例 #6
0
import os
import asyncio

from electrum_grlc.simple_config import SimpleConfig
from electrum_grlc import constants
from electrum_grlc.daemon import Daemon
from electrum_grlc.storage import WalletStorage
from electrum_grlc.wallet import Wallet, create_new_wallet
from electrum_grlc.wallet_db import WalletDB
from electrum_grlc.commands import Commands
from electrum_grlc.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-grlc/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)
コード例 #7
0

def get_newly_added_servers(fname1, fname2=None):
    with open(fname1) as f:
        res_hostmap = json.loads(f.read())
    if fname2 is not None:
        with open(fname2) as f:
            dict2 = json.loads(f.read())
        common_set = set.intersection(set(res_hostmap), set(dict2))
        res_hostmap = {k: v for k, v in res_hostmap.items() if k in common_set}
    return res_hostmap


# 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:
        # prune existing servers
        old_servers_all = constants.net.DEFAULT_SERVERS
        old_servers_online = await network.prune_offline_servers(
            constants.net.DEFAULT_SERVERS)
        # add new servers
        newly_added_servers = get_newly_added_servers(fname1, fname2)
コード例 #8
0
 def test_fee_to_depth(self):
     config = SimpleConfig(self.options)
     config.mempool_fees = [[49, 100000], [10, 120000], [6, 150000],
                            [5, 125000], [1, 36000000]]
     self.assertEqual(100000, config.fee_to_depth(500))
     self.assertEqual(100000, config.fee_to_depth(50))
     self.assertEqual(100000, config.fee_to_depth(49))
     self.assertEqual(220000, config.fee_to_depth(48))
     self.assertEqual(220000, config.fee_to_depth(10))
     self.assertEqual(370000, config.fee_to_depth(9))
     self.assertEqual(370000, config.fee_to_depth(6.5))
     self.assertEqual(370000, config.fee_to_depth(6))
     self.assertEqual(495000, config.fee_to_depth(5.5))
     self.assertEqual(36495000, config.fee_to_depth(0.5))
コード例 #9
0
 def test_depth_target_to_fee(self):
     config = SimpleConfig(self.options)
     config.mempool_fees = [[49, 100110], [10, 121301], [6, 153731],
                            [5, 125872], [1, 36488810]]
     self.assertEqual(2 * 1000, config.depth_target_to_fee(1000000))
     self.assertEqual(6 * 1000, config.depth_target_to_fee(500000))
     self.assertEqual(7 * 1000, config.depth_target_to_fee(250000))
     self.assertEqual(11 * 1000, config.depth_target_to_fee(200000))
     self.assertEqual(50 * 1000, config.depth_target_to_fee(100000))
     config.mempool_fees = []
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**5))
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**6))
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**7))
     config.mempool_fees = [[1, 36488810]]
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**5))
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**6))
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**7))
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**8))
     config.mempool_fees = [[5, 125872], [1, 36488810]]
     self.assertEqual(6 * 1000, config.depth_target_to_fee(10**5))
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**6))
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**7))
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**8))
     config.mempool_fees = []
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**5))
     config.mempool_fees = None
     self.assertEqual(None, config.depth_target_to_fee(10**5))