コード例 #1
0
        public override async Task Execute()
        {
            using (var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow))
                using (var password = Prompt.GetPasswordAsSecureString("Password:"******"To:", null, ConsoleColor.Red);
                    var amount  = Prompt.GetString("Amount:", null, ConsoleColor.Red);
                    var memo    = Prompt.GetString("Memo:", null, ConsoleColor.Green);
                    var yesNo   = Prompt.GetYesNo("Send redemption key to message pool?", true, ConsoleColor.Yellow);

                    if (double.TryParse(amount, out double t))
                    {
                        await Spinner.StartAsync("Processing payment ...", async spinner =>
                        {
                            this.spinner = spinner;

                            try
                            {
                                var session = new Session(identifier, password)
                                {
                                    Amount           = t.ConvertToUInt64(),
                                    ForwardMessage   = yesNo,
                                    Memo             = memo,
                                    RecipientAddress = address
                                };

                                await actorService.Tansfer(session);
                                session = actorService.GetSession(session.SessionId);

                                if (actorService.State != State.Completed)
                                {
                                    var failedMessage = JsonConvert.SerializeObject(session.LastError.GetValue("message"));
                                    logger.LogCritical(failedMessage);
                                    spinner.Fail(failedMessage);
                                    return;
                                }

                                if (session.ForwardMessage.Equals(false))
                                {
                                    await SaveRedemptionKeyLocal(session.SessionId);
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.LogError(ex.StackTrace);
                                throw ex;
                            }
                            finally
                            {
                                var balance  = await walletService.AvailableBalance(identifier, password);
                                spinner.Text = $"Available Balance: {balance.Result.DivWithNaT().ToString("F9")}";
                            }
                        }, Patterns.Toggle3);
                    }
                }
        }
コード例 #2
0
    private static FileInfo[] FilterFiles(int?days, bool all, bool force, Spinner spinner, FileInfo[] files)
    {
        if (!all)
        {
            if (days == null)
            {
                spinner.Fail("This selection needs the number of days you want to delete.\n" +
                             "Please use the -d or -a option.");
            }

            var dayLimit = DateTime.Now.AddDays(days !.Value * -1);
            files = files.Where(file => file.CreationTime.Date < dayLimit.Date).ToArray();
        }

        var fileCount = files.Length;

        if (fileCount > 50 && !force)
        {
            spinner.Fail("More than 50 files would be deleted with this option.\n" +
                         "Please use the command again with the -f option to delete.");
        }

        return(files);
    }
コード例 #3
0
    private Uri TriggerTimelineCreation(string raidGroup, DateTime date, Spinner spinner, string[] files, int uploadOk,
                                        int uploadFail)
    {
        var uri    = new Uri($"{_configurationHelper.Configuration.EndpointUri}/{raidGroup}/{date.Date:dd.MM.yyyy}");
        var client = new HttpClient();

        spinner.Text = $"Creating timeline...";
        var timelineResponse = client.PostAsync(uri, null).Result;

        if (timelineResponse.StatusCode != HttpStatusCode.OK)
        {
            spinner.Fail($"Tried uploading {files.Length} files: {uploadOk} ok, {uploadFail} failed.\n" +
                         $"Timeline creation failed!");
            _logger.LogError(timelineResponse.ReasonPhrase);
        }

        var location = timelineResponse.Content.ReadAsStringAsync().Result;

        return(new Uri(location));
    }
コード例 #4
0
        public override async Task Execute()
        {
            using var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow);
            using var passphrase = Prompt.GetPasswordAsSecureString("Passphrase:", ConsoleColor.Yellow);

            var paymentId = Prompt.GetString("PAYMENTID:", null, ConsoleColor.Green);

            if (!string.IsNullOrEmpty(paymentId))
            {
                await Spinner.StartAsync("Receiving payment...", async spinner =>
                {
                    this.spinner = spinner;

                    try
                    {
                        var session = _walletService.SessionAddOrUpdate(new Session(identifier, passphrase));

                        await _walletService.ReceivePayment(session.SessionId, paymentId);

                        if (session.LastError != null)
                        {
                            spinner.Fail(JsonConvert.SerializeObject(session.LastError.GetValue("message")));
                            return;
                        }

                        var transaction       = _walletService.LastWalletTransaction(session.SessionId, WalletType.Receive);
                        var txnReceivedAmount = transaction == null ? 0.ToString() : transaction.Payment.DivWithNaT().ToString("F9");
                        var txnMemo           = transaction == null ? "" : transaction.Memo;
                        var balance           = _walletService.AvailableBalance(session.SessionId);

                        spinner.Succeed($"Memo: {txnMemo}  Received: {txnReceivedAmount}  Available Balance: {balance.Result.DivWithNaT():F9}");
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"Message: {ex.Message}\n Stack: {ex.StackTrace}");
                        throw;
                    }
                }, Patterns.Toggle3);
            }
        }
