Beispiel #1
0
        private void btnGenerateEscrowInvitation_Click(object sender, EventArgs e)
        {
            EscrowCodeSet cs = new EscrowCodeSet();

            txtEscrowForPayer.Text = cs.EscrowInvitationCodeA;
            txtEscrowForPayee.Text = cs.EscrowInvitationCodeB;
        }
Beispiel #2
0
        private void btnPayerDone_Click(object sender, EventArgs e)
        {
            if (btnPayerDone.Text == "Reset")
            {
                setPayerElementsVisible(false);
                btnPayerDone.Text = "Done";
                return;
            }


            try {
                txtPayerCode1.Text = Util.Base58Trim(txtPayerCode1.Text);
                txtPayerCode2.Text = Util.Base58Trim(txtPayerCode2.Text);
                EscrowCodeSet cs = new EscrowCodeSet(txtPayerCode1.Text, txtPayerCode2.Text);
                txtPayerAddress.Text = cs.BitcoinAddress;
                setPayerElementsVisible(true);
                btnPayerDone.Text = "Reset";
                if (cs.SamePartyWarningApplies)
                {
                    MessageBox.Show("The Payment Invitation Code appears to have been generated from the same Escrow Invitation Code you entered, " +
                                    "and not its mate.  You might be verifying a Payment Invitation you produced yourself, rather than one " +
                                    "produced by your trading partner.", "Are you verifying the wrong thing?", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
        private void btnPayerDone_Click(object sender, EventArgs e)
        {
            if (btnPayerDone.Text == "Reset") {
                setPayerElementsVisible(false);
                btnPayerDone.Text = "Done";
                return;
            }

            try {
                EscrowCodeSet cs = new EscrowCodeSet(txtPayerCode1.Text, txtPayerCode2.Text);
                txtPayerAddress.Text = cs.BitcoinAddress;
                setPayerElementsVisible(true);
                btnPayerDone.Text = "Reset";
                if (cs.SamePartyWarningApplies) {
                    MessageBox.Show("The Payment Invitation Code appears to have been generated from the same Escrow Invitation Code you entered, " +
                        "and not its mate.  You might be verifying a Payment Invitation you produced yourself, rather than one " +
                        "produced by your trading partner.", "Are you verifying the wrong thing?", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;

            }
        }
        private void btnGenerateEscrowInvitation_Click(object sender, EventArgs e)
        {
            EscrowCodeSet cs = new EscrowCodeSet();

            txtEscrowForPayer.Text = cs.EscrowInvitationCodeA;
            txtEscrowForPayee.Text = cs.EscrowInvitationCodeB;
        }
Beispiel #5
0
 private void btnGenPayee_Click(object sender, EventArgs e)
 {
     try {
         txtPayeeCode.Text = Util.Base58Trim(txtPayeeCode.Text);
         EscrowCodeSet cs = new EscrowCodeSet(txtPayeeCode.Text);
         txtPayeeGeneratedInvite.Text  = cs.PaymentInvitationCode;
         txtPayeeGeneratedAddress.Text = cs.BitcoinAddress;
     } catch (Exception ex) {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         return;
     }
 }
        private void btnRedeem_Click(object sender, EventArgs e)
        {
            try {
                EscrowCodeSet cs = new EscrowCodeSet(txtRedeemCode1.Text, txtRedeemCode2.Text, txtRedeemCode3.Text);
                txtRedeemAddress.Text = cs.BitcoinAddress;
                txtRedeemPrivKey.Text = cs.PrivateKey;
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;

            }
        }
        private void btnGenPayee_Click(object sender, EventArgs e)
        {
            try {
                EscrowCodeSet cs = new EscrowCodeSet(txtPayeeCode.Text);
                txtPayeeGeneratedInvite.Text = cs.PaymentInvitationCode;
                txtPayeeGeneratedAddress.Text = cs.BitcoinAddress;
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;

            }
        }
Beispiel #8
0
        private void btnRedeem_Click(object sender, EventArgs e)
        {
            try {
                txtRedeemCode1.Text = Util.Base58Trim(txtRedeemCode1.Text);
                txtRedeemCode2.Text = Util.Base58Trim(txtRedeemCode2.Text);
                txtRedeemCode3.Text = Util.Base58Trim(txtRedeemCode3.Text);

                EscrowCodeSet cs = new EscrowCodeSet(txtRedeemCode1.Text, txtRedeemCode2.Text, txtRedeemCode3.Text);
                txtRedeemAddress.Text = cs.BitcoinAddress;
                txtRedeemPrivKey.Text = cs.PrivateKey;
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }
Beispiel #9
0
        public HttpResponseMessage Put(string id, EscrowWebCreate form)
        {
            Guid listid;

            if (!string.IsNullOrEmpty(id) && Guid.TryParse(id, out listid))
            {
                Listing list = data.Listings.GetByID(listid);
                if (list != null)
                {
                    if (!form.PubKey.StartsWith("-----BEGIN PUBLIC KEY-----\nMI") ||
                        !form.PubKey.EndsWith("-----END PUBLIC KEY-----"))
                    {
                        ModelState.AddModelError("PubKey", "Invalid public key");
                    }
                    if (list.UserProfile.UserId == WebSecurity.CurrentUserId) // cant buy own item
                    {
                        ModelState.AddModelError("id", "Cannot buy own item");
                    }
                    if (list.ListingAdditions.Any(s => (ListingAdditionType)s.AdditionType == ListingAdditionType.Shipping) &&
                        (!form.ShippingId.HasValue ||
                         !list.ListingAdditions.Where(s => (ListingAdditionType)s.AdditionType == ListingAdditionType.Shipping)
                         .Any(s => s.LAId == form.ShippingId.Value))) // Bad shipping selection
                    {
                        ModelState.AddModelError("ShippingId", "Invalid shipping id");
                    }
                    if ((form.VariationId.HasValue && form.VariationId.Value > -1) &&
                        !list.ListingAdditions.Where(s => (ListingAdditionType)s.AdditionType == ListingAdditionType.SingleSelect)
                        .Any(s => s.LAId == form.VariationId.Value)) // Bad variation
                    {
                        ModelState.AddModelError("VariationId", "Invalid variation id");
                    }

                    if (!ModelState.IsValid)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                    }
                    else
                    {
                        ListingAddition ship = form.ShippingId.HasValue
                            ? list.ListingAdditions.SingleOrDefault(s => s.LAId == form.ShippingId.Value)
                            : null;
                        ListingAddition vari = form.VariationId.HasValue && form.VariationId.Value > -1
                            ? list.ListingAdditions.SingleOrDefault(s => s.LAId == form.VariationId.Value)
                            : null;


                        EscrowCodeSet cs     = new EscrowCodeSet();
                        Escrow        escrow = new Escrow()
                        {
                            EscrowId      = Guid.NewGuid(),
                            BuyerId       = WebMatrix.WebData.WebSecurity.CurrentUserId,
                            SellerId      = list.UserId,
                            BuyerPubkey   = form.PubKey,
                            BuyerPrivkey  = form.EncPrivKey,
                            EicA          = cs.EscrowInvitationCodeA,
                            EicB          = cs.EscrowInvitationCodeB,
                            State         = (int)EscrowState.Created,
                            CreatedDate   = DateTime.Now,
                            ListingId     = list.ListingId,
                            ShippingName  = ship != null ? ship.Name : null,
                            ShippingPrice = ship != null ? ship.Price : new Nullable <decimal>(),
                            VariationName = vari != null ? vari.Name : null
                        };

                        //pubkeymd5 = MD5.Create()
                        //    .ComputeHash(Encoding.UTF8.GetBytes(form.PubKey))
                        //    .Select(x => x.ToString("x2"))
                        //    .Aggregate((i, j) => i + j)

                        try
                        {
                            data.Escrows.Insert(escrow);
                            data.Save();
                            User buyer = data.Users.GetByID(WebMatrix.WebData.WebSecurity.CurrentUserId);


                            string emailBodyText =
                                "<p>User <b>" + buyer.UserName + "</b> wants to purchase your listing for: </p>" +
                                "<p><i>" + escrow.Listing.Title + "</p></i>" +
                                "<p>Click <a href=\"https://anark.it/escrow/\">here</a> to view your transactions</p><br/>" +
                                "<p>You may contact the buyer at <a href=\"mailto:" + buyer.Email + "\">" + buyer.Email + "</a></p>" +
                                "<p>For extra security, ask for the Session Code from the buyer if he has not already emailed it to you.</p>";
                            Globals.SendEmail(list.UserProfile.Email, "You have a purchase request!", emailBodyText);
                        }
                        catch (Exception err)
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Failed to save"));
                        }

                        return(Request.CreateResponse(HttpStatusCode.Created, list.UserProfile.Email));
                    }
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not found"));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not found"));
            }
        }