Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

IExternalProcessHelper created to abstract the static call Process.Start #47

Merged
merged 29 commits into from
Nov 19, 2017
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bdf0079
Remove AssetViewModel dependency from HomeViewModel
aboimpinto Nov 8, 2017
cb23038
when removing the AssetViewModel dependency from HomeView, one bindin…
aboimpinto Nov 8, 2017
7aed22c
Remove TransactionsViewModel dependency from HomeViewModel
aboimpinto Nov 8, 2017
2ee0045
First draft of the BlockChainController
Nov 8, 2017
fc1e4da
WalletController created
aboimpinto Nov 10, 2017
d3ae9f1
CreateWallet in WalletController implemented from code in HomeViewModel
Nov 11, 2017
d7505bd
* WalletController: OpenWallet code copy
Nov 12, 2017
77782b9
Merge branch 'master' into master
justingaffney Nov 13, 2017
0f3f889
Decoupled some views from their respective view model classes using m…
justingaffney Nov 14, 2017
c02bdea
Merge pull request #32 from jlgaffney/master
justingaffney Nov 14, 2017
ef4e948
Replace Application.Instance calls with ApplicationContext that was i…
Nov 14, 2017
2c237ab
Merge branch 'master' of https://github.com/aboimpinto/neo-gui-wpf
Nov 14, 2017
ebd99f4
Remove from solution already removed messages classes
aboimpinto Nov 15, 2017
c92fd18
Cleanup in AccountViewModel don't access the ApplicationContext using…
aboimpinto Nov 15, 2017
b413488
Merge branch 'dev' into master
aboimpinto Nov 15, 2017
df26fb7
Remove singleton ApplicationContext from HomeViewModel and inject it …
aboimpinto Nov 15, 2017
02eaeb8
merge from master upstream
aboimpinto Nov 15, 2017
078c347
Remove extra-code added by mistake during the merge
aboimpinto Nov 15, 2017
d9ccd10
This object is declared as Singleton, therefore the lock in not neces…
aboimpinto Nov 15, 2017
05bea27
WalletController is been injected in the BlockChainController instead…
aboimpinto Nov 15, 2017
45931c7
The access to the singleton Application.Instance is not removed from …
aboimpinto Nov 15, 2017
78475ce
First atempt to wire the BlockChainController in the app.
Nov 16, 2017
9a1364e
* Added some technical debts issues
aboimpinto Nov 16, 2017
c1c1ad6
All the code related with wallet access goes not throuh WalletControl…
aboimpinto Nov 16, 2017
3ff0741
Set application context in view in constructor
justingaffney Nov 17, 2017
8a6e1ee
ExternalProcessHelper was create to wrapper the calls Process.Start t…
aboimpinto Nov 17, 2017
5199f0d
merge dev
Nov 18, 2017
9ab9ee5
merge with dev
Nov 18, 2017
5f08f97
Basic implementation of IDialogHelper and usage to in HomeViewModel t…
Nov 18, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions neo-gui/App.config
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Neo.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Neo.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
</startup>
<userSettings>
<Neo.Properties.Settings>
<setting name="NeedUpgrade" serializeAs="String">
<value>True</value>
</setting>
<setting name="LastWalletPath" serializeAs="String">
<value />
<value/>
</setting>
<setting name="InstallCertificate" serializeAs="String">
<value>True</value>
</setting>
<setting name="NEP5Watched" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
</value>
</setting>
<setting name="AppTheme" serializeAs="String">
<value />
<value/>
</setting>
</Neo.Properties.Settings>
</userSettings>
Expand Down
6 changes: 5 additions & 1 deletion neo-gui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ internal App(bool updateIsRequired = false)

BuildContainer();

this.MainWindow = updateIsRequired ? (Window) new UpdateView() : new HomeView();
var blockChainController = ApplicationContext.Instance.ContainerLifetimeScope.Resolve(typeof(IBlockChainController)) as IBlockChainController;
blockChainController.StartLocalNode();

this.MainWindow = updateIsRequired ? (Window)new UpdateView() : new HomeView();
}