コード例 #5
0
        public override async Task Execute()
        {
            using (var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow))
                using (var password = Prompt.GetPasswordAsSecureString("Password:"******"To:", null, ConsoleColor.Red);
                    var amount  = Prompt.GetString("Amount:", null, ConsoleColor.Red);
                    var memo    = Prompt.GetString("Memo:", null, ConsoleColor.Green);
                    var yesNo   = Prompt.GetYesNo("Send redemption key to message pool?", true, ConsoleColor.Yellow);


                    if (double.TryParse(amount, out double t))
                    {
                        await Spinner.StartAsync("Processing payment ...", async spinner =>
                        {
                            this.spinner = spinner;

                            try
                            {
                                var sent = await actorService
                                           .MasterKey(password)
                                           .Identifier(identifier)
                                           .Amount(t)
                                           .ToAddress(address)
                                           .Memo(memo)
                                           .SendPayment();

                                if (sent.Equals(false))
                                {
                                    var failedMessage = JsonConvert.SerializeObject(actorService.GetLastError().GetValue("message"));
                                    logger.LogCritical(failedMessage);
                                    spinner.Fail(failedMessage);
                                    return;
                                }

                                switch (yesNo)
                                {
                                case true:
                                    var networkMessage = await actorService.SendPaymentMessage(true);
                                    var success        = networkMessage.GetValue("success").ToObject <bool>();

                                    if (success.Equals(false))
                                    {
                                        spinner.Fail(JsonConvert.SerializeObject(networkMessage.GetValue("message")));
                                    }

                                    break;

                                case false:
                                    var localMessage = await actorService.SendPaymentMessage(false);

                                    SaveRedemptionKeyLocal(localMessage);

                                    break;
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.LogError(ex.StackTrace);
                                throw ex;
                            }
                            finally
                            {
                                spinner.Text = $"Available Balance: {Convert.ToString(await actorService.CheckBalance())}";
                            }
                        });
                    }
                }
        }
コード例 #6
0
        public override async Task Execute()
        {
            using var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow);
            using var passphrase = Prompt.GetPasswordAsSecureString("Passphrase:", ConsoleColor.Yellow);

            var address = Prompt.GetString("Address:", null, ConsoleColor.Red);
            var amount  = Prompt.GetString("Amount:", null, ConsoleColor.Red);
            var memo    = Prompt.GetString("Memo:", null, ConsoleColor.Green);

            if (decimal.TryParse(amount, out var t))
            {
                await Spinner.StartAsync("Processing payment ...", async spinner =>
                {
                    this.spinner = spinner;

                    try
                    {
                        var session = _walletService.SessionAddOrUpdate(new Session(identifier, passphrase)
                        {
                            SessionType       = SessionType.Coin,
                            WalletTransaction = new WalletTransaction
                            {
                                Memo             = memo,
                                Payment          = t.ConvertToUInt64(),
                                RecipientAddress = address,
                                WalletType       = WalletType.Send
                            }
                        });

                        _walletService.CreateTransaction(session.SessionId);

                        if (session.LastError != null)
                        {
                            spinner.Fail(JsonConvert.SerializeObject(session.LastError.GetValue("message")));
                            return;
                        }

                        await _walletService.Send(session.SessionId);

                        if (session.LastError != null)
                        {
                            spinner.Fail(JsonConvert.SerializeObject(session.LastError.GetValue("message")));
                            return;
                        }

                        var balance = _walletService.History(session.SessionId);
                        var message = $"Available Balance: {balance.Result.Last().Balance}";

                        var walletTx = _walletService.LastWalletTransaction(session.SessionId, WalletType.Send);
                        if (walletTx != null)
                        {
                            message += $"PaymentID: {walletTx.Transaction.TxnId.ByteToHex()}";
                        }

                        spinner.Succeed(message);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.StackTrace);
                        throw;
                    }
                }, Patterns.Toggle3);
            }
        }
