コード例 #1
0
        private async Task BroadcastTransactionToBackendAsync(SmartTransaction transaction)
        {
            Logger.LogInfo("Broadcasting with backend...");
            using (TorHttpClient torHttpClient = Synchronizer.HttpClientFactory.NewBackendTorHttpClient(isolateStream: true))
            {
                var client = new WasabiClient(torHttpClient);

                try
                {
                    await client.BroadcastAsync(transaction).ConfigureAwait(false);
                }
                catch (HttpRequestException ex2) when(RpcErrorTools.IsSpentError(ex2.Message))
                {
                    if (transaction.Transaction.Inputs.Count == 1)                     // If we tried to only spend one coin, then we can mark it as spent. If there were more coins, then we do not know.
                    {
                        OutPoint input = transaction.Transaction.Inputs.First().PrevOut;
                        foreach (var coin in WalletManager.CoinsByOutPoint(input))
                        {
                            coin.SpentAccordingToBackend = true;
                        }
                    }

                    throw;
                }
            }

            BelieveTransaction(transaction);

            Logger.LogInfo($"Transaction is successfully broadcasted to backend: {transaction.GetHash()}.");
        }
コード例 #2
0
        private async Task BroadcastTransactionToBackendAsync(SmartTransaction transaction)
        {
            Logger.LogInfo("Broadcasting with backend...");
            using (var client = new WasabiClient(Synchronizer.WasabiClient.TorClient.DestinationUriAction, Synchronizer.WasabiClient.TorClient.TorSocks5EndPoint))
            {
                try
                {
                    await client.BroadcastAsync(transaction).ConfigureAwait(false);
                }
                catch (HttpRequestException ex2) when(ex2.Message.Contains("bad-txns-inputs-missingorspent", StringComparison.InvariantCultureIgnoreCase) ||
                                                      ex2.Message.Contains("missing-inputs", StringComparison.InvariantCultureIgnoreCase) ||
                                                      ex2.Message.Contains("txn-mempool-conflict", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (transaction.Transaction.Inputs.Count == 1)                     // If we tried to only spend one coin, then we can mark it as spent. If there were more coins, then we do not know.
                    {
                        OutPoint input = transaction.Transaction.Inputs.First().PrevOut;
                        lock (WalletServicesLock)
                        {
                            foreach (var walletService in AliveWalletServices)
                            {
                                SmartCoin coin = walletService.Coins.GetByOutPoint(input);
                                if (coin != default)
                                {
                                    coin.SpentAccordingToBackend = true;
                                }
                            }
                        }
                    }
                }
            }

            BelieveTransaction(transaction);

            Logger.LogInfo($"Transaction is successfully broadcasted to backend: {transaction.GetHash()}.");
        }