public static bool Create(string walletPath, out LocalWallet localWallet) { localWallet = new LocalWallet(); WalletAccount walletAccount; try { if (!Create(walletPath, out walletAccount)) { return(false); } localWallet.WalletName = walletPath; localWallet.Address = walletAccount.Address; localWallet.PublicKey = walletAccount.GetKey().PublicKey.EncodePoint(true).ToHexString(); localWallet.Password = _password; return(true); } catch { return(false); } }
public static bool OpenDefaultWallet() { LocalWallet localWallet; try { string walletPath = "DefaultWallet.json"; string walletPassword = null; if (App.WalletSettings.LocalWallets.Count() > 0 && App.WalletSettings.DefaultWallet != null && App.WalletSettings.DefaultPassword != null) { walletPath = App.WalletSettings.DefaultWallet; walletPassword = App.WalletSettings.DefaultPassword; } if (!File.Exists(walletPath)) { walletPath = "DefaultWallet.json"; if (NeoStudio.NeoWallet.Create(walletPath, out localWallet)) { if (App.WalletSettings.LocalWallets.Count(w => w.WalletName == localWallet.WalletName) == 0) { App.WalletSettings.LocalWallets.Add(localWallet); ((MainWindowViewModel)((NeoStudio.View.MainWindow)App.Current.MainWindow).DataContext).WalletList.Add(localWallet); App.WalletSettings.DefaultWallet = localWallet.WalletName; App.WalletSettings.DefaultPassword = localWallet.Password; App.WalletSettings.Save(Path.GetDirectoryName(localWallet.WalletName)); } ((MainWindowViewModel)((NeoStudio.View.MainWindow)App.Current.MainWindow).DataContext).SelectedWallet = localWallet; return(true); } else { return(false); } } if (walletPassword == null) { if (NeoStudio.NeoWallet.OpenWallet(walletPath)) { App.WalletSettings.DefaultWallet = walletPath; if (App.WalletSettings.LocalWallets.Count(w => w.WalletName == walletPath) == 0) { localWallet = new LocalWallet(); localWallet.WalletName = walletPath; App.WalletSettings.LocalWallets.Add(localWallet); App.WalletSettings.Save(Path.GetDirectoryName(localWallet.WalletName)); ((MainWindowViewModel)((NeoStudio.View.MainWindow)App.Current.MainWindow).DataContext).WalletList.Add(localWallet); } ((MainWindowViewModel)((NeoStudio.View.MainWindow)App.Current.MainWindow).DataContext).SelectedWallet = App.WalletSettings.LocalWallets.FirstOrDefault(w => w.WalletName == walletPath); return(true); } else { return(false); } } if (walletPassword != null) { if (NeoStudio.NeoWallet.OpenWallet(walletPath, walletPassword)) { App.WalletSettings.DefaultWallet = walletPath; App.WalletSettings.DefaultPassword = walletPassword; App.WalletSettings.Save(Path.GetDirectoryName(walletPath)); ((MainWindowViewModel)((NeoStudio.View.MainWindow)App.Current.MainWindow).DataContext).SelectedWallet = App.WalletSettings.LocalWallets.FirstOrDefault(w => w.WalletName == walletPath); return(true); } else { return(false); } } return(false); } catch { return(false); } }
public static bool OpenWallet(LocalWallet localWallet) { return(OpenWallet(localWallet.WalletName, localWallet.Password)); }