protected override void OnStartup(StartupEventArgs e)
Expand All @@ -37,6 +40,7 @@ private static void BuildContainer()
{
var autoFacContainerBuilder = new ContainerBuilder();

autoFacContainerBuilder.RegisterModule<NeoGuiRegistrationModule>();
autoFacContainerBuilder.RegisterModule<ViewModelsRegistrationModule>();
autoFacContainerBuilder.RegisterModule<BaseRegistrationModule>();
autoFacContainerBuilder.RegisterModule<ControllersRegistrationModule>();
Expand Down
6 changes: 0 additions & 6 deletions neo-gui/ApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ public class ApplicationContext : IApplicationContext
#region Singleton Pattern
private static readonly Lazy<ApplicationContext> lazyInstance = new Lazy<ApplicationContext>(() => new ApplicationContext());

// Prevent other classes from calling constructor
private ApplicationContext()
{
}

public static ApplicationContext Instance => lazyInstance.Value;

#endregion

public ILifetimeScope ContainerLifetimeScope { get; set; }
Expand Down
14 changes: 14 additions & 0 deletions neo-gui/Controllers/AccountItemExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using Neo.UI;

namespace Neo.Controllers
{
public static class AccountItemExtensionMethods
{
public static AccountItem GetAccountItemForAddress(this IEnumerable<AccountItem> accountItems, string address)
{
return accountItems.FirstOrDefault(x => x.Address.Equals(address));
}
}
}
87 changes: 48 additions & 39 deletions neo-gui/Controllers/BlockChainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Neo.Implementations.Blockchains.LevelDB;
using Neo.Implementations.Wallets.EntityFramework;
using Neo.IO;
using Neo.Network;
using Neo.Properties;
using Neo.SmartContract;
using Neo.UI;
Expand All @@ -22,11 +23,13 @@ namespace Neo.Controllers
public class BlockChainController : IBlockChainController
{
#region Private Fields
private readonly object uiUpdateTimerLock = new object();
private readonly IWalletController walletController;
private readonly IApplicationContext applicationContext;
private readonly IMessagePublisher messagePublisher;
private readonly IDispatcher dispatcher;

private LocalNode localNode;

private DateTime persistenceTime = DateTime.MinValue;
private Timer uiUpdateTimer;
private bool balanceChanged;
Expand All @@ -35,51 +38,52 @@ public class BlockChainController : IBlockChainController

#region Constructor
public BlockChainController(
IWalletController walletController,
IApplicationContext applicationContext,
IMessagePublisher messagePublisher,
IDispatcher dispatcher)
{
this.walletController = walletController;
this.applicationContext = applicationContext;
this.messagePublisher = messagePublisher;
this.dispatcher = dispatcher;
}
#endregion

#region IBlockChainController implementation
public void StartLocalNode()
{
this.localNode = new LocalNode
{
UpnpEnabled = true
};
this.applicationContext.LocalNode = this.localNode;

Task.Run(() =>
{
CheckForNewerVersion();

ImportBlocksIfRequired();

Blockchain.PersistCompleted += Blockchain_PersistCompleted;
Blockchain.PersistCompleted += this.BlockchainPersistCompleted;

// Start node
this.applicationContext.LocalNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
this.localNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
});

lock (this.uiUpdateTimerLock)
this.uiUpdateTimer = new Timer
{
if (this.uiUpdateTimer != null)
{
// Stop previous timer
this.uiUpdateTimer.Stop();

this.uiUpdateTimer.Elapsed -= this.UpdateWallet;

this.uiUpdateTimer.Dispose();

this.uiUpdateTimer = null;
}
Interval = 500,
Enabled = true,
AutoReset = true
};

var timer = new Timer
{
Interval = 500,
Enabled = true,
AutoReset = true
};

timer.Elapsed += this.UpdateWallet;
this.uiUpdateTimer.Elapsed += this.UpdateWallet;
}

this.uiUpdateTimer = timer;
}
public void Relay(Transaction transaction)
{
this.localNode.Relay(transaction);
}
#endregion

Expand All @@ -89,7 +93,6 @@ private void UpdateWallet(object sender, ElapsedEventArgs e)
var persistenceSpan = DateTime.UtcNow - this.persistenceTime;

this.UpdateBlockProgress(persistenceSpan);

this.UpdateBalances(persistenceSpan);
}

Expand All @@ -98,7 +101,10 @@ private void UpdateBlockProgress(TimeSpan persistenceSpan)
var blockProgressIndeterminate = false;
var blockProgress = 0;

if (persistenceSpan < TimeSpan.Zero) persistenceSpan = TimeSpan.Zero;
if (persistenceSpan < TimeSpan.Zero)
{
persistenceSpan = TimeSpan.Zero;
}

if (persistenceSpan > Blockchain.TimePerBlock)
{
Expand All @@ -111,7 +117,7 @@ private void UpdateBlockProgress(TimeSpan persistenceSpan)
}

var blockHeight = $"{GetWalletHeight()}/{Blockchain.Default.Height}/{Blockchain.Default.HeaderHeight}";
var nodeCount = this.applicationContext.LocalNode.RemoteNodeCount;
var nodeCount = this.localNode.RemoteNodeCount;
var blockStatus = $"{Strings.WaitingForNextBlock}:";

