public override async Task DoProcess() { try { Console.WriteLine("Checking for new coinjoin transactions...."); var json = await _client.GetAddressTransactionsAsync(Constants.CoordinatorAddress); var jsonTransactions = json["address"]["transactions"]; foreach (var transaction in jsonTransactions) { var confirmations = transaction.Value <int>("confirmations"); if (confirmations == 0) { continue; } var txData = new TransactionMetadata { TransactionId = uint256.Parse(transaction.Value <string>("txid")), BlockNumber = transaction.Value <uint>("block"), FirstTimeSeen = Utils.UnixTimeToDateTime(transaction.Value <ulong>("first_seen")), Time = Utils.UnixTimeToDateTime(transaction.Value <ulong>("time")), Size = transaction.Value <uint>("size"), VirtualSize = transaction.Value <uint>("vsize") }; _processorChannel.Send(txData); } } catch (Exception) { // If fail it will retry await Task.Delay(TimeSpan.FromSeconds(30)); } }
private static async Task Main(string[] args) { var client = new SmartBitApiClient(); while (true) { JObject json = null; while (json == null) { try { json = await client.GetAddressTransactionsAsync(Constants.CoordinatorAddress); } catch (Exception) { await Task.Delay(2000); } } var jsonTransactions = json["address"]["transactions"]; foreach (var transaction in jsonTransactions) { var confirmations = transaction.Value <int>("confirmations"); if (confirmations == 0) { continue; } var txId = uint256.Parse(transaction.Value <string>("txid")); var blockNumber = transaction.Value <uint>("block"); var firstTimeSeen = Utils.UnixTimeToDateTime(transaction.Value <ulong>("first_seen")); var time = Utils.UnixTimeToDateTime(transaction.Value <ulong>("time")); var outputs = transaction["outputs"]; foreach (var output in outputs) { var address = output["addresses"].First(); if (address.ToString() != Constants.CoordinatorAddress.ToString()) { continue; } var index = output.Value <int>("n"); var value = output.Value <decimal>("value"); // Console.WriteLine($"{blockNumber}, {time}, {firstTimeSeen}, {txId}, {index}, {value}, {address}"); Console.WriteLine($"{firstTimeSeen}, {txId}, {index}, {value}"); } } } }