示例#1
0
    async def paid_invoices_stream(self) -> AsyncGenerator[str, None]:
        async with purerpc.secure_channel(
            self.endpoint,
            self.port,
            get_ssl_context(self.cert_path),
        ) as channel:
            client = purerpc.Client("lnrpc.Lightning", channel)
            subscribe_invoices = client.get_method_stub(
                "SubscribeInvoices",
                purerpc.RPCSignature(
                    purerpc.Cardinality.UNARY_STREAM,
                    ln.InvoiceSubscription,
                    ln.Invoice,
                ),
            )
            macaroon = load_macaroon(self.macaroon_path)

            async for inv in subscribe_invoices(
                ln.InvoiceSubscription(),
                metadata=[("macaroon", macaroon)],
            ):
                if not inv.settled:
                    continue

                checking_id = stringify_checking_id(inv.r_hash)
                yield checking_id

        print("lost connection to lnd InvoiceSubscription, please restart lnbits.")
示例#2
0
 def __init__(self, channel):
     self._client = purerpc.Client("Greeter", channel)
     self.SayHello = self._client.get_method_stub(
         "SayHello",
         purerpc.RPCSignature(
             purerpc.Cardinality.UNARY_UNARY,
             generated.greeter_pb2.HelloRequest,
             generated.greeter_pb2.HelloReply,
         ))
     self.SayHelloGoodbye = self._client.get_method_stub(
         "SayHelloGoodbye",
         purerpc.RPCSignature(
             purerpc.Cardinality.UNARY_STREAM,
             generated.greeter_pb2.HelloRequest,
             generated.greeter_pb2.HelloReply,
         ))
     self.SayHelloToMany = self._client.get_method_stub(
         "SayHelloToMany",
         purerpc.RPCSignature(
             purerpc.Cardinality.STREAM_STREAM,
             generated.greeter_pb2.HelloRequest,
             generated.greeter_pb2.HelloReply,
         ))
     self.SayHelloToManyAtOnce = self._client.get_method_stub(
         "SayHelloToManyAtOnce",
         purerpc.RPCSignature(
             purerpc.Cardinality.STREAM_UNARY,
             generated.greeter_pb2.HelloRequest,
             generated.greeter_pb2.HelloReply,
         ))
示例#3
0
 def __init__(self, channel):
     self._client = purerpc.Client("challenges.Challenge2", channel)
     self.create = self._client.get_method_stub(
         "create",
         purerpc.RPCSignature(
             purerpc.Cardinality.UNARY_UNARY,
             api_pb2.ChallengeRequest2,
             api_pb2.ChallengeResponse,
         ))
示例#4
0
async def test_purerpc_stream_client_parallel(greeter_pb2, channel):
    async def test_say_hello(client):
        stream = await client.rpc("SayHello", greeter_pb2.HelloRequest,
                                  greeter_pb2.HelloReply)
        await stream.send_message(greeter_pb2.HelloRequest(name="World"))
        await stream.close()
        assert (await stream.receive_message()).message == "Hello, World"
        assert await stream.receive_message() is None

    async def test_say_hello_goodbye(client):
        stream = await client.rpc("SayHelloGoodbye", greeter_pb2.HelloRequest,
                                  greeter_pb2.HelloReply)
        await stream.send_message(greeter_pb2.HelloRequest(name="World"))
        await stream.close()
        assert (await stream.receive_message()).message == "Hello, World"
        assert (await stream.receive_message()).message == "Goodbye, World"
        assert await stream.receive_message() is None

    async def test_say_hello_to_many(client):
        stream = await client.rpc("SayHelloToMany", greeter_pb2.HelloRequest,
                                  greeter_pb2.HelloReply)
        await stream.send_message(greeter_pb2.HelloRequest(name="Foo"))
        assert (await stream.receive_message()).message == "Hello, Foo"
        await stream.send_message(greeter_pb2.HelloRequest(name="Bar"))
        assert (await stream.receive_message()).message == "Hello, Bar"
        await stream.send_message(greeter_pb2.HelloRequest(name="Baz"))
        await stream.send_message(greeter_pb2.HelloRequest(name="World"))
        assert (await stream.receive_message()).message == "Hello, Baz"
        assert (await stream.receive_message()).message == "Hello, World"
        await stream.close()
        assert await stream.receive_message() is None

    async def test_say_hello_to_many_at_once(client):
        stream = await client.rpc("SayHelloToManyAtOnce",
                                  greeter_pb2.HelloRequest,
                                  greeter_pb2.HelloReply)
        await stream.send_message(greeter_pb2.HelloRequest(name="Foo"))
        await stream.send_message(greeter_pb2.HelloRequest(name="Bar"))
        await stream.send_message(greeter_pb2.HelloRequest(name="Baz"))
        await stream.send_message(greeter_pb2.HelloRequest(name="World"))
        await stream.close()
        assert (
            await
            stream.receive_message()).message == "Hello, Foo, Bar, Baz, World"
        assert await stream.receive_message() is None

    client = purerpc.Client("Greeter", channel)
    await test_say_hello(client)
    await test_say_hello_goodbye(client)
    await test_say_hello_to_many(client)
    await test_say_hello_to_many_at_once(client)
示例#5
0
 def __init__(self, channel):
     self._client = purerpc.Client("challenges.Challenge", channel)
     self.create = self._client.get_method_stub(
         "create",
         purerpc.RPCSignature(
             purerpc.Cardinality.UNARY_UNARY,
             api_pb2.ChallengeRequest,
             api_pb2.ChallengeResponse,
         ))
     self.bulk_create = self._client.get_method_stub(
         "bulk_create",
         purerpc.RPCSignature(
             purerpc.Cardinality.STREAM_STREAM,
             api_pb2.ChallengeRequest,
             api_pb2.ChallengeResponse,
         ))
     self.list = self._client.get_method_stub(
         "list",
         purerpc.RPCSignature(
             purerpc.Cardinality.UNARY_STREAM,
             google.protobuf.empty_pb2.Empty,
             api_pb2.ChallengeResponse,
         ))