コード例 #1
0
ファイル: test_lnpeer.py プロジェクト: kxiong1234/vialectrum
 def prepare_peers(self, alice_channel, bob_channel):
     k1, k2 = keypair(), keypair()
     t1, t2 = transport_pair(k2, k1, alice_channel.name, bob_channel.name)
     q1, q2 = asyncio.Queue(), asyncio.Queue()
     w1 = MockLNWallet(k1, k2, alice_channel, tx_queue=q1)
     w2 = MockLNWallet(k2, k1, bob_channel, tx_queue=q2)
     p1 = Peer(w1, k1.pubkey, t1)
     p2 = Peer(w2, k2.pubkey, t2)
     w1.peer = p1
     w2.peer = p2
     # mark_open won't work if state is already OPEN.
     # so set it to FUNDED
     alice_channel._state = ChannelState.FUNDED
     bob_channel._state = ChannelState.FUNDED
     # this populates the channel graph:
     p1.mark_open(alice_channel)
     p2.mark_open(bob_channel)
     return p1, p2, w1, w2, q1, q2
コード例 #2
0
 def prepare_peers(self):
     k1, k2 = keypair(), keypair()
     t1, t2 = transport_pair(self.alice_channel.name, self.bob_channel.name)
     q1, q2 = asyncio.Queue(), asyncio.Queue()
     w1 = MockLNWallet(k1, k2, self.alice_channel, tx_queue=q1)
     w2 = MockLNWallet(k2, k1, self.bob_channel, tx_queue=q2)
     p1 = Peer(w1, k1.pubkey, t1)
     p2 = Peer(w2, k2.pubkey, t2)
     w1.peer = p1
     w2.peer = p2
     # mark_open won't work if state is already OPEN.
     # so set it to OPENING
     self.alice_channel.set_state("OPENING")
     self.bob_channel.set_state("OPENING")
     # this populates the channel graph:
     p1.mark_open(self.alice_channel)
     p2.mark_open(self.bob_channel)
     return p1, p2, w1, w2, q1, q2
コード例 #3
0
    def prepare_chans_and_peers_in_square(self) -> SquareGraph:
        key_a, key_b, key_c, key_d = [keypair() for i in range(4)]
        chan_ab, chan_ba = create_test_channels(alice_name="alice",
                                                bob_name="bob",
                                                alice_pubkey=key_a.pubkey,
                                                bob_pubkey=key_b.pubkey)
        chan_ac, chan_ca = create_test_channels(alice_name="alice",
                                                bob_name="carol",
                                                alice_pubkey=key_a.pubkey,
                                                bob_pubkey=key_c.pubkey)
        chan_bd, chan_db = create_test_channels(alice_name="bob",
                                                bob_name="dave",
                                                alice_pubkey=key_b.pubkey,
                                                bob_pubkey=key_d.pubkey)
        chan_cd, chan_dc = create_test_channels(alice_name="carol",
                                                bob_name="dave",
                                                alice_pubkey=key_c.pubkey,
                                                bob_pubkey=key_d.pubkey)
        trans_ab, trans_ba = transport_pair(key_a, key_b, chan_ab.name,
                                            chan_ba.name)
        trans_ac, trans_ca = transport_pair(key_a, key_c, chan_ac.name,
                                            chan_ca.name)
        trans_bd, trans_db = transport_pair(key_b, key_d, chan_bd.name,
                                            chan_db.name)
        trans_cd, trans_dc = transport_pair(key_c, key_d, chan_cd.name,
                                            chan_dc.name)
        txq_a, txq_b, txq_c, txq_d = [asyncio.Queue() for i in range(4)]
        w_a = MockLNWallet(local_keypair=key_a,
                           chans=[chan_ab, chan_ac],
                           tx_queue=txq_a)
        w_b = MockLNWallet(local_keypair=key_b,
                           chans=[chan_ba, chan_bd],
                           tx_queue=txq_b)
        w_c = MockLNWallet(local_keypair=key_c,
                           chans=[chan_ca, chan_cd],
                           tx_queue=txq_c)
        w_d = MockLNWallet(local_keypair=key_d,
                           chans=[chan_db, chan_dc],
                           tx_queue=txq_d)
        peer_ab = Peer(w_a, key_b.pubkey, trans_ab)
        peer_ac = Peer(w_a, key_c.pubkey, trans_ac)
        peer_ba = Peer(w_b, key_a.pubkey, trans_ba)
        peer_bd = Peer(w_b, key_d.pubkey, trans_bd)
        peer_ca = Peer(w_c, key_a.pubkey, trans_ca)
        peer_cd = Peer(w_c, key_d.pubkey, trans_cd)
        peer_db = Peer(w_d, key_b.pubkey, trans_db)
        peer_dc = Peer(w_d, key_c.pubkey, trans_dc)
        w_a._peers[peer_ab.pubkey] = peer_ab
        w_a._peers[peer_ac.pubkey] = peer_ac
        w_b._peers[peer_ba.pubkey] = peer_ba
        w_b._peers[peer_bd.pubkey] = peer_bd
        w_c._peers[peer_ca.pubkey] = peer_ca
        w_c._peers[peer_cd.pubkey] = peer_cd
        w_d._peers[peer_db.pubkey] = peer_db
        w_d._peers[peer_dc.pubkey] = peer_dc

        w_b.network.config.set_key('lightning_forward_payments', True)
        w_c.network.config.set_key('lightning_forward_payments', True)

        # mark_open won't work if state is already OPEN.
        # so set it to FUNDED
        for chan in [
                chan_ab, chan_ac, chan_ba, chan_bd, chan_ca, chan_cd, chan_db,
                chan_dc
        ]:
            chan._state = ChannelState.FUNDED
        # this populates the channel graph:
        peer_ab.mark_open(chan_ab)
        peer_ac.mark_open(chan_ac)
        peer_ba.mark_open(chan_ba)
        peer_bd.mark_open(chan_bd)
        peer_ca.mark_open(chan_ca)
        peer_cd.mark_open(chan_cd)
        peer_db.mark_open(chan_db)
        peer_dc.mark_open(chan_dc)
        return SquareGraph(
            w_a=w_a,
            w_b=w_b,
            w_c=w_c,
            w_d=w_d,
            peer_ab=peer_ab,
            peer_ac=peer_ac,
            peer_ba=peer_ba,
            peer_bd=peer_bd,
            peer_ca=peer_ca,
            peer_cd=peer_cd,
            peer_db=peer_db,
            peer_dc=peer_dc,
            chan_ab=chan_ab,
            chan_ac=chan_ac,
            chan_ba=chan_ba,
            chan_bd=chan_bd,
            chan_ca=chan_ca,
            chan_cd=chan_cd,
            chan_db=chan_db,
            chan_dc=chan_dc,
        )