public IActionResult CreateTransaction([FromBody] byte[] data) { var payment = MessagePackSerializer.Deserialize <SendPayment>(data); var session = _walletService.SessionAddOrUpdate( new Session(payment.Credentials.Identifier.ToSecureString(), payment.Credentials.Passphrase.ToSecureString()) { SessionType = payment.SessionType, WalletTransaction = new WalletTransaction { Fee = payment.SessionType == SessionType.Coin ? payment.Fee : 0, Payment = payment.Amount, Reward = payment.SessionType == SessionType.Coinstake ? payment.Fee : 0, Memo = payment.Memo, RecipientAddress = payment.Address } }); var walletTransaction = _walletService.CreateTransaction(session.SessionId); if (walletTransaction.Success) { var transaction = _walletService.GetTransaction(session.SessionId); if (transaction != null) { return(new ObjectResult(new { messagepack = transaction.Serialize() })); } } _walletService.RollBackTransaction(session.SessionId); return(new StatusCodeResult(StatusCodes.Status404NotFound)); }
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); } }