Ejemplo n.º 1
0
    def __init__(self, bcnode):
        self.p2p_port = new_port()
        self.rpc_port = new_port()
        self.data_dir = new_data_dir("lit")
        self.peer_mapping = {}

        # Write a hexkey to the privkey file
        with open(paths.join(self.data_dir, "privkey.hex"), 'w+') as f:
            s = ''
            for _ in range(64):
                s += hexchars[random.randint(0, len(hexchars) - 1)]
            print('Using key:', s)
            f.write(s + "\n")

        # See if we should print stdout
        outputredir = subprocess.DEVNULL
        ev_output_show = os.getenv("LIT_OUTPUT_SHOW", default="0")
        ev_show_id = os.getenv("LIT_ID_SHOW", default="X")
        if ev_output_show == "1" and (ev_show_id == "X"
                                      or ev_show_id == str(self.id)):
            outputredir = None

        # Now figure out the args to use and then start Lit.
        args = [
            LIT_BIN,
            "-v",
            "4",
            "--reg",
            "127.0.0.1:" + str(bcnode.p2p_port),
            "--tn3",
            "",  # disable autoconnect
            "--dir",
            self.data_dir,
            "--unauthrpc",
            "--rpcport=" + str(self.rpc_port),
            "--autoReconnect",
            "--autoListenPort=" + str(self.p2p_port)
        ]
        self.proc = subprocess.Popen(args,
                                     stdin=subprocess.DEVNULL,
                                     stdout=outputredir,
                                     stderr=outputredir)

        # Make the RPC client for future use, too.
        testutil.wait_until_port("localhost", self.rpc_port)
        self.rpc = litrpc.LitClient("localhost", str(self.rpc_port))

        # Make it listen to P2P connections!
        lres = self.rpc.Listen(Port=":" + str(self.p2p_port))
        testutil.wait_until_port("localhost", self.p2p_port)
        self.lnid = lres["Adr"]
Ejemplo n.º 2
0
    def __init__(self):
        self.p2p_port = new_port()
        self.rpc_port = new_port()
        self.data_dir = new_data_dir("bitcoind")

        # Actually start the bitcoind
        args = [
            "bitcoind",
            "-regtest",
            "-server",
            "-printtoconsole",
            "-datadir=" + self.data_dir,
            "-port=" + str(self.p2p_port),
            "-rpcuser=rpcuser",
            "-rpcpassword=rpcpass",
            "-rpcport=" + str(self.rpc_port),
        ]
        self.proc = subprocess.Popen(args,
                                     stdout=subprocess.DEVNULL,
                                     stderr=subprocess.DEVNULL)

        # Make the RPC client for it.
        testutil.wait_until_port("localhost", self.rpc_port)
        testutil.wait_until_port("localhost", self.p2p_port)
        self.rpc = btcrpc.BtcClient("localhost", self.rpc_port, "rpcuser",
                                    "rpcpass")

        # Make sure that we're actually ready to accept RPC calls.
        def ck_ready():
            bci = self.rpc.getblockchaininfo(
            )  # just need "some call" that'll fail if we're not ready
            if 'code' in bci and bci['code'] <= 0:
                return False
            else:
                return True

        testutil.wait_until(ck_ready, errmsg="took too long to load wallet")

        # Activate SegWit (apparently this is how you do it)
        self.rpc.generate(500)

        def ck_segwit():
            bci = self.rpc.getblockchaininfo()
            try:
                return bci["bip9_softforks"]["segwit"]["status"] == "active"
            except:
                return False

        testutil.wait_until(ck_segwit, errmsg="couldn't activate segwit")
Ejemplo n.º 3
0
    def start(self):
        # Sanity check.
        assert self.proc is None, "tried to start a node that is already started!"

        # See if we should print stdout
        outputredir = subprocess.DEVNULL
        ev_output_show = os.getenv("LIT_OUTPUT_SHOW", default="0")
        ev_show_id = os.getenv("LIT_ID_SHOW", default="X")
        if ev_output_show == "1" and (ev_show_id == "X"
                                      or ev_show_id == str(self.id)):
            outputredir = None

        # Now figure out the args to use and then start Lit.
        args = [
            LIT_BIN,
            "-vv",
            "--reg",
            "127.0.0.1:" + str(self.bcnode.p2p_port),
            "--tn3",
            "",  # disable autoconnect
            "--dir",
            self.data_dir,
            "--unauthrpc",
            "--rpcport=" + str(self.rpc_port),
            "--noautolisten"
        ]
        penv = os.environ.copy()
        lkw = 'LIT_KEYFILE_WARN'
        if lkw not in penv:
            penv[lkw] = '0'
        self.proc = subprocess.Popen(args,
                                     stdin=subprocess.DEVNULL,
                                     stdout=outputredir,
                                     stderr=outputredir,
                                     env=penv)

        # Make the RPC client for future use, too.
        testutil.wait_until_port("localhost", self.rpc_port)
        self.rpc = litrpc.LitClient("localhost", str(self.rpc_port))

        # Make it listen to P2P connections!
        lres = self.rpc.Listen(Port=self.p2p_port)
        testutil.wait_until_port("localhost", self.p2p_port)
        self.lnid = lres[
            "Adr"]  # technically we do this more times than we have to, that's okay