public MissingBase58ViewModel()
        {
            // Don't move this line, service must be instantiated here
            InputService inServ = new();

            b58Service = new Base58Service(Result);

            IObservable <bool> isFindEnabled = this.WhenAnyValue(
                x => x.Input, x => x.MissingChar,
                x => x.Result.CurrentState, (b58, c, state) =>
                !string.IsNullOrEmpty(b58) &&
                inServ.IsMissingCharValid(c) &&
                state != State.Working);

            FindCommand            = ReactiveCommand.Create(Find, isFindEnabled);
            InputTypeList          = ListHelper.GetAllEnumValues <Base58Service.InputType>();
            ExtraInputTypeList     = ListHelper.GetEnumDescItems(InputType.PrivateKey).ToArray();
            SelectedExtraInputType = ExtraInputTypeList.First();

            HasExample = true;
            IObservable <bool> isExampleVisible = this.WhenAnyValue(
                x => x.Result.CurrentState,
                (state) => state != State.Working);

            ExampleCommand = ReactiveCommand.Create(Example, isExampleVisible);

            SetExamples(GetExampleData());
        }
示例#2
0
        public void GetShiftedMultPow58Test(int maxPow, int uLen, int shift)
        {
            ulong[] shiftedPowers = Base58Service.GetShiftedMultPow58(maxPow, uLen, shift);

            ulong mask  = (1U << shift) - 1;
            int   index = 0;

            for (int i = 0; i < 58; i++)
            {
                for (int j = 0; j < maxPow; j++)
                {
                    byte[] ba = new byte[4 * uLen];
                    for (int k = 0; k < ba.Length; k += 4, index++)
                    {
                        // Make sure values are shifted correctly
                        Assert.Equal(0U, shiftedPowers[index] & mask);
                        ulong val = shiftedPowers[index] >> shift;
                        // Make sure each unshifted value fits in a UInt32
                        Assert.True(val <= uint.MaxValue);

                        ba[k]     = (byte)val;
                        ba[k + 1] = (byte)(val >> 8);
                        ba[k + 2] = (byte)(val >> 16);
                        ba[k + 3] = (byte)(val >> 24);
                    }

                    BigInteger actual   = new(ba, true, false);
                    BigInteger expected = BigInteger.Pow(58, j) * i;
                    Assert.Equal(expected, actual);
                }
            }

            Assert.Equal(index, shiftedPowers.Length);
        }