Esempio n. 1
0
 public void Dispose()
 {
     listener?.Shutdown();
     listener?.Dispose();
     listener = null;
     awaitedTransactions?.Dispose();
     awaitedTransactions = null;
 }
Esempio n. 2
0
        public async Task ListenPaymentsTest()
        {
            var result = (payment : false, deposit : false);

            using (var stellarServer = new Server(StellarNodeUri))
            {
                KeyPair account1 = KeyPair.FromSecretSeed(Account1SecretSeed);
                KeyPair account2 = KeyPair.FromSecretSeed(Account2SecretSeed);

                var tcs = new TaskCompletionSource <(bool payment, bool deposit)>();

                IEventSource eventSource = stellarServer
                                           .Payments
                                           .ForAccount(account2)
                                           .Cursor("now")
                                           .Stream((sender, operation) =>
                {
                    if (operation is PaymentOperationResponse payment)
                    {
                        if (payment.To.Address == account2.Address)
                        {
                            result.deposit = true;
                        }
                        else if (payment.From.Address == account2.Address)
                        {
                            result.payment = true;
                        }

                        if (result.payment && result.deposit)
                        {
                            tcs.SetResult(result);
                        }
                    }
                });

                eventSource.Connect();

                await SendPayment(account1, account2, 1, stellarServer);
                await SendPayment(account2, account1, 1, stellarServer);

                await Task.WhenAny(tcs.Task, Task.Delay(10000));

                eventSource.Dispose();
            }

            Assert.IsTrue(result.payment);
            Assert.IsTrue(result.deposit);
        }