public async Task <IActionResult> GenerateUnconfirmedScript([FromBody] MultisigModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault().ErrorMessage)); } var trx = await _transactionRepository.GetByHash(model.Hash); if (trx == null) { return(BadRequest($"Unable to load transaction '{model.Hash}'.")); } var merchant = await _merchantRepository.GetByUser(trx.UserId); if (string.IsNullOrWhiteSpace(merchant.XPubKey)) { return(BadRequest("You can not continue to create a transaction because the seller's xPub key is incorrect.")); } try { var founds = MAD.Deposit(trx.Amount); Tuple <string, string> script = null; script = _bitcoinService.CreateTransactionElectrum( model.XPubKey, merchant.XPubKey, founds.Item1, founds.Item2); if (script != null) { trx.XPubKey = model.XPubKey; trx.UnconfirmedDepositTx = script.Item1; trx.RedeemScript = script.Item2; trx.Status = StatusTransaction.UnconfirmedDeposit; trx.Email = model.Email; await _transactionRepository.Update(trx); } return(Json(new { unconfirmedScript = script?.Item1 })); } catch (Exception e) { _logger.LogError(e, e.Message); return(this.BadRequest("Something bad happened while transaction was created.")); } }
public async Task SendPartiallyWithdrawScript([FromBody] MultisigModel model) { try { await _transactionRepository.SavePartiallyWithdrawScript(model.Hash, model.PartiallySignedScript); var trx = await _transactionRepository.GetByHash(model.Hash); var user = await _userManager.FindByIdAsync(trx.UserId); var message = "Buyer has confirmed withdraw transaction."; await _logRepository.Add(trx.Id, message); await _emailSender.SendEmailTransactionAsync(user.Email, message); } catch (Exception e) { _logger.LogError(e, e.Message); } }