diff --git a/src/Features/Blockcore.Features.NodeHost/UI/Pages/Index.razor b/src/Features/Blockcore.Features.NodeHost/UI/Pages/Index.razor index 1cecf1d5c..e04cf68ab 100644 --- a/src/Features/Blockcore.Features.NodeHost/UI/Pages/Index.razor +++ b/src/Features/Blockcore.Features.NodeHost/UI/Pages/Index.razor @@ -1,9 +1,15 @@ @page "/" +@implements IDisposable + @using Blockcore.Utilities.Extensions @using Blockcore.Networks @using Blockcore.UI.BlazorModal @using Blockcore.Consensus.Chain +@using Blockcore.EventBus +@using Blockcore.EventBus.CoreEvents +@using Blockcore.EventBus.CoreEvents.Peer +@using Blockcore.Signals @inject IFullNode FullNode @inject Network Network @@ -12,142 +18,145 @@ @inject Blockcore.Interfaces.IInitialBlockDownloadState InitialBlockDownloadState @inject NavigationManager NavigationManager @inject ModalService ModalService +@inject ISignals Signals @{ -
-

@this.Network.CoinTicker.ToUpper() Network

-
- - - +
+

@this.Network.CoinTicker.ToUpper() Network

+
+ + + +
-
-
-
-
-
-
-
-
-

@this.Network.CoinTicker.ToUpper()

-

+
+
+
+
+
+
+
+

@this.Network.CoinTicker.ToUpper()

+

+
-
-
-
- +
+
+ +
+
Network
-
Network
-
-
-
-
-
-
-
-

@this.ConnectionManager.ConnectedPeers.Count()

-

+
+
+
+
+
+
+

@this.ConnectionManager.ConnectedPeers.Count()

+

+
-
-
-
- +
+
+ +
+
Peers
-
Peers
-
-
-
-
-
-
-
- @if (this.InitialBlockDownloadState.IsInitialBlockDownload()) - { - - } - else - { - - } -

+
+
+
+
+
+
+ @if (this.InitialBlockDownloadState.IsInitialBlockDownload()) + { + + } + else + { + + } +

+
-
-
-
- +
+
+ +
-
- @if (this.InitialBlockDownloadState.IsInitialBlockDownload()) + @if (this.InitialBlockDownloadState.IsInitialBlockDownload()) + { +
Chain Syncing
+ } + else { -
Chain Syncing
- } else {
Chain Synced
} +
-
-
-
-
-
-
-
-

@this.ChainIndexer.Tip.Height

-

+
+
+
+
+
+
+

@this.ChainIndexer.Tip.Height

+

+
-
-
-
- +
+
+ +
+
Block Height
-
Block Height
-
-
-
-
-
-

Peers

-
- - - - - - - - - - - @foreach (var peer in this.ConnectionManager.ConnectedPeers) - { +
+
+
+
+

Peers

+
+
IP ADDRESSCONNECTIONAGENTVERSION
+ - - - - + + + + - } - -
@peer.RemoteSocketEndpoint.ToString()@(peer.Inbound ? "Inbound" : "Outbound") @peer.PeerVersion?.UserAgent@peer.PeerVersion?.VersionIP ADDRESSCONNECTIONAGENTVERSION
+ + + @foreach (var peer in this.ConnectionManager.ConnectedPeers) + { + + @peer.RemoteSocketEndpoint.ToString() + @(peer.Inbound ? "Inbound" : "Outbound") + @peer.PeerVersion?.UserAgent + @peer.PeerVersion?.Version + + } + + +
-
} @code { @@ -163,4 +172,42 @@ { ModalService.Show("Add Node", typeof(Modal.ModalAddNode)); } + + List subscriptionTokens; + + protected override void OnAfterRender(bool firstRender) + { + if (firstRender && this.Signals != null) + { + this.subscriptionTokens = new List() + { + this.Signals.Subscribe(this.ReloadEvent), + this.Signals.Subscribe(this.ReloadEvent), + this.Signals.Subscribe(this.ReloadEvent) + }; + } + } + + DateTime lastRefresh = DateTime.UtcNow; + + private void ReloadEvent(object _) + { + if ((DateTime.UtcNow - lastRefresh).Seconds > 3) + { + lastRefresh = DateTime.UtcNow; + + InvokeAsync(this.StateHasChanged); + } + } + + public void Dispose() + { + if (subscriptionTokens != null) + { + foreach (var subscriptionToken in subscriptionTokens) + { + subscriptionToken.Dispose(); + } + } + } } \ No newline at end of file diff --git a/src/Features/Blockcore.Features.Wallet/Events/TransactionSpent.cs b/src/Features/Blockcore.Features.Wallet/Events/TransactionSpent.cs new file mode 100644 index 000000000..e95a34c49 --- /dev/null +++ b/src/Features/Blockcore.Features.Wallet/Events/TransactionSpent.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Blockcore.Consensus.TransactionInfo; +using Blockcore.EventBus; +using NBitcoin; + +namespace Blockcore.Features.Wallet.Events +{ + /// + /// Event that is executed when a transactions output is spent in the wallet. + /// + /// + public class TransactionSpent : EventBase + { + public Transaction SpentTransaction { get; } + + public OutPoint SpentOutPoint { get; } + + public TransactionSpent(Transaction spentTransaction, OutPoint spentOutPoint) + { + this.SpentTransaction = spentTransaction; + this.SpentOutPoint = spentOutPoint; + } + } +} \ No newline at end of file diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletView.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletView.razor index 4f1f1080b..272dbc228 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletView.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/WalletView.razor @@ -1,16 +1,21 @@ @page "/walletview/{walletname}/{accountname}" +@implements IDisposable @using Blockcore.Features.Wallet.Interfaces @using NBitcoin; @using Blockcore.Features.Wallet.Api.Controllers @using Blockcore.Features.Wallet.Api.Models +@using Blockcore.Features.Wallet.Events @using Blockcore.Networks +@using Blockcore.Signals @using Blockcore.UI.BlazorModal +@using Blockcore.EventBus @inject NavigationManager NavigationManager @inject IWalletManager WalletManager @inject Network Network @inject ModalService ModalService +@inject ISignals Signals @{ var accountBalance = this.WalletManager.GetBalances(walletname, accountname).Single(); @@ -127,4 +132,41 @@ Console.WriteLine(selection); NavigateToWallet(selection, "account 0"); } + + List subscriptionTokens; + + protected override void OnAfterRender(bool firstRender) + { + if (firstRender && this.Signals != null) + { + this.subscriptionTokens = new List() + { + this.Signals.Subscribe(this.ReloadEvent), + this.Signals.Subscribe(this.ReloadEvent), + }; + } + } + + DateTime lastRefresh = DateTime.UtcNow; + + private void ReloadEvent(object _) + { + if ((DateTime.UtcNow - lastRefresh).Seconds > 1) + { + lastRefresh = DateTime.UtcNow; + + InvokeAsync(this.StateHasChanged); + } + } + + public void Dispose() + { + if (subscriptionTokens != null) + { + foreach (var subscriptionToken in subscriptionTokens) + { + subscriptionToken.Dispose(); + } + } + } } \ No newline at end of file diff --git a/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor b/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor index 9d57d27ad..d31de4bfd 100644 --- a/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor +++ b/src/Features/Blockcore.Features.Wallet/UI/Pages/Wallets.razor @@ -1,4 +1,5 @@ @page "/wallets" +@implements IDisposable @using Blockcore.Features.Wallet.Interfaces @using Blockcore.Interfaces @@ -6,6 +7,11 @@ @using Blockcore.UI.BlazorModal @using NBitcoin; @using Blockcore.Consensus.Chain +@using Blockcore.EventBus +@using Blockcore.EventBus.CoreEvents +@using Blockcore.EventBus.CoreEvents.Peer +@using Blockcore.Features.Wallet.Events +@using Blockcore.Signals @inject IWalletManager WalletManager @inject NavigationManager NavigationManager @@ -16,6 +22,7 @@ @inject IPooledTransaction PooledTransaction @inject Blockcore.Interfaces.IInitialBlockDownloadState InitialBlockDownloadState @inject ModalService ModalService +@inject ISignals Signals @{ @if (!this.WalletManager.ContainsWallets) @@ -271,4 +278,42 @@ { ModalService.Show("Create your Wallet", typeof(Modal.ModalWalletCreate)); } + + List subscriptionTokens; + + protected override void OnAfterRender(bool firstRender) + { + if (firstRender && this.Signals != null) + { + this.subscriptionTokens = new List() +{ + this.Signals.Subscribe(this.ReloadEvent), + this.Signals.Subscribe(this.ReloadEvent), + }; + } + } + + DateTime lastRefresh = DateTime.UtcNow; + + private void ReloadEvent(object _) + { + if ((DateTime.UtcNow - lastRefresh).Seconds > 1) + { + lastRefresh = DateTime.UtcNow; + + InvokeAsync(this.StateHasChanged); + } + } + + public void Dispose() + { + if (subscriptionTokens != null) + { + foreach (var subscriptionToken in subscriptionTokens) + { + subscriptionToken.Dispose(); + } + } + } + } \ No newline at end of file diff --git a/src/Features/Blockcore.Features.Wallet/WalletManager.cs b/src/Features/Blockcore.Features.Wallet/WalletManager.cs index dceff9c3b..4444fe607 100644 --- a/src/Features/Blockcore.Features.Wallet/WalletManager.cs +++ b/src/Features/Blockcore.Features.Wallet/WalletManager.cs @@ -139,7 +139,7 @@ public WalletManager( IScriptAddressReader scriptAddressReader, ISignals signals = null, IBroadcasterManager broadcasterManager = null, // no need to know about transactions the node will broadcast to. - IUtxoIndexer utxoIndexer = null) + IUtxoIndexer utxoIndexer = null) { Guard.NotNull(loggerFactory, nameof(loggerFactory)); Guard.NotNull(network, nameof(network)); @@ -1205,10 +1205,7 @@ public virtual bool ProcessTransaction(Transaction transaction, int? blockHeight foundReceivingTrx = true; this.logger.LogDebug("Transaction '{0}' contained funds received by the user's wallet(s).", hash); - if (this.signals != null) - { - this.signals.Publish(new Events.TransactionFound(transaction)); - } + this.signals?.Publish(new Events.TransactionFound(transaction)); } } } @@ -1226,6 +1223,8 @@ public virtual bool ProcessTransaction(Transaction transaction, int? blockHeight this.AddSpendingTransactionToWallet(walletIndexItem.Value.Wallet, transaction, input.PrevOut, walletIndexItem.Value.Wallet, blockHeight, block); foundSendingTrx = true; this.logger.LogDebug("Transaction '{0}' contained funds sent by the user's wallet(s).", hash); + + this.signals?.Publish(new Events.TransactionSpent(transaction, input.PrevOut)); } } } @@ -2149,7 +2148,7 @@ public IEnumerable Sweep(IEnumerable privateKeys, string destAdd total += txOut.Value; if (total == 0) - { + { continue; } @@ -2199,7 +2198,7 @@ public void PrepareTransaction(string destAddress, ref TransactionBuilder builde TransactionPolicyError[] errors = builder.Check(sweepTransaction); if (errors.Length == 0) - { + { sweepTransactions.Add(sweepTransaction.ToHex()); } else @@ -2208,11 +2207,11 @@ public void PrepareTransaction(string destAddress, ref TransactionBuilder builde foreach (var error in errors) { sweepTransactions.Add(error.ToString()); - } + } } // Reset the builder and related state, as we are now creating a fresh transaction. builder = new TransactionBuilder(this.network); } } -} +} \ No newline at end of file