Ejemplo n.º 1
0
 private static void _Instance_OnRequestUserInput(object sender, RequestUserInputArgs e)
 {
     Console.Write(e.Message);
     while (e.UserInput == null)
     {
         e.UserInput = Console.ReadLine();
     }
 }
Ejemplo n.º 2
0
        public void Start(string toAddress, bool showCancel = false)
        {
            var addressUtil = new AddressUtil();

            if (!string.IsNullOrWhiteSpace(toAddress))
            {
                if (toAddress.StartsWith("0x") && addressUtil.IsValidAddressLength(toAddress) && addressUtil.IsChecksumAddress(toAddress))
                {
                    _CancellationTokenSource = new CancellationTokenSource();
                    _Task = Task.Run(() => RunMeter(toAddress, _CancellationTokenSource.Token), _CancellationTokenSource.Token);
                    return;
                }
                else
                {
                    toAddress = null;
                    OnMessage?.Invoke(this, new MessageArgs("Invalid user defined address."));
                }
            }

            var query = new StringBuilder();

            query.AppendLine("Select Token Contract:");
            query.AppendLine("1: 0xBitcoin");
            query.AppendLine("2: 0xCatEther");
            query.AppendLine("3: KIWI Token");
            query.AppendLine("4: 0xZibit");
            query.AppendLine("or enter Contract Address (including '0x' prefix)");
            if (showCancel)
            {
                query.AppendLine("Press Ctrl-C again to quit.");
            }

            var request = new RequestUserInputArgs(query.ToString());

            while (string.IsNullOrWhiteSpace(toAddress))
            {
                OnRequestUserInput?.Invoke(this, request);

                switch (request.UserInput)
                {
                case "1":
                case "0xBitcoin":
                    toAddress = Contracts._0xBitcoin;
                    break;

                case "2":
                case "0xCatEther":
                    toAddress = Contracts._0xCatether;
                    break;

                case "3":
                case "KIWI Token":
                    toAddress = Contracts.KIWI_Token;
                    break;

                case "4":
                case "0xZibit":
                    toAddress = Contracts._0xZibit;
                    break;

                default:
                    if (request.UserInput == null)
                    {
                        break;
                    }

                    if (request.UserInput.StartsWith("0x") && addressUtil.IsValidAddressLength(request.UserInput) && addressUtil.IsChecksumAddress(request.UserInput))
                    {
                        toAddress = request.UserInput;
                    }
                    else
                    {
                        OnMessage?.Invoke(this, new MessageArgs("Invalid address."));
                        request.UserInput = null;
                    }
                    break;
                }
            }
            _CancellationTokenSource = new CancellationTokenSource();
            _Task = Task.Run(() => RunMeter(toAddress, _CancellationTokenSource.Token), _CancellationTokenSource.Token);
        }