public ActionResult Index(int id, string addr, decimal amount) { if (Request.IsLocal) { EscrowAccept escrowaccept = data.EscrowAccepts.GetByID(id); Escrow escrow = escrowaccept.Escrow.FirstOrDefault(); if (escrow != null && escrowaccept.EscrowAddress == addr && escrow != null) { escrowaccept.LastAddressBalance = escrowaccept.LastAddressBalance.HasValue ? escrowaccept.LastAddressBalance.Value + amount : amount; data.Save(); Price total = escrow.GetTotal(); decimal balance = (total.BTC - amount); string direction = balance >= 0 ? "<p>Looks like the payment was a little short. Try contacting the buyer and asking them to send the difference. If you cannot come to a resolution, contact support</p>" : "<p>The buyer's balance has been paid, now it's time for you to fill the order!</p>"; string emailBodyText = "<p>The user <a href=\"mailto:" + escrow.UserBuyer.Email + "\">" + escrow.UserBuyer.UserName + "</a> has sent " + amount.FormatNumber() + " BTC to the escrow address for item:</p>" + "<p><i>" + escrow.Listing.Title + "</p></i><br/>" + "<p>Total: " + total.BTC.FormatNumber() + " BTC</p>" + "<p>Paid: " + amount.FormatNumber() + " BTC</p>" + "<p><b>Balance: " + (total.BTC - amount).FormatNumber() + " BTC</b></p><br/>" + direction + "<p>Click <a href=\"" + Url.Action("view", "escrow", new { id = escrow.EscrowId.StringWithoutDashes() }, Request.Url.Scheme) + "\">here</a> to view this transaction</p><br/>"; Globals.SendEmail(escrow.UserSeller.Email, "You've received " + amount.FormatNumber() + " BTC!", emailBodyText); return(Content("Dispatched email to " + escrow.UserBuyer.Email)); } else { return(Content("Bitcoin address does not match!")); } } else { return(Content("Unauthorized")); } }
public HttpResponseMessage Post(Guid id, EscrowWebAccept model) { Escrow escrow = data.Escrows.GetByID(id); Listing list = escrow != null ? escrow.Listing : null; if (list != null && escrow != null && WebSecurity.CurrentUserId == escrow.SellerId) { if (escrow.EscrowAccept != null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } if (!model.PubKey.StartsWith("-----BEGIN PUBLIC KEY-----\nMI") || !model.PubKey.EndsWith("-----END PUBLIC KEY-----")) { ModelState.AddModelError("PubKey", "Invalid public key"); } byte[] hex = Util.Base58CheckToByteArray(model.BitcoinAddr); if (hex == null || hex.Length != 21) { ModelState.AddModelError("BitcoinAddr", "Address is not valid."); } if (!ModelState.IsValid) { Request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } EscrowAccept accept = new EscrowAccept() { AutoReleaseDt = DateTime.Now.AddDays(14), CreatedDate = DateTime.Now, EscrowAddress = model.BitcoinAddr, PinvBuyer = model.PinvEncBuyer, PinvSeller = model.PinvEncSeller, SellerPubkey = model.PubKey, SellerPrivkey = model.EncPrivKey }; escrow.State = (int)EscrowState.Accepted; try { data.EscrowAccepts.Insert(accept); escrow.EscrowAccept = accept; //list.CurrentEscrow = escrow; data.Save(); Thread t = new Thread(new ThreadStart(delegate() { try { AnarkRE.Communication.PipeClient pc = new Communication.PipeClient(); pc.SendData(accept.AcceptId + "," + accept.EscrowAddress); } catch (Exception err) { Globals.WriteError("pipeerror.log", err); } })); t.IsBackground = true; t.Start(); try { string emailBodyText = "<p>The seller has accepted your request to buy the listing: </p>" + "<p><i>" + escrow.Listing.Title + "</p></i>" + "<p>Click <a href=\"https://anark.it/escrow/view/" + escrow.EscrowId.StringWithoutDashes() + "\">here</a> to view this transaction</p><br/>" + "<p>Upon entering your transaction password, the verified escrow bitcoin address will be shown. Send your payment to this bitcoin address and notify the seller so that he may begin delivery." + "<p>After you have received your order, be sure to log back in and release the funds to the seller.</p>"; Globals.SendEmail(escrow.UserBuyer.Email, "Purchase Request Accepted!", emailBodyText); } catch { } return(Request.CreateResponse(HttpStatusCode.OK, new { })); } catch (Exception err) { Globals.WriteError("accepterror.log", err); return(Request.CreateResponse(HttpStatusCode.BadRequest, "Save failed")); } } return(Request.CreateResponse(HttpStatusCode.NotFound)); }