/
MissingBase58ViewModel.cs
78 lines (64 loc) · 2.63 KB
/
MissingBase58ViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// The FinderOuter
// Copyright (c) 2020 Coding Enthusiast
// Distributed under the MIT software license, see the accompanying
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
using FinderOuter.Backend;
using FinderOuter.Services;
using ReactiveUI;
using System;
namespace FinderOuter.ViewModels
{
public class MissingBase58ViewModel : OptionVmBase
{
public MissingBase58ViewModel()
{
// Don't move this line, service must be instantiated here
b58Service = new Base58Sevice(Result);
IObservable<bool> isFindEnabled = this.WhenAnyValue(
x => x.Input, x => x.MissingChar,
x => x.Result.CurrentState, (b58, c, state) =>
!string.IsNullOrEmpty(b58) &&
b58Service.IsMissingCharValid(c) &&
state != Models.State.Working);
FindCommand = ReactiveCommand.Create(Find, isFindEnabled);
}
public override string OptionName => "Missing Base58";
public override string Description => $"Helps you recover missing base-58 characters in any base-58 encoded strings that " +
$"has a checksum. Examples are private keys, extended pub/priv keys, addresses,...{Environment.NewLine}" +
$"Enter the base-58 string and replace its missing characters with the symbol defined by {nameof(MissingChar)} " +
$"parameter and press Find.";
private readonly Base58Sevice b58Service;
private string _input;
public string Input
{
get => _input;
set => this.RaiseAndSetIfChanged(ref _input, value);
}
private char _mis = '*';
public char MissingChar
{
get => _mis;
set => this.RaiseAndSetIfChanged(ref _mis, value);
}
private bool _isSpecial;
public bool IsSpecialCase
{
get => _isSpecial;
set => this.RaiseAndSetIfChanged(ref _isSpecial, value);
}
public string MissingToolTip => $"Choose one of these symbols {Constants.Symbols} to use instead of the missing characters";
public string SpecialToolTip => "Select this for a special case where you have a compressed private key that is missing " +
"exactly 3 characters and you don't know their locations.";
public override void Find()
{
if (IsSpecialCase)
{
_ = b58Service.FindUnknownLocation(Input);
}
else
{
_ = b58Service.Find(Input, MissingChar);
}
}
}
}