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

Commit

Permalink
Merge dev changes into the master branch (#95)
Browse files Browse the repository at this point in the history
* Abstract HomeViewModel from all the others viewModels (#33)

* Remove AssetViewModel dependency from HomeViewModel

* when removing the AssetViewModel dependency from HomeView, one binding was forgot

* Remove TransactionsViewModel dependency from HomeViewModel

* First draft of the BlockChainController

* WalletController created

* CreateWallet in WalletController implemented from code in HomeViewModel

* * WalletController: OpenWallet code copy
* DialogHelper created - Object that will abstract the creation and show dialogs.

* All dependencies on HomeViewModel are now injected in the constructor (#36)

* Remove AssetViewModel dependency from HomeViewModel

* when removing the AssetViewModel dependency from HomeView, one binding was forgot

* Remove TransactionsViewModel dependency from HomeViewModel

* First draft of the BlockChainController

* WalletController created

* CreateWallet in WalletController implemented from code in HomeViewModel

* * WalletController: OpenWallet code copy
* DialogHelper created - Object that will abstract the creation and show dialogs.

* Decoupled some views from their respective view model classes using messages

* Replace Application.Instance calls with ApplicationContext that was injected in the constructor

* Remove from solution already removed messages classes

* Cleanup in AccountViewModel don't access the ApplicationContext using the Singleton but the constructor injection object

* Remove singleton ApplicationContext from HomeViewModel and inject it in constructor.

* Remove extra-code added by mistake during the merge

* This object is declared as Singleton, therefore the lock in not necessary. This class will be created only once.

* WalletController is been injected in the BlockChainController instead to access through ApplicationContext

* The access to the singleton Application.Instance is not removed from all the ViewModels.
IApplicationContext has been injected in this classes.

* First atempt to wire the BlockChainController in the app.
Cannot connect to the peers

* * Added some technical debts issues
* Wallet and blockchain code removed from HomeViewModel
* ApplicationContext injection removed from HomeViewModel

* All the code related with wallet access goes not throuh WalletController in AccountsViewModel

* Set application context in view in constructor

* Bug fixes in dev branch (#49)

* Fixed wallet password changing, fixed restore accounts, fixed HomeView menu items not enabling when wallet is opened

* Added input binding to open the wallet in OpenWalletView when the enter key is pressed

* Removed IApplicationContext.CurrentWallet and replaced all uses with IWalletController methods (#50)

* Extracted blockchain setup logic from Program.cs and moved it to BlockChainController.cs (#51)

Also added a very basic splash screen, which needs a lot of work

* IExternalProcessHelper created to abstract the static call Process.Start, added basic IDialogHelper implementation (#47)

* Remove AssetViewModel dependency from HomeViewModel

* when removing the AssetViewModel dependency from HomeView, one binding was forgot

* Remove TransactionsViewModel dependency from HomeViewModel

* First draft of the BlockChainController

* WalletController created

* CreateWallet in WalletController implemented from code in HomeViewModel

* * WalletController: OpenWallet code copy
* DialogHelper created - Object that will abstract the creation and show dialogs.

* Decoupled some views from their respective view model classes using messages

* Replace Application.Instance calls with ApplicationContext that was injected in the constructor

* Remove from solution already removed messages classes

* Cleanup in AccountViewModel don't access the ApplicationContext using the Singleton but the constructor injection object

* Remove singleton ApplicationContext from HomeViewModel and inject it in constructor.

* Remove extra-code added by mistake during the merge

* This object is declared as Singleton, therefore the lock in not necessary. This class will be created only once.

* WalletController is been injected in the BlockChainController instead to access through ApplicationContext

* The access to the singleton Application.Instance is not removed from all the ViewModels.
IApplicationContext has been injected in this classes.

* First atempt to wire the BlockChainController in the app.
Cannot connect to the peers

* * Added some technical debts issues
* Wallet and blockchain code removed from HomeViewModel
* ApplicationContext injection removed from HomeViewModel

* All the code related with wallet access goes not throuh WalletController in AccountsViewModel

* Set application context in view in constructor

* ExternalProcessHelper was create to wrapper the calls Process.Start that start a external process to the application.

* Basic implementation of IDialogHelper and usage to in HomeViewModel to open OpenWalletView #44

* Splash screen improvements (#52)

* Small splash screen improvements

* Moved logo icon file to Resources directory, added logo to splash screen

* Localised ThemeStyle enum values, cleaned up TODO's, added themed border to splash screen (#53)

* Removed Program.cs (#54)

Replaced Program.Main method with an auto-generated Main method inside App

* Removed LocalNode property from IApplicationContext (#55)

Replaced references with IBlockChainController method calls

* NotificationHelper + Remove code from HomeViewModel to WalletController (#57)

* Remove AssetViewModel dependency from HomeViewModel

* when removing the AssetViewModel dependency from HomeView, one binding was forgot

* Remove TransactionsViewModel dependency from HomeViewModel

* First draft of the BlockChainController

* WalletController created

* CreateWallet in WalletController implemented from code in HomeViewModel

* * WalletController: OpenWallet code copy
* DialogHelper created - Object that will abstract the creation and show dialogs.

* Decoupled some views from their respective view model classes using messages

* Replace Application.Instance calls with ApplicationContext that was injected in the constructor

* Remove from solution already removed messages classes

* Cleanup in AccountViewModel don't access the ApplicationContext using the Singleton but the constructor injection object

* Remove singleton ApplicationContext from HomeViewModel and inject it in constructor.

* Remove extra-code added by mistake during the merge

* This object is declared as Singleton, therefore the lock in not necessary. This class will be created only once.

* WalletController is been injected in the BlockChainController instead to access through ApplicationContext

* The access to the singleton Application.Instance is not removed from all the ViewModels.
IApplicationContext has been injected in this classes.

* First atempt to wire the BlockChainController in the app.
Cannot connect to the peers

* * Added some technical debts issues
* Wallet and blockchain code removed from HomeViewModel
* ApplicationContext injection removed from HomeViewModel

* All the code related with wallet access goes not throuh WalletController in AccountsViewModel

* Set application context in view in constructor

* ExternalProcessHelper was create to wrapper the calls Process.Start that start a external process to the application.

* Basic implementation of IDialogHelper and usage to in HomeViewModel to open OpenWalletView #44

* * NotificationHelper created (using nuget from https://github.com/raflop/ToastNotifications)
* Move some code from HomeViewModel to WalletController that use the NotificationHelper to show how the action end

#39, #56

* When a Wallet is opened is need to check if need to upgrade. There are now methods that perfom that and they should be called in the Caller, in this case HomeViewModel.

* * Moving relevant code from BlockChainController to WalletController
* Remove unnecessary IDispatcher from BlockChainController
* Remove unnecessary IDialogHelper from WalletControler

All of this was to remove Circular Reference between BlockChainController and WalletController

* Removed singleton instance of ApplicationContext (#58)

* Merged changes from master branch (#59)

* Re-added BaseRegistrationModule.cs to project file

This compile tag was accidentally removed from the .csproj file

* Added Neo.Gui.Helper .NET standard project, fixed messaging in AccountsViewModel, AssetsViewModel and TransactionsViewModel (#60)

* Cleaned up wallet status updating code, added RemoteBlockChainController, small UI changes (#61)

* Refactored private WalletController method names to help clarify what they do

* Cleaned up wallet status updating code, added RemoteBlockChainController, small UI changes

* Added view model unit tests project (#62)

* Moved appropriate classes and interfaces to Neo.Gui.Base project (#63)

* Fixes for various problems

* Renamed Neo.Gui.Helpers project to Neo.Gui.Base, move some interfaces to Neo.Gui.Base, renamed neo-gui project to Neo.Gui.Wpf

* Updated name of Neo.Gui.Base directory

* Converted static VersionHelper class to an injectable class and added IVersionHelper interface to Neo.Gui.Base

* Fixed error with VersionHelper in App.xaml.cs

* Added newer version checking back

* Replaced IApplicationContext instance with static IoC container lifetime scope setter method in DialogHelper

* Deleted PeerState.cs and moved logic into LocalBlockChainController

* Moved a few classes to Neo.Gui.Base

* Moved sharable theming logic to Neo.Gui.Base

* Moved classes into Neo.Gui.Base project

* Changed directory structure for some classes

* Refactor namespaces (#64)

* Refactored namespaces in Neo.Gui.Base to reflect changes in directory structure

* Refactored namespaces in Neo.Gui.Wpf project

* Moved appropriate classes and interfaces to Neo.Gui.Base project (#65)

* Added Neo.Gui.ViewModels project, fixed resource paths

* Extracted System.Drawing.Color to System.Windows.Media.Color conversion to a separate extensions class

* Moved remaining messaging classes and interfaces to Neo.Gui.Base, moved all registration module classes to one directory

* Moved dialog result classes to Neo.Gui.Base, removed references to views from view model classes

* Removed all remaining direct references to Neo.Core.Blockchain class from view models and replaced with IBlockChainController calls

* Moved message classes to Neo.Gui.Base

* Modified namespaces of message classes to reflect new location

* Refactoring, UI changes (#66)

* Changed Blockchain.PersistCompleted event handler add and remove wrapper methods to an event

* Moved collection item class to Neo.Gui.Base project

* Refactoring and UI changes

* Moved localizable strings resource file to Neo.Gui.Base, added ColorToSolidColorBrushConverter (#67)

* Removed duplicate localizable string resource files

* Moved CertificateQueryService to base project (#68)

* Moved CertificateQueryService to base project, added BaseRegistrationModule

* Changed CertificateQueryService to internal

*  Removed most references to IBlockChainController from view model classes (#69)

* Removed most references to IBlockChainController from view model classes, removed Neo.Gui.Wpf references from IWalletController

* Moved WalletController to Neo.Gui.Base project

* Added MvvmLight library to Neo.Gui.Wpf project, replaced RelayCommand references with MvvmLight equivalent class (#70)

* Revert "Added MvvmLight library to Neo.Gui.Wpf project, replaced RelayCommand references with MvvmLight equivalent class (#70)"

This reverts commit 07c5150.

*  Removed all remaining references to IBlockChainController from view model classes (#71)

* Removed all remaining references to IBlockChainController from view models

* Added IMessageSubscriber.Unsubscribe() calls to view models that were subscribing to messages

* Refactored controller class namespaces

* Moved RemoteBlockChainController to base project, preparation for moving LocalBlockChainController to base project (#72)

* Moved root certificate installation from LocalBlockChainController to App

* Moved RemoteBlockChainController to base project

* Replaced view class references with IDialogHelper ShowDialog method calls (#73)

* Dispatch messages on UI Thread, abstracted view references from view models (#75)

* Remove AssetViewModel dependency from HomeViewModel

* when removing the AssetViewModel dependency from HomeView, one binding was forgot

* Remove TransactionsViewModel dependency from HomeViewModel

* First draft of the BlockChainController

* WalletController created

* CreateWallet in WalletController implemented from code in HomeViewModel

* * WalletController: OpenWallet code copy
* DialogHelper created - Object that will abstract the creation and show dialogs.

* Decoupled some views from their respective view model classes using messages

* Replace Application.Instance calls with ApplicationContext that was injected in the constructor

* Remove from solution already removed messages classes

* Cleanup in AccountViewModel don't access the ApplicationContext using the Singleton but the constructor injection object

* Remove singleton ApplicationContext from HomeViewModel and inject it in constructor.

* Remove extra-code added by mistake during the merge

* This object is declared as Singleton, therefore the lock in not necessary. This class will be created only once.

* WalletController is been injected in the BlockChainController instead to access through ApplicationContext

* The access to the singleton Application.Instance is not removed from all the ViewModels.
IApplicationContext has been injected in this classes.

* First atempt to wire the BlockChainController in the app.
Cannot connect to the peers

* * Added some technical debts issues
* Wallet and blockchain code removed from HomeViewModel
* ApplicationContext injection removed from HomeViewModel

* All the code related with wallet access goes not throuh WalletController in AccountsViewModel

* Set application context in view in constructor

* ExternalProcessHelper was create to wrapper the calls Process.Start that start a external process to the application.

* Basic implementation of IDialogHelper and usage to in HomeViewModel to open OpenWalletView #44

* * NotificationHelper created (using nuget from https://github.com/raflop/ToastNotifications)
* Move some code from HomeViewModel to WalletController that use the NotificationHelper to show how the action end

#39, #56

* When a Wallet is opened is need to check if need to upgrade. There are now methods that perfom that and they should be called in the Caller, in this case HomeViewModel.

* * Moving relevant code from BlockChainController to WalletController
* Remove unnecessary IDispatcher from BlockChainController
* Remove unnecessary IDialogHelper from WalletControler

All of this was to remove Circular Reference between BlockChainController and WalletController

* When a message is published should be Dispatched to UI thread.

* * DialogHelper receive parameters
* (..).ShowDialog calles were replaced by DialogHelper
* ICommand were replaced by RelayCommand
* Dialogs now can be closed using the CloseEvent in the DialogViewModel<T>

* Refactor HomeViewModel (#83)

* Remove AssetViewModel dependency from HomeViewModel

* when removing the AssetViewModel dependency from HomeView, one binding was forgot

* Remove TransactionsViewModel dependency from HomeViewModel

* First draft of the BlockChainController

* WalletController created

* CreateWallet in WalletController implemented from code in HomeViewModel

* * WalletController: OpenWallet code copy
* DialogHelper created - Object that will abstract the creation and show dialogs.

* Decoupled some views from their respective view model classes using messages

* Replace Application.Instance calls with ApplicationContext that was injected in the constructor

* Remove from solution already removed messages classes

* Cleanup in AccountViewModel don't access the ApplicationContext using the Singleton but the constructor injection object

* Remove singleton ApplicationContext from HomeViewModel and inject it in constructor.

* Remove extra-code added by mistake during the merge

* This object is declared as Singleton, therefore the lock in not necessary. This class will be created only once.

* WalletController is been injected in the BlockChainController instead to access through ApplicationContext

* The access to the singleton Application.Instance is not removed from all the ViewModels.
IApplicationContext has been injected in this classes.

* First atempt to wire the BlockChainController in the app.
Cannot connect to the peers

* * Added some technical debts issues
* Wallet and blockchain code removed from HomeViewModel
* ApplicationContext injection removed from HomeViewModel

* All the code related with wallet access goes not throuh WalletController in AccountsViewModel

* Set application context in view in constructor

* ExternalProcessHelper was create to wrapper the calls Process.Start that start a external process to the application.

* Basic implementation of IDialogHelper and usage to in HomeViewModel to open OpenWalletView #44

* * NotificationHelper created (using nuget from https://github.com/raflop/ToastNotifications)
* Move some code from HomeViewModel to WalletController that use the NotificationHelper to show how the action end

#39, #56

* When a Wallet is opened is need to check if need to upgrade. There are now methods that perfom that and they should be called in the Caller, in this case HomeViewModel.

* * Moving relevant code from BlockChainController to WalletController
* Remove unnecessary IDispatcher from BlockChainController
* Remove unnecessary IDialogHelper from WalletControler

All of this was to remove Circular Reference between BlockChainController and WalletController

* When a message is published should be Dispatched to UI thread.

* * DialogHelper receive parameters
* (..).ShowDialog calles were replaced by DialogHelper
* ICommand were replaced by RelayCommand
* Dialogs now can be closed using the CloseEvent in the DialogViewModel<T>

* * Refactor HomeViewModel to be align with Region structure
* Remove one line methods
* AboutView is Dialog
* DeveloperTools can be open with DialogHelper
* Fix on DialogHelper: When a dialog ViewModel don't implement the IDialogViewModel, the Dialog can be shown anyway
* Settings helper abstract the GuiSettings static calls.

#80, #81, #82

* Added injectable clipboard and settings managers (#74)

* Refactored class names to separate them into either Helper, Service or Manager classes

* Added injectable ClipboardManager class

* Replaced Clipboard references with IClipboardManager references

* Added settings manager interface and implementation class files

* Replaced some references to Neo.Gui.Wpf.Properties.Settings with ISettingsManager

* Moved LocalBlockchainController to Neo.Gui.Base project

* Abstracted some settings to ISettingsManager, added ToAddress and ToScriptHash wrapper method in IWalletController to remove more NEO lib references from view models

* Fixed typo, abstracted all remaining settings used by view models into ISettingsViewModel

* Fixed merge errors

* Moved abstracted settings logic to ISettingManager

* Abstracted all file operations out of view models (#84)

* Abstracted most file operations out of view models

* Added ICompressedFileManager to abstract compressed file operations from view models, moved file manager implementation classes to base project

* Abstracted OpenFileDialog and SaveFileDialog from view models, removed "using" lines that aren't needed (#85)

* Removed references to System.Windows.MessageBox from view models and replaced with method calls to IDialogManager (#86)

* Abstracted InputBox and InformationBox usage into IDialogManager (#87)

* Removed references of InputBox and InformationBox controls from all view models and replaced with calls to IDialogManager methods, cleaned up application intialization logic

* Moved NeoWindow style to newly added StyleResources resource dictionary file

* Replaced usages of MahApps dialog management library with IDialogManager.ShowMessageDialog method calls

* Draft of UnitTests (#89)

* Remove AssetViewModel dependency from HomeViewModel

* when removing the AssetViewModel dependency from HomeView, one binding was forgot

* Remove TransactionsViewModel dependency from HomeViewModel

* First draft of the BlockChainController

* WalletController created

* CreateWallet in WalletController implemented from code in HomeViewModel

* * WalletController: OpenWallet code copy
* DialogHelper created - Object that will abstract the creation and show dialogs.

* Decoupled some views from their respective view model classes using messages

* Replace Application.Instance calls with ApplicationContext that was injected in the constructor

* Remove from solution already removed messages classes

* Cleanup in AccountViewModel don't access the ApplicationContext using the Singleton but the constructor injection object

* Remove singleton ApplicationContext from HomeViewModel and inject it in constructor.

* Remove extra-code added by mistake during the merge

* This object is declared as Singleton, therefore the lock in not necessary. This class will be created only once.

* WalletController is been injected in the BlockChainController instead to access through ApplicationContext

* The access to the singleton Application.Instance is not removed from all the ViewModels.
IApplicationContext has been injected in this classes.

* First atempt to wire the BlockChainController in the app.
Cannot connect to the peers

* * Added some technical debts issues
* Wallet and blockchain code removed from HomeViewModel
* ApplicationContext injection removed from HomeViewModel

* All the code related with wallet access goes not throuh WalletController in AccountsViewModel

* Set application context in view in constructor

* ExternalProcessHelper was create to wrapper the calls Process.Start that start a external process to the application.

* Basic implementation of IDialogHelper and usage to in HomeViewModel to open OpenWalletView #44

* * NotificationHelper created (using nuget from https://github.com/raflop/ToastNotifications)
* Move some code from HomeViewModel to WalletController that use the NotificationHelper to show how the action end

#39, #56

* When a Wallet is opened is need to check if need to upgrade. There are now methods that perfom that and they should be called in the Caller, in this case HomeViewModel.

* * Moving relevant code from BlockChainController to WalletController
* Remove unnecessary IDispatcher from BlockChainController
* Remove unnecessary IDialogHelper from WalletControler

All of this was to remove Circular Reference between BlockChainController and WalletController

* When a message is published should be Dispatched to UI thread.

* * DialogHelper receive parameters
* (..).ShowDialog calles were replaced by DialogHelper
* ICommand were replaced by RelayCommand
* Dialogs now can be closed using the CloseEvent in the DialogViewModel<T>

* * Refactor HomeViewModel to be align with Region structure
* Remove one line methods
* AboutView is Dialog
* DeveloperTools can be open with DialogHelper
* Fix on DialogHelper: When a dialog ViewModel don't implement the IDialogViewModel, the Dialog can be shown anyway
* Settings helper abstract the GuiSettings static calls.

#80, #81, #82

* First unit tests for HomeViewModel

#46

* Add testes to MessageHandlers

* Delete SettingsHelper.cs

* Delete ISettingsHelper.cs

* Moved viewmodel classes out to .NET standard Neo.Gui.ViewModels project (#90)

Also updated Neo nuget package version to 2.4.1

* Fixed namespace error

* HomeViewModel 29 tests added (#91)

* Remove AssetViewModel dependency from HomeViewModel

* when removing the AssetViewModel dependency from HomeView, one binding was forgot

* Remove TransactionsViewModel dependency from HomeViewModel

* First draft of the BlockChainController

* WalletController created

* CreateWallet in WalletController implemented from code in HomeViewModel

* * WalletController: OpenWallet code copy
* DialogHelper created - Object that will abstract the creation and show dialogs.

* Decoupled some views from their respective view model classes using messages

* Replace Application.Instance calls with ApplicationContext that was injected in the constructor

* Remove from solution already removed messages classes

* Cleanup in AccountViewModel don't access the ApplicationContext using the Singleton but the constructor injection object

* Remove singleton ApplicationContext from HomeViewModel and inject it in constructor.

* Remove extra-code added by mistake during the merge

* This object is declared as Singleton, therefore the lock in not necessary. This class will be created only once.

* WalletController is been injected in the BlockChainController instead to access through ApplicationContext

* The access to the singleton Application.Instance is not removed from all the ViewModels.
IApplicationContext has been injected in this classes.

* First atempt to wire the BlockChainController in the app.
Cannot connect to the peers

* * Added some technical debts issues
* Wallet and blockchain code removed from HomeViewModel
* ApplicationContext injection removed from HomeViewModel

* All the code related with wallet access goes not throuh WalletController in AccountsViewModel

* Set application context in view in constructor

* ExternalProcessHelper was create to wrapper the calls Process.Start that start a external process to the application.

* Basic implementation of IDialogHelper and usage to in HomeViewModel to open OpenWalletView #44

* * NotificationHelper created (using nuget from https://github.com/raflop/ToastNotifications)
* Move some code from HomeViewModel to WalletController that use the NotificationHelper to show how the action end

#39, #56

* When a Wallet is opened is need to check if need to upgrade. There are now methods that perfom that and they should be called in the Caller, in this case HomeViewModel.

* * Moving relevant code from BlockChainController to WalletController
* Remove unnecessary IDispatcher from BlockChainController
* Remove unnecessary IDialogHelper from WalletControler

All of this was to remove Circular Reference between BlockChainController and WalletController

* When a message is published should be Dispatched to UI thread.

* * DialogHelper receive parameters
* (..).ShowDialog calles were replaced by DialogHelper
* ICommand were replaced by RelayCommand
* Dialogs now can be closed using the CloseEvent in the DialogViewModel<T>

* * Refactor HomeViewModel to be align with Region structure
* Remove one line methods
* AboutView is Dialog
* DeveloperTools can be open with DialogHelper
* Fix on DialogHelper: When a dialog ViewModel don't implement the IDialogViewModel, the Dialog can be shown anyway
* Settings helper abstract the GuiSettings static calls.

#80, #81, #82

* First unit tests for HomeViewModel

#46

* Add testes to MessageHandlers

* Delete SettingsHelper.cs

* Delete ISettingsHelper.cs

* All public methods in HomeViewModel is fully tested

#46

* Fix references due the change of the ViewModels to their own project

#46

* AssetsViewModelTests class created and GUI reference removed from the Tests Project

#46

* Merge new commits in neo-project/neo-gui repo (#93)

* Updated Neo nuget package version to 2.5.0

* Removed RestoreAccount dialog

* Merged changes from neo-project/neo-gui

* Fix bug of not saving wallet file

* Updated Neo nuget packages

* Added GetStandardAccounts method to IWalletController to reduce duplicate code

* Fixed bug with not clearing the flag that indicates whether wallet balance has changed

* Removed old leftover neo-gui directory

* Fixed error from merge

* Code cleanup, added missing NEP-6 wallet Save method calls

* Moved view model classes to Neo.Gui.ViewModels project, moved transaction generation logic into WalletController (#94)

* Code cleanup, added missing NEP-6 wallet Save method calls

* Removed unused exception class file

* Moved certificate viewing logic to CertficateService, moved transaction generation logic to WalletController. Moved BulkPayViewModel, PayToViewModel and SigningViewModel to Neo.Gui.ViewModels project

* Replaced RelayCommand and ViewModelBase implementations with MvvmLight library implementations

* Add #if DEBUG statements to prevent application from loading update XML document when running a debug build

* Cleaned up namespaces to reflect current directory structure

* AssetViewModel tests (#92)
  • Loading branch information
justingaffney committed Dec 19, 2017
1 parent 78ec329 commit 62b18d8
Show file tree
Hide file tree
Showing 399 changed files with 11,267 additions and 6,913 deletions.
18 changes: 18 additions & 0 deletions Neo.Gui.Base/BaseRegistrationModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Autofac;
using Neo.Gui.Base.Certificates;

namespace Neo.Gui.Base
{
public class BaseRegistrationModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder
.RegisterType<CertificateService>()
.As<ICertificateService>()
.SingleInstance();

base.Load(builder);
}
}
}
17 changes: 17 additions & 0 deletions Neo.Gui.Base/Certificates/CertificateQueryResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Security.Cryptography.X509Certificates;

namespace Neo.Gui.Base.Certificates
{
public class CertificateQueryResult : IDisposable
{
public CertificateQueryResultType Type { get; set; }

public X509Certificate2 Certificate { get; set; }

public void Dispose()
{
this.Certificate?.Dispose();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Neo.Cryptography
namespace Neo.Gui.Base.Certificates
{
internal enum CertificateQueryResultType
public enum CertificateQueryResultType
{
Querying,
QueryFailed,
Expand Down
198 changes: 198 additions & 0 deletions Neo.Gui.Base/Certificates/CertificateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

using Neo.Core;
using Neo.Gui.Base.Helpers;
using Neo.SmartContract;
using Neo.Wallets;
using Neo.Gui.Base.Managers;

using ECCurve = Neo.Cryptography.ECC.ECCurve;
using ECPoint = Neo.Cryptography.ECC.ECPoint;

namespace Neo.Gui.Base.Certificates
{
internal class CertificateService : ICertificateService
{
private readonly IDirectoryManager directoryManager;
private readonly IFileManager fileManager;
private readonly IProcessHelper processHelper;

private readonly Dictionary<UInt160, CertificateQueryResult> results = new Dictionary<UInt160, CertificateQueryResult>();

private string certCachePath;
private bool initialized;

public CertificateService(
IDirectoryManager directoryManager,
IFileManager fileManager,
IProcessHelper processHelper)
{
this.directoryManager = directoryManager;
this.fileManager = fileManager;
this.processHelper = processHelper;
}

public void Initialize(string certificateCachePath)
{
this.certCachePath = certificateCachePath;

if (!this.directoryManager.DirectoryExists(certificateCachePath))
{
this.directoryManager.Create(certificateCachePath);
}

this.initialized = true;
}

public CertificateQueryResult Query(ECPoint publickey)
{
if (!this.initialized)
{
throw new Exception("Service has not been initialized!");
}

var hash = GetRedeemScriptHashFromPublicKey(publickey);

lock (results)
{
if (results.ContainsKey(hash)) return results[hash];
results[hash] = new CertificateQueryResult { Type = CertificateQueryResultType.Querying };
}

var path = this.GetCachedCertificatePathFromScriptHash(hash);
var address = Wallet.ToAddress(hash);

if (this.fileManager.FileExists(path))
{
lock (results)
{
UpdateResultFromFile(hash);
}
}
else
{
var url = $"http://cert.onchain.com/antshares/{address}.cer";
var web = new WebClient();
web.DownloadDataCompleted += this.Web_DownloadDataCompleted;
web.DownloadDataAsync(new Uri(url), hash);
}
return results[hash];
}

public bool ViewCertificate(ECPoint publicKey)
{
if (!this.initialized)
{
throw new Exception("Service has not been initialized!");
}

var hash = GetRedeemScriptHashFromPublicKey(publicKey);

var path = this.GetCachedCertificatePathFromScriptHash(hash);

if (!this.fileManager.FileExists(path)) return false;

this.processHelper.Run(path);

return true;
}

#region Private methods

private void UpdateResultFromFile(UInt160 hash)
{
var path = this.GetCachedCertificatePathFromScriptHash(hash);

X509Certificate2 cert;
try
{
cert = new X509Certificate2(path);
}
catch (CryptographicException)
{
results[hash].Type = CertificateQueryResultType.Missing;
return;
}

if (cert.PublicKey.Oid.Value != "1.2.840.10045.2.1")
{
results[hash].Type = CertificateQueryResultType.Missing;
return;
}

// Compare hash with cached value
var decodedPublicKey = ECPoint.DecodePoint(cert.PublicKey.EncodedKeyValue.RawData, ECCurve.Secp256r1);
var decodedHash = GetRedeemScriptHashFromPublicKey(decodedPublicKey);

if (!hash.Equals(decodedHash))
{
results[hash].Type = CertificateQueryResultType.Missing;
return;
}

using (var chain = new X509Chain())
{
results[hash].Certificate = cert;
if (chain.Build(cert))
{
results[hash].Type = CertificateQueryResultType.Good;
}
else if (chain.ChainStatus.Length == 1 && chain.ChainStatus[0].Status == X509ChainStatusFlags.NotTimeValid)
{
results[hash].Type = CertificateQueryResultType.Expired;
}
else
{
results[hash].Type = CertificateQueryResultType.Invalid;
}
}
}

private void Web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
if (!this.initialized) return;

using ((WebClient)sender)
{
var hash = (UInt160)e.UserState;
if (e.Cancelled || e.Error != null)
{
lock (results)
{
results[hash].Type = CertificateQueryResultType.Missing;
}
}
else
{
var path = this.GetCachedCertificatePathFromScriptHash(hash);

this.fileManager.WriteAllBytes(path, e.Result);

lock (results)
{
this.UpdateResultFromFile(hash);
}
}
}
}

private static UInt160 GetRedeemScriptHashFromPublicKey(ECPoint publicKey)
{
return Contract.CreateSignatureRedeemScript(publicKey).ToScriptHash();
}

private string GetCachedCertificatePathFromScriptHash(UInt160 scriptHash)
{
var address = Wallet.ToAddress(scriptHash);

return Path.Combine(this.certCachePath, $"{address}.cer");
}

#endregion
}
}
13 changes: 13 additions & 0 deletions Neo.Gui.Base/Certificates/ICertificateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Neo.Cryptography.ECC;

namespace Neo.Gui.Base.Certificates
{
public interface ICertificateService
{
void Initialize(string certificateCachePath);

CertificateQueryResult Query(ECPoint publickey);

bool ViewCertificate(ECPoint publicKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.ObjectModel;
using System.Linq;

namespace Neo.UI.Base.Collections
namespace Neo.Gui.Base.Collections
{
public class ConcurrentObservableCollection<T> : ObservableCollection<T>
{
Expand Down
33 changes: 33 additions & 0 deletions Neo.Gui.Base/Controllers/BlockChainStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;

namespace Neo.Gui.Base.Controllers
{
public class BlockchainStatus
{
public BlockchainStatus(uint height, uint headerHeight, bool nextBlockProgressIsIndeterminate,
double nextBlockProgressFraction, TimeSpan timeSinceLastBlock, uint nodeCount)
{
this.Height = height;
this.HeaderHeight = headerHeight;

this.NextBlockProgressIsIndeterminate = nextBlockProgressIsIndeterminate;
this.NextBlockProgressFraction = nextBlockProgressFraction;

this.TimeSinceLastBlock = timeSinceLastBlock;

this.NodeCount = nodeCount;
}

public uint Height { get; }

public uint HeaderHeight { get; }

public bool NextBlockProgressIsIndeterminate { get; }

public double NextBlockProgressFraction { get; }

public TimeSpan TimeSinceLastBlock { get; set; }

public uint NodeCount { get; set; }
}
}
40 changes: 40 additions & 0 deletions Neo.Gui.Base/Controllers/IBlockChainController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using Neo.Core;
using Neo.Network;

namespace Neo.Gui.Base.Controllers
{
public interface IBlockchainController : IDisposable
{
RegisterTransaction GoverningToken { get; }

RegisterTransaction UtilityToken { get; }

uint BlockHeight { get; }

event EventHandler<Block> PersistCompleted;

void Initialize();

BlockchainStatus GetStatus();

void Relay(Transaction transaction);

void Relay(IInventory inventory);

Transaction GetTransaction(UInt256 hash);

Transaction GetTransaction(UInt256 hash, out int height);

AccountState GetAccountState(UInt160 scriptHash);

ContractState GetContractState(UInt160 scriptHash);

AssetState GetAssetState(UInt256 assetId);

Fixed8 CalculateBonus(IEnumerable<CoinReference> inputs, bool ignoreClaimed = true);

Fixed8 CalculateBonus(IEnumerable<CoinReference> inputs, uint heightEnd);
}
}
Loading

0 comments on commit 62b18d8

Please sign in to comment.