private async Task CheckBalance(SecureString identifier, SecureString password)
        {
            var total = await walletService.AvailableBalance(identifier, password);

            console.ForegroundColor = ConsoleColor.Magenta;
            console.WriteLine($"\nAvailable Balance: {total}\n");
            console.ForegroundColor = ConsoleColor.White;
        }
        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);
                    }
                }
        }
Beispiel #3
0
        public override async Task Execute()
        {
            try
            {
                using (var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow))
                    using (var password = Prompt.GetPasswordAsSecureString("Password:"******"\nWallet balance: {total.Result.DivWithNaT().ToString("F9")}\n");
                        console.ForegroundColor = ConsoleColor.White;
                    }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public override async Task Execute()
        {
            using (var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow))
                using (var password = Prompt.GetPasswordAsSecureString("Password:"******"Address:", null, ConsoleColor.Red);

                    if (!string.IsNullOrEmpty(address))
                    {
                        await Spinner.StartAsync("Processing receive payment(s) ...", async spinner =>
                        {
                            this.spinner = spinner;

                            await Task.Delay(500);

                            try
                            {
                                var session = new Session(identifier, password)
                                {
                                    SenderAddress = address
                                };
                                await actorService.ReceivePayment(session);
                            }
                            catch (Exception ex)
                            {
                                logger.LogError($"Message: {ex.Message}\n Stack: {ex.StackTrace}");
                                throw ex;
                            }
                            finally
                            {
                                var transaction       = await walletService.LastTransaction(identifier, password, TransactionType.Receive);
                                var txnReceivedAmount = transaction == null ? 0.ToString() : transaction.Amount.DivWithNaT().ToString("F9");
                                var txnMemo           = transaction == null ? "" : transaction.Memo;
                                var balance           = await walletService.AvailableBalance(identifier, password);

                                spinner.Text = $"Memo: {txnMemo}  Received: {txnReceivedAmount}  Available Balance: {balance.Result.DivWithNaT().ToString("F9")}";
                            }
                        }, Patterns.Toggle3);
                    }
                }
        }
Beispiel #5
0
        public override Task Execute()
        {
            try
            {
                using var identifier = Prompt.GetPasswordAsSecureString("Identifier:", ConsoleColor.Yellow);
                using var passphrase = Prompt.GetPasswordAsSecureString("Passphrase:", ConsoleColor.Yellow);

                var session = _walletService.SessionAddOrUpdate(new Session(identifier, passphrase));
                var total   = _walletService.AvailableBalance(session.SessionId);

                _console.ForegroundColor = ConsoleColor.Green;
                _console.WriteLine($"\nBalance: {total.Result.DivWithNaT():F9}\n");
                _console.ForegroundColor = ConsoleColor.White;
            }
            catch (Exception)
            {
                throw;
            }

            return(Task.CompletedTask);
        }
        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);
            }
        }
Beispiel #7
0
        public async Task <IActionResult> WalletBalance([FromBody] CredentialsDto credentials)
        {
            var total = await walletService.AvailableBalance(credentials.Identifier.ToSecureString(), credentials.Password.ToSecureString());

            return(new OkObjectResult(new { balance = total }));
        }
Beispiel #8
0
        /// <summary>
        /// Receives payment from redemption key.
        /// </summary>
        /// <returns>The payment redemption key.</returns>
        /// <param name="cypher">Cypher.</param>
        public async Task <TaskResult <bool> > ReceivePaymentRedemptionKey(Session session, string cypher)
        {
            Guard.Argument(session, nameof(session)).NotNull();
            Guard.Argument(cypher, nameof(cypher)).NotNull().NotEmpty();

            session           = SessionAddOrUpdate(session);
            session.LastError = null;

            try
            {
                bool TestFromAddress() => Util.FormatNetworkAddress(DecodeAddress(session.SenderAddress).ToArray()) != null;

                if (TestFromAddress().Equals(false))
                {
                    return(TaskResult <bool> .CreateFailure(JObject.FromObject(new
                    {
                        success = false,
                        message = "Failed to read the recipient public key!"
                    })));
                }

                await SetSecretKey(session.SessionId);

                var pk      = Util.FormatNetworkAddress(DecodeAddress(session.SenderAddress).ToArray());
                var message = JObject.Parse(cypher).ToObject <MessageDto>();
                var rmsg    = ReadMessage(session.SecretKey, message.Body, pk);

                ParseMessage(rmsg, out bool isPayment, out string store);

                var previousBal = await walletService.AvailableBalance(session.Identifier, session.MasterKey);

                var payment = await Payment(session.SessionId, store);

                if (payment)
                {
                    var availableBal = await walletService.AvailableBalance(session.Identifier, session.MasterKey);

                    var transaction = await walletService.LastTransaction(session.Identifier, session.MasterKey, TransactionType.Receive);

                    return(TaskResult <bool> .CreateSuccess(JObject.FromObject(new
                    {
                        success = true,
                        message = new
                        {
                            previous = previousBal,
                            memo = transaction.Memo,
                            received = transaction.Amount,
                            available = availableBal
                        }
                    })));
                }

                return(TaskResult <bool> .CreateFailure(JObject.FromObject(new
                {
                    success = false,
                    message = new
                    {
                        available = previousBal
                    }
                })));
            }
            catch (Exception ex)
            {
                logger.LogError($"Message: {ex.Message}\n Stack: {ex.StackTrace}");
                return(TaskResult <bool> .CreateFailure(ex));
            }
        }
Beispiel #9
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 (double.TryParse(amount, out double 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.CreatePayment(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.AvailableBalance(session.SessionId);
                        var message = $"Available Balance: {balance.Result.DivWithNaT():F9}";

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

                        spinner.Succeed(message);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.StackTrace);
                        throw;
                    }
                }, Patterns.Toggle3);
            }
        }