var blockProgressMessage = new BlockProgressMessage(
Expand All @@ -125,7 +131,7 @@ private void UpdateBlockProgress(TimeSpan persistenceSpan)

private void UpdateBalances(TimeSpan persistenceSpan)
{
if (ApplicationContext.Instance.CurrentWallet == null) return;
if (!this.walletController.IsWalletOpen) return;

this.UpdateAssetBalances();

Expand All @@ -134,9 +140,9 @@ private void UpdateBalances(TimeSpan persistenceSpan)

private void UpdateAssetBalances()
{
if (ApplicationContext.Instance.CurrentWallet.WalletHeight > Blockchain.Default.Height + 1) return;
if (this.walletController.WalletWeight > Blockchain.Default.Height + 1) return;

this.messagePublisher.Publish(new UpdateAcountListMessage());
this.messagePublisher.Publish(new AccountBalancesChangedMessage());
this.messagePublisher.Publish(new UpdateAssetsBalanceMessage(this.balanceChanged));
}

Expand All @@ -147,7 +153,8 @@ private async void UpdateNEP5TokenBalances(TimeSpan persistenceSpan)
if (persistenceSpan <= TimeSpan.FromSeconds(2)) return;

// Update balances
var addresses = ApplicationContext.Instance.CurrentWallet.GetAddresses().ToArray();
var addresses = this.walletController.GetAddresses();

foreach (var s in Settings.Default.NEP5Watched)
{
var scriptHash = UInt160.Parse(s);
Expand Down Expand Up @@ -203,11 +210,11 @@ private uint GetWalletHeight()
{
uint walletHeight = 0;

if (this.applicationContext.CurrentWallet != null &&
this.applicationContext.CurrentWallet.WalletHeight > 0)
if (this.walletController.IsWalletOpen &&
this.walletController.WalletWeight > 0)
{
// Set wallet height
walletHeight = this.applicationContext.CurrentWallet.WalletHeight - 1;
walletHeight = this.walletController.WalletWeight - 1;
}

return walletHeight;
Expand Down Expand Up @@ -270,15 +277,17 @@ private void ImportBlocks(Stream stream)
blockchain.VerifyBlocks = true;
}

private void Blockchain_PersistCompleted(object sender, Block block)
private void BlockchainPersistCompleted(object sender, Block block)
{
this.persistenceTime = DateTime.UtcNow;
if (ApplicationContext.Instance.CurrentWallet != null)
if (this.walletController.IsWalletOpen)
{
this.checkNep5Balance = true;

var coins = ApplicationContext.Instance.CurrentWallet.GetCoins();
if (coins.Any(coin => !coin.State.HasFlag(CoinState.Spent) &&
var coins = this.walletController.GetCoins();

if (coins.Any(
coin => !coin.State.HasFlag(CoinState.Spent) &&
coin.Output.AssetId.Equals(Blockchain.GoverningToken.Hash)))
{
balanceChanged = true;
Expand Down
5 changes: 5 additions & 0 deletions neo-gui/Controllers/ControllersRegistrationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ protected override void Load(ContainerBuilder builder)
.As<IBlockChainController>()
.SingleInstance();

builder
.RegisterType<WalletController>()
.As<IWalletController>()
.SingleInstance();

base.Load(builder);
}
}
Expand Down
9 changes: 4 additions & 5 deletions neo-gui/Controllers/IBlockChainController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Neo.Core;

namespace Neo.Controllers
{
public interface IBlockChainController
{
void StartLocalNode();

void Relay(Transaction transaction);
}
}
35 changes: 33 additions & 2 deletions neo-gui/Controllers/IWalletController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,40 @@
namespace Neo.Controllers
using System.Collections.Generic;
using Neo.Core;
using Neo.SmartContract;
using Neo.Wallets;

namespace Neo.Controllers
{
public interface IWalletController
{
bool IsWalletOpen { get; }

uint WalletWeight { get; }

void CreateWallet(string walletPath, string password);

void OpenWallet(string walletPath, string password);
void OpenWallet(string walletPath, string password, bool repairMode);

void CloseWallet();

void RebuildWalletIndexes();

void SaveTransaction(Transaction transaction);

void Sign(ContractParametersContext context);

void CreateNewKey(); // TODO - Issue #43 [AboimPinto] - this method will create a new key or new NEO address? Please review the name.

IEnumerable<UInt160> GetAddresses();

IEnumerable<Coin> GetCoins();

VerificationContract GetContract(UInt160 scriptHash);

void ImportWatchOnlyAddress(string addressToImport);

KeyPair GetKeyByScriptHash(UInt160 scriptHash);

void DeleteAddress(UInt160 scriptHash);
}
}
Loading