public async Task <IBlockchainTransaction> GetTransactionAsync( string txId, CancellationToken cancellationToken = default(CancellationToken)) { Info.Blockchain.API.Models.Transaction tx; try { tx = await _explorer .GetTransactionByHashAsync(txId) .ConfigureAwait(false); } catch (ServerApiException e) { Log.Warning("Server api exception while get transaction by id {@txId}: {@message}", txId, ResolveExceptionMessage(e)); return(null); } return(new BitcoinBasedTransaction( currency: _currency, tx: Transaction.Parse(await GetTxHexAsync(txId).ConfigureAwait(false), _currency.Network), blockInfo: new BlockInfo { Fees = await GetTxFeeAsync(txId).ConfigureAwait(false), Confirmations = (int)(await GetBlockCountAsync().ConfigureAwait(false) - tx.BlockHeight + 1), BlockHeight = tx.BlockHeight, FirstSeen = tx.Time, BlockTime = tx.Time })); }
public MainWindow() { InitializeComponent(); if (walletPasswordCancel) { Model = null; Backup_Wallet.Visibility = Visibility.Collapsed; Delete.Visibility = Visibility.Collapsed; Tools.Visibility = Visibility.Collapsed; Wallet.Visibility = Visibility.Collapsed; } else { if (Model != null) { MainFrame.NavigationService.Navigate(new overview(Model)); explorer = new BlockExplorer(); new Thread(() => { Thread.CurrentThread.IsBackground = true; if (CheckForInternetConnection()) { walletData.Serialize(Model.Wallet); Model.Update(); } while (true) { if (CheckForInternetConnection()) { var Addresses = explorer.GetMultiAddressAsync(Model.Addresses).Result.Addresses; var TxsCount = Model.TxRecords == null ? 0 : Model.TxRecords.Count; if (explorer.GetMultiAddressAsync(Model.Addresses).Result.Transactions.Count() > TxsCount) { walletData.Serialize(Model.Wallet); Model.Update(); } foreach (var tx in Model.TxRecords) { if (tx.lockTime < 0) { var txAsync = explorer.GetTransactionByHashAsync(tx.hash).Result; if (txAsync.BlockHeight > 0) { var data = JsonConvert.DeserializeObject <Data>( File.ReadAllText(walletFileSerializer .Deserialize(Model.Wallet.WalletFilePath).walletTransactionsPath)); data.txData[tx.hash].lockTime = txAsync.BlockHeight; File.WriteAllText( walletFileSerializer.Deserialize(Model.Wallet.WalletFilePath) .walletTransactionsPath, JsonConvert.SerializeObject(data)); Model.Update(); } } } using (var client = new HttpClient()) { const string url = @"https://api.blockcypher.com/v1/btc/main"; var result = client.GetAsync(url, HttpCompletionOption.ResponseContentRead).Result; var asyncData = new FileInfo(Model.Wallet.WalletFilePath).Directory.FullName + Path.DirectorySeparatorChar + "asyncData.json"; if (result.IsSuccessStatusCode) { File.WriteAllText(asyncData, result.Content.ReadAsStringAsync().Result); } Model.Update(); } } Thread.Sleep(15000); } }).Start(); } else { var defaultWallet = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + Path.DirectorySeparatorChar + "ArGo" + Path.DirectorySeparatorChar + "default_wallet.json"; if (File.Exists(defaultWallet)) { var walletPasswordWindow = new walletPasswordWindow(defaultWallet); walletPasswordWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; walletPasswordWindow.Show(); Close(); } else { var walletWizard = new walletWizard(); walletWizard.WindowStartupLocation = WindowStartupLocation.CenterScreen; walletWizard.Show(); Close(); } } } }