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()}."); }
private async Task BroadcastTransactionToBackendAsync(SmartTransaction transaction) { Logger.LogInfo("Broadcasting with backend..."); IHttpClient httpClient = HttpClientFactory.NewHttpClientWithCircuitPerRequest(); WasabiClient client = new(httpClient); 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; } } // Exception message is in form: 'message:::tx1:::tx2:::etc.' where txs are encoded in HEX. IEnumerable <SmartTransaction> txs = ex2.Message.Split(":::", StringSplitOptions.RemoveEmptyEntries) .Skip(1) // Skip the exception message. .Select(x => new SmartTransaction(Transaction.Parse(x, Network), Height.Mempool)); foreach (var tx in txs) { WalletManager.Process(tx); } throw; } BelieveTransaction(transaction); Logger.LogInfo($"Transaction is successfully broadcasted to backend: {transaction.GetHash()}."); }