コード例 #7
0
        public override async Task Execute()
        {
            try
            {
                using (var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow))
                    using (var password = Prompt.GetPasswordAsSecureString("Password:"******"Amount:", null, ConsoleColor.Red);
                        var address = Prompt.GetString("To:", null, ConsoleColor.Red);
                        var memo    = Prompt.GetString("Memo:", null, ConsoleColor.Green);
                        var yesNo   = Prompt.GetYesNo("Send redemption key to message pool?", true, ConsoleColor.Yellow);

                        using (var insecureIdentifier = identifier.Insecure())
                        {
                            await vaultService.GetDataAsync(identifier, password, $"wallets/{insecureIdentifier.Value}/wallet");
                        }

                        if (double.TryParse(amount, out double t))
                        {
                            JObject payment;

                            await Spinner.StartAsync("Processing payment ...", async spinner =>
                            {
                                this.spinner  = spinner;
                                spinner.Color = ConsoleColor.Blue;

                                payment = await actorService
                                          .From(password)
                                          .Identifier(identifier)
                                          .Amount(t)
                                          .To(address)
                                          .Memo(memo)
                                          .SendPayment(yesNo);

                                spinner.Text = "Fetching balance ...";
                                await Task.Delay(1500);

                                await CheckBalance(identifier, password);

                                spinner.Text = "Done ...";

                                if (yesNo.Equals(false))
                                {
                                    SaveRedemptionKeyLocal(spinner, payment);
                                }
                                else
                                {
                                    var success = payment.GetValue("success");
                                    var message = payment.GetValue("message");

                                    if (success.ToObject <bool>().Equals(false))
                                    {
                                        spinner.Fail(message.ToObject <string>());
                                    }
                                }
                            });
                        }
                    }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
        public override async Task Execute()
        {
            using (var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow))
                using (var password = Prompt.GetPasswordAsSecureString("Password:"******"Memo:", null, ConsoleColor.Green);
                    var address   = Prompt.GetString("Address:", null, ConsoleColor.Red);
                    var amountStr = Prompt.GetString("Amount:", null, ConsoleColor.Red);

                    if (!string.IsNullOrEmpty(address) && double.TryParse(amountStr, out double amount))
                    {
                        await Spinner.StartAsync("Revving up the printer", async spinner =>
                        {
                            this.spinner = spinner;

                            await Task.Delay(500);

                            try
                            {
                                spinner.Text = "Transferring money";

                                actorService
                                .MasterKey(password)
                                .Identifier(identifier)
                                .ToAddress(address)
                                .Memo(memo);

                                await actorService.SetRandomAddress();
                                await actorService.SetSecretKey();
                                await actorService.SetPublicKey();

                                var coin = coinService
                                           .TransactionCoin(new TransactionCoin {
                                    Input = (ulong)amount
                                })
                                           .BuildReceiver(password)
                                           .Coin();

                                coin.Hash    = coinService.Hash(coin).ToHex();
                                coin.Network = walletService.NetworkAddress(coin).ToHex();

                                var c = SendCoin(coin);

                                if (c == null)
                                {
                                    spinner.Fail("Something went wrong ;(");
                                }

                                var networkMessage = await actorService.SendPaymentMessage(true);
                                var success        = networkMessage.GetValue("success").ToObject <bool>();

                                if (success.Equals(false))
                                {
                                    spinner.Fail(JsonConvert.SerializeObject(networkMessage.GetValue("message")));
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.LogError(ex.Message);
                                logger.LogError(ex.StackTrace);
                                throw ex;
                            }
                            finally
                            {
                                spinner.Text = "Printed...";
                            }
                        });
                    }
                }
        }