public void RecoverWalletSuccessfullyReturnsWalletModel() { Wallet.Wallet wallet = new Wallet.Wallet { Name = "myWallet", Network = WalletHelpers.GetNetwork("mainnet") }; var mockWalletWrapper = new Mock <IWalletManager>(); mockWalletWrapper.Setup(w => w.LoadWallet(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(wallet); var controller = new WalletController(mockWalletWrapper.Object, new Mock <ITracker>().Object); // Act var result = controller.Load(new WalletLoadRequest { Name = "myWallet", FolderPath = "", Password = "" }); // Assert mockWalletWrapper.VerifyAll(); var viewResult = Assert.IsType <JsonResult>(result); Assert.NotNull(viewResult.Value); Assert.IsType <WalletModel>(viewResult.Value); var model = viewResult.Value as WalletModel; Assert.Equal("Main", model.Network); }
public void RecoverWalletSuccessfullyReturnsWalletModel() { Bitcoin.Wallet.Wallet wallet = new Bitcoin.Wallet.Wallet { Name = "myWallet", Network = WalletHelpers.GetNetwork("mainnet") }; var mockWalletWrapper = new Mock <IWalletManager>(); mockWalletWrapper.Setup(w => w.LoadWallet(It.IsAny <string>(), It.IsAny <string>())).Returns(wallet); string dir = AssureEmptyDir("TestData/ControllersTests/RecoverWalletSuccessfullyReturnsWalletModel"); var dataFolder = new DataFolder(new NodeSettings { DataDir = dir }); var controller = new WalletController(mockWalletWrapper.Object, new Mock <IWalletSyncManager>().Object, It.IsAny <ConnectionManager>(), Network.Main, new Mock <ConcurrentChain>().Object, dataFolder); // Act var result = controller.Load(new WalletLoadRequest { Name = "myWallet", FolderPath = "", Password = "" }); // Assert mockWalletWrapper.VerifyAll(); var viewResult = Assert.IsType <OkResult>(result); Assert.Equal(200, viewResult.StatusCode); }
public static void StakeForGame(int number_of_players, User user, string token, PostSuccessCallback callback, PostFailedCallback fallback) { float stake = GetStakeAmount(number_of_players); float current_amount = WalletHelpers.CurrentUserWallet(user); float new_amount = WalletHelpers.DebitUserWallet(user, stake); string tranx_id = Generate.UniqueUuid(); Transaction transaction = new Transaction(tranx_id, "stake", current_amount, new_amount, user.local_id); string trans_data = FormatPostData.TransactionFieldModel(transaction); user.wallet_balance = new_amount; string new_user_data = FormatPostData.UserFieldModel(user); //FireBase.Patch( // new_user_data, "users/" + user.local_id, token, // (response3) => // { // FireBase.Post( // trans_data, "/transactions/?documentId=" + tranx_id, token, // (response1) => // { // callback(new_amount); // }, // (error) => // { // fallback(error); // } // ); // }, // (error) => { fallback(error); } //); }
/// <inheritdoc /> public Wallet RecoverWallet(string password, string folderPath, string name, string network, string mnemonic, DateTime creationTime, string passphrase = null) { // for now the passphrase is set to be the password by default. if (passphrase == null) { passphrase = password; } // generate the root seed used to generate keys ExtKey extendedKey = (new Mnemonic(mnemonic)).DeriveExtKey(passphrase); Network coinNetwork = WalletHelpers.GetNetwork(network); // create a wallet file Wallet wallet = this.GenerateWalletFile(password, folderPath, name, coinNetwork, extendedKey, creationTime); // generate multiple accounts and addresses from the get-go for (int i = 0; i < WalletRecoveryAccountsCount; i++) { HdAccount account = CreateNewAccount(wallet, this.coinType, password); this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer); this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer, true); } int blockSyncStart = this.chain.GetHeightAtTime(creationTime); this.UpdateLastBlockSyncedHeight(wallet, blockSyncStart); // save the changes to the file and add addresses to be tracked this.SaveToFile(wallet); this.Load(wallet); this.LoadKeysLookup(); return(wallet); }
public void LoadWalletSuccessfullyReturnsWalletModel() { Bitcoin.Wallet.Wallet wallet = new Bitcoin.Wallet.Wallet { Name = "myWallet", Network = WalletHelpers.GetNetwork("mainnet") }; var mockWalletWrapper = new Mock <IWalletManager>(); mockWalletWrapper.Setup(w => w.RecoverWallet(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), null)).Returns(wallet); var controller = new WalletController(mockWalletWrapper.Object, new Mock <IWalletSyncManager>().Object, It.IsAny <ConnectionManager>(), Network.Main, new Mock <ConcurrentChain>().Object); // Act var result = controller.Recover(new WalletRecoveryRequest { Name = "myWallet", FolderPath = "", Password = "", Network = "MainNet", Mnemonic = "mnemonic" }); // Assert mockWalletWrapper.VerifyAll(); var viewResult = Assert.IsType <OkResult>(result); Assert.Equal(200, viewResult.StatusCode); }
public void WrongNetworkThrowsArgumentException() { var exception = Record.Exception(() => WalletHelpers.GetNetwork("myNetwork")); Assert.NotNull(exception); Assert.IsType <ArgumentException>(exception); }
/// <inheritdoc /> public Mnemonic CreateWallet(string password, string folderPath, string name, string network, string passphrase = null) { // for now the passphrase is set to be the password by default. if (passphrase == null) { passphrase = password; } // generate the root seed used to generate keys from a mnemonic picked at random // and a passphrase optionally provided by the user Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.Twelve); ExtKey extendedKey = mnemonic.DeriveExtKey(passphrase); Network coinNetwork = WalletHelpers.GetNetwork(network); // create a wallet file Wallet wallet = this.GenerateWalletFile(password, folderPath, name, coinNetwork, extendedKey); // generate multiple accounts and addresses from the get-go for (int i = 0; i < WalletCreationAccountsCount; i++) { HdAccount account = CreateNewAccount(wallet, this.coinType, password); this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer); this.CreateAddressesInAccount(account, coinNetwork, UnusedAddressesBuffer, true); } // save the changes to the file and add addresses to be tracked this.SaveToFile(wallet); this.PubKeys = this.LoadKeys(this.coinType); this.Load(wallet); return(mnemonic); }
public void GetNetworkIsCaseInsensitive() { Network testNetwork = WalletHelpers.GetNetwork("Test"); Assert.Equal(Network.TestNet, testNetwork); Network mainNetwork = WalletHelpers.GetNetwork("MainNet"); Assert.Equal(Network.Main, mainNetwork); }
public AddedWalletPageViewModel(KeyManager keyManager) { WalletName = keyManager.WalletName; WalletType = WalletHelpers.GetType(keyManager); SetupCancel(enableCancel: false, enableCancelOnEscape: false, enableCancelOnPressed: false); EnableBack = false; NextCommand = ReactiveCommand.Create(() => OnNext(keyManager)); }
public HardwareWalletAuthDialogViewModel(Wallet wallet, TransactionAuthorizationInfo transactionAuthorizationInfo) { if (!wallet.KeyManager.IsHardwareWallet) { throw new InvalidOperationException("Not a hardware wallet."); } _wallet = wallet; _transactionAuthorizationInfo = transactionAuthorizationInfo; WalletType = WalletHelpers.GetType(wallet.KeyManager); SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true); EnableBack = false; }
public void UpdateLabels() { var labels = WalletHelpers.GetLabels(); var mostUsedLabels = labels.GroupBy(x => x) .Select(x => new { Label = x.Key, Count = x.Count() }) .OrderByDescending(x => x.Count) .ToList(); _sourceLabels.Clear(); _sourceLabels.AddRange( mostUsedLabels.Select(x => new SuggestionLabelViewModel(x.Label, x.Count))); }
public HardwareWalletAuthDialogViewModel(Wallet wallet, TransactionAuthorizationInfo transactionAuthorizationInfo) { if (!wallet.KeyManager.IsHardwareWallet) { throw new InvalidOperationException("Not a hardware wallet."); } _wallet = wallet; _transactionAuthorizationInfo = transactionAuthorizationInfo; WalletType = WalletHelpers.GetType(wallet.KeyManager); SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true); EnableBack = false; AuthorizationFailedMessage = $"Authorization failed.{Environment.NewLine}Please, check your device and try again."; }
public LoginViewModel(ClosedWalletViewModel closedWalletViewModel) { var wallet = closedWalletViewModel.Wallet; IsPasswordNeeded = !wallet.KeyManager.IsWatchOnly; WalletName = wallet.WalletName; _password = ""; _errorMessage = ""; WalletType = WalletHelpers.GetType(closedWalletViewModel.Wallet.KeyManager); NextCommand = ReactiveCommand.CreateFromTask(async() => await OnNextAsync(closedWalletViewModel, wallet)); OkCommand = ReactiveCommand.Create(OnOk); ForgotPasswordCommand = ReactiveCommand.Create(() => OnForgotPassword(wallet)); EnableAutoBusyOn(NextCommand); }
public ReceiveViewModel(Wallet wallet) { _wallet = wallet; _labels = new ObservableCollectionExtended <string>(); var allLabels = WalletHelpers.GetLabels(); var mostUsedLabels = allLabels.GroupBy(x => x) .Select(x => new { Label = x.Key, Count = x.Count() }) .OrderByDescending(x => x.Count) .ToList(); _suggestions = mostUsedLabels.Select(x => x.Label).ToHashSet(); _suggestionLabels = new SourceList <SuggestionLabelViewModel>(); _suggestionLabelResults = new ObservableCollectionExtended <SuggestionLabelViewModel>(); _suggestionLabels.AddRange( mostUsedLabels.Select(x => new SuggestionLabelViewModel(x.Label, x.Count))); var suggestionLabelsFilter = this.WhenAnyValue(x => x.Labels).Select(_ => Unit.Default) .Merge(Observable.FromEventPattern(Labels, nameof(Labels.CollectionChanged)).Select(_ => Unit.Default)) .Select(SuggestionLabelsFilter); _suggestionLabels .Connect() .Filter(suggestionLabelsFilter) .Sort(SortExpressionComparer <SuggestionLabelViewModel> .Descending(x => x.Count)) .Top(3) .ObserveOn(RxApp.MainThreadScheduler) .Bind(_suggestionLabelResults) .Subscribe(); SetupCancel(enableCancel: true, enableCancelOnEscape: true, enableCancelOnPressed: true); EnableBack = false; NextCommand = ReactiveCommand.Create(OnNext, _labels.ToObservableChangeSet().Select(_ => _labels.Count > 0)); ShowExistingAddressesCommand = ReactiveCommand.Create(OnShowExistingAddresses); }
private async Task OnImportWalletAsync() { try { var filePath = await FileDialogHelper.ShowOpenFileDialogAsync("Import wallet file", new[] { "json" }); if (filePath is null) { return; } var walletName = Path.GetFileNameWithoutExtension(filePath); var validationError = WalletHelpers.ValidateWalletName(walletName); if (validationError is { }) { Navigate().To(new WalletNamePageViewModel(WalletCreationOption.ImportWallet, filePath)); return; } var keyManager = await ImportWalletHelper.ImportWalletAsync(Services.WalletManager, walletName, filePath); Navigate().To(new AddedWalletPageViewModel(keyManager)); }
public void GetTestNetNetworkRetuirnsNetworkTest() { Network network = WalletHelpers.GetNetwork("testnet"); Assert.Equal(Network.TestNet, network); }
public void GetMainNetNetworkRetuirnsNetworkMain() { Network network = WalletHelpers.GetNetwork("mainnet"); Assert.Equal(Network.Main, network); }
public void UpdateLabels() { var labelPool = new Dictionary <string, int>(); // int: score. // Make recent and receive labels count more for the current wallet var multiplier = 100; foreach (var label in KeyManager.GetReceiveLabels().Reverse().SelectMany(x => x.Labels)) { var score = (Intent == Intent.Receive ? 100 : 1) * multiplier; if (!labelPool.TryAdd(label, score)) { labelPool[label] += score; } if (multiplier > 1) { multiplier--; } } // Receive addresses should be more dominant. foreach (var label in WalletHelpers.GetReceiveAddressLabels().SelectMany(x => x.Labels)) { var score = Intent == Intent.Receive ? 100 : 1; if (!labelPool.TryAdd(label, score)) { labelPool[label] += score; } } // Change addresses shouldn't be much dominant, but should be present. foreach (var label in WalletHelpers.GetChangeAddressLabels().SelectMany(x => x.Labels)) { var score = 1; if (!labelPool.TryAdd(label, score)) { labelPool[label] += score; } } multiplier = 100; // Make recent labels count more. foreach (var label in WalletHelpers.GetTransactionLabels().SelectMany(x => x.Labels).Reverse()) { var score = (Intent == Intent.Send ? 100 : 1) * multiplier; if (!labelPool.TryAdd(label, score)) { labelPool[label] += score; } if (multiplier > 1) { multiplier--; } } var unwantedLabelSuggestions = new[] { "test", // Often people use the string "test" as a label. It obviously cannot be a real label, just a test label. "zerolink mixed coin", // Obsolated autogenerated label from old WW1 versions. "zerolink change", // Obsolated autogenerated label from old WW1 versions. "zerolink dequeued change" // Obsolated autogenerated label from old WW1 versions. }; var labels = labelPool .Where(x => !unwantedLabelSuggestions.Any(y => y.Equals(x.Key, StringComparison.OrdinalIgnoreCase)) && !x.Key.StartsWith("change of (", StringComparison.OrdinalIgnoreCase)); // An obsolated autogenerated label pattern was from old WW1 versions starting with "change of (". var mostUsedLabels = labels .GroupBy(x => x.Key) .Select(x => new { Label = x.Key, Score = x.Sum(y => y.Value) }) .OrderByDescending(x => x.Score) .ToList(); _sourceLabels.Clear(); _sourceLabels.AddRange( mostUsedLabels.Select(x => new SuggestionLabelViewModel(x.Label, x.Score))); }
/// <inheritdoc /> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return(WalletHelpers.GetNetwork((string)reader.Value)); }