private void RefreshNbBlocks() { var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet(); if (authenticatedWallet == null) { return; } var rpcClient = new RpcClient(authenticatedWallet.Network); rpcClient.GetBlockCount().ContinueWith((r) => { try { var nb = r.Result; Application.Current.Dispatcher.Invoke(() => { WalletPageStore.Instance().NbBlocks = nb; _viewModel.NbBlocks = nb; }); } catch (AggregateException ex) { } }); }
private void RefreshBlocks() { var authenticatedWallet = WalletStore.Instance().GetAuthenticatedWallet(); if (authenticatedWallet == null) { return; } var rpcClient = new RpcClient(authenticatedWallet.Network); var startIndex = 0; var lastIndex = WalletPageStore.Instance().NbBlocks; var waitBlockHashes = new List <Task <IEnumerable <byte> > >(); for (var i = startIndex; i < lastIndex; i++) { waitBlockHashes.Add(rpcClient.GetBlockHash(i)); } Task.WhenAll(waitBlockHashes.ToArray()).ContinueWith((r) => { var waitAllBlocks = new List <Task <Block> >(); try { var lstBHash = r.Result.ToList(); foreach (var bHash in lstBHash) { if (bHash == null) { continue; } waitAllBlocks.Add(rpcClient.GetBlock(bHash)); } } catch (AggregateException) { } Task.WhenAll(waitAllBlocks.ToArray()).ContinueWith((b) => { try { Application.Current.Dispatcher.Invoke(() => { _viewModel.Blocks.Clear(); }); var blocks = b.Result; foreach (var block in blocks) { if (block == null) { continue; } var blockHash = block.GetHashHeader().ToHexString(); var previousHash = block.BlockHeader.PreviousBlockHeader.ToHexString(); var nbTransactions = block.Transactions.Count(); var fees = block.GetTotalFees(); Application.Current.Dispatcher.Invoke(() => { _viewModel.Blocks.Add(new BlockViewModel { Fees = fees, Hash = blockHash, PreviousHash = previousHash }); }); } } catch (AggregateException) { } }); }); }