Example #1
0
        public override void HandleRequest(RequestContext context, NameValueCollection query)
        {
            var acc       = Database.GetAccount(Convert.ToInt32(query["a"]));
            var passToken = query["b"];

            // verify
            if (String.IsNullOrEmpty(passToken) || !acc.PassResetToken.Equals(passToken))
            {
                context.Respond(Program.Resources.ChangePass.GetResetErrorHtml());
                return;
            }

            // change password
            var password = CreatePassword(new Random().Next(8, 12));

            Database.ChangePassword(acc.UUID, password);

            // reset token
            acc.PassResetToken = "";
            acc.FlushAsync();

            // send email with pass
            var apikey  = Program.Config.serverSettings.sendGridApiKey;
            var sg      = new SendGrid.SendGridAPIClient(apikey);
            var from    = new Email("*****@*****.**", "Valor");
            var subject = "New Password on Valor";
            var to      = new Email(acc.UUID);
            var content = new Content("text/plain", Program.Resources.ChangePass.GetResetEmail(password));
            var mail    = new Mail(from, subject, to, content);

            sg.client.mail.send.post(requestBody: mail.Get());

            // return html page
            context.Respond(Program.Resources.ChangePass.GetResetHtml(password));
        }
Example #2
0
        /// <summary>	Executes the push fee collection action. </summary>
        ///
        /// <remarks>	Paul, 06/03/2015. </remarks>
        ///
        /// <param name="ctx">      The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        Task OnPushFeeCollection(RequestContext ctx, IDummy dummy)
        {
            if (ConfirmDaemon(ctx, dummy))
            {
                long oldRow = m_Database.CountFeeRows();

                List <FeeCollectionRow> allFees = JsonSerializer.DeserializeFromString <List <FeeCollectionRow> >(ctx.Request.Body);

                try
                {
                    dummy.m_database.BeginTransaction();

                    foreach (FeeCollectionRow fee in allFees)
                    {
                        dummy.m_database.InsertFeeTransaction(fee.symbol_pair,
                                                              fee.buy_trxid,
                                                              fee.sell_trxid,
                                                              fee.buy_fee,
                                                              fee.sell_fee,
                                                              fee.transaction_processed_uid,
                                                              fee.exception,
                                                              fee.start_txid,
                                                              fee.end_txid,
                                                              true);
                    }

                    dummy.m_database.EndTransaction();

                    long newRows = m_Database.CountFeeRows();

                    if (newRows > oldRow)
                    {
                        // here we should process the fees
                        FeeReporting(allFees);
                    }

                    ctx.Respond <bool>(true);
                }
                catch (Exception)
                {
                    dummy.m_database.RollbackTransaction();

                    ctx.Respond <bool>(false);

                    throw;
                }
            }
            else
            {
                ctx.Respond <bool>(false);
            }

            return(null);
        }
Example #3
0
        /// <summary>	Executes the push market action. </summary>
        ///
        /// <remarks>	Paul, 19/02/2015. </remarks>
        ///
        /// <param name="ctx">      The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        Task OnPushMarket(RequestContext ctx, IDummy dummy)
        {
            if (ConfirmDaemon(ctx, dummy))
            {
                MarketRow market = JsonSerializer.DeserializeFromString <MarketRow>(ctx.Request.Body);
                dummy.m_database.UpdateMarketInDatabase(market);
                ctx.Respond <bool>(true);
            }
            else
            {
                ctx.Respond <bool>(false);
            }

            return(null);
        }
Example #4
0
        /// <summary>	Executes the produce report action. </summary>
        ///
        /// <remarks>	Paul, 14/03/2015. </remarks>
        ///
        /// <param name="ctx">      The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        public Task OnProduceReport(RequestContext ctx, T dummy)
        {
            uint   sinceTid = RestHelpers.GetQueryArg <uint, ApiExceptionMissingParameter>(ctx, WebForms.kSince);
            string market   = RestHelpers.GetQueryArg <string>(ctx, WebForms.kSymbolPair);

            MarketRow m = m_database.GetMarket(market);

            if (m == null)
            {
                throw new ApiExceptionUnknownMarket(market);
            }

            List <TransactionsRow> allTrans = m_database.GetCompletedTransactionsInMarketSince(market, sinceTid);

            StringWriter stream = new StringWriter();

            stream.WriteLine("All completed transactions in market " + market + " since tid " + sinceTid + "<br/>");
            stream.WriteLine("<br/>");
            stream.WriteLine("Tid, Type, Price, Amount, Fee, Date<br/>");
            foreach (TransactionsRow t in allTrans)
            {
                stream.WriteLine(t.uid + "," + t.order_type + "," + t.price + "," + t.amount + "," + t.fee + "," + t.date + "<br/>");
            }

            ctx.Respond(stream.ToString(), System.Net.HttpStatusCode.OK);
            return(null);
        }
Example #5
0
        /// <summary>	Executes the push transactions action. </summary>
        ///
        /// <remarks>	Paul, 19/02/2015. </remarks>
        ///
        /// <param name="ctx">      The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        async Task OnPushTransactions(RequestContext ctx, IDummy dummy)
        {
            if (ConfirmDaemon(ctx, dummy))
            {
                string allTrans = ctx.Request.Body;
                if (ctx.Request.m_Truncated)
                {
                    allTrans += await ctx.Request.GetBody(kMb);
                }

                List <TransactionsRow> newTrans = JsonSerializer.DeserializeFromString <List <TransactionsRow> >(allTrans);

                OnPushTransactions(newTrans, dummy.m_database);

                ctx.Respond <bool>(true);
            }
            else
            {
                ctx.Respond <bool>(false);
            }
        }
Example #6
0
        private static void OnError(Exception e, RequestContext rContext)
        {
            Log.Error($"{e.Message}\r\n{e.StackTrace}");

            try
            {
                rContext.Respond("<Error>Internal server error</Error>", 500);
            }
            catch
            {
            }
        }
Example #7
0
        /// <summary>	Executes the get statistics action. </summary>
        ///
        /// <remarks>	Paul, 30/01/2015. </remarks>
        ///
        /// <param name="ctx">      The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        Task OnGetStats(RequestContext ctx, IDummy dummy)
        {
            uint sinceTid = RestHelpers.GetPostArg <uint, ApiExceptionMissingParameter>(ctx, WebForms.kLimit);

            List <TransactionsRow> lastTransactions = m_database.Query <TransactionsRow>("SELECT * FROM transactions WHERE uid>@uid ORDER BY uid;", sinceTid);
            SiteStatsRow           stats            = new SiteStatsRow
            {
                bid_price     = m_bidPrice,
                ask_price     = m_askPrice,
                max_bitassets = m_bitsharesDepositLimit,
                max_btc       = m_bitcoinDepositLimit
            };

            ctx.Respond <StatsPacket>(new StatsPacket {
                m_lastTransactions = lastTransactions, m_stats = stats
            });

            return(null);
        }
Example #8
0
        public override Task Render(RequestContext ctx, StringWriter stream, IDummy authObj)
        {
                        #if MONO
            AddResource(new JsResource(Constants.kWebRoot, "/js/mainPageCompiled.js", true));
                        #endif

            IEnumerable <string> markets = ctx.Request.GetWildcardParameters(2);

            // get any referral partner out of the query args
            int refid = 0;
            if (ctx.Request.QueryArgs.Args.ContainsKey(WebForms.kReferralId))
            {
                int.TryParse((string)ctx.Request.QueryArgs.Args[WebForms.kReferralId], out refid);
            }

            string @base = "", quote = "";
            if (markets.Count() == 2)
            {
                @base = markets.First();
                quote = markets.Last();
            }

            string market = @base + "_" + quote;

            if (authObj.m_database.GetMarket(market) == null)
            {
                ctx.Respond(System.Net.HttpStatusCode.NotFound);
            }

            ImgResource logo = CreateLogo();
            AddResource(logo);

            // render head
            base.Render(ctx, stream, authObj);

            using (new DivContainer(stream, "ng-app", "myApp", "ng-controller", "StatsController", HtmlAttributes.id, "rootId"))
            {
                using (new DivContainer(stream, HtmlAttributes.@class, "jumbotron clearfix no-padding-bottom-top"))
                {
                    using (new DivContainer(stream, HtmlAttributes.@class, "container"))
                    {
                        using (new DivContainer(stream, HtmlAttributes.@class, "row"))
                        {
                            using (new DivContainer(stream, HtmlAttributes.@class, "col-xs-12"))
                            {
                                RenderJumbo(stream, logo);

                                using (new DivContainer(stream, HtmlAttributes.id, "serviceStatusId"))
                                {
                                    SPAN("Market status: ");
                                    SPAN("{{status}}", "", "label label-{{label}}");
                                }

                                /*using (new DivContainer(stream, HtmlAttributes.id, "serviceStatusId"))
                                 * {
                                 *      SPAN("Market status: ");
                                 *      SPAN("{{status}}", "", "label label-{{label}}");
                                 *      HR();
                                 *
                                 *      SPAN("Symbol: ");
                                 *      SPAN("", "assetSymbolId", "label label-success");
                                 *      BR();
                                 *
                                 *      SPAN("Name: ");
                                 *      SPAN("", "assetNameId", "label label-success");
                                 *      BR();
                                 *
                                 *      SPAN("Description: ");
                                 *      SPAN("", "assetDescriptionId", "label label-success");
                                 *      BR();
                                 *
                                 *      SPAN("Supply: ");
                                 *      SPAN("", "assetSupplyId", "label label-success");
                                 *      BR();
                                 *
                                 *      using (new Script(stream, HtmlAttributes.src, "https://api.bitsharesblocks.com/v2/assets/" + @base + "?callback=UpdateAssetDetails"))
                                 *      {
                                 *
                                 *      }
                                 * }*/
                            }
                        }
                    }
                }

                //
                // buy and sell section
                //
                //
                using (new DivContainer(stream, HtmlAttributes.@class, "container"))
                {
                    using (new DivContainer(stream, HtmlAttributes.@class, "row"))
                    {
                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-6"))
                        {
                            Button("Buy {{market.base_symbol}}<br/><span class='badge'>1.00 {{market.quote_symbol}}</span><span class='glyphicon glyphicon-arrow-right arrow'></span><span class='badge'>{{market.buy_quantity | number:3}} {{market.base_symbol}}</span>",
                                   HtmlAttributes.@class, "btn btn-success btn-lg btn-block",
                                   "data-toggle", "collapse",
                                   "aria-expanded", "false",
                                   "aria-controls", "buyId",
                                   "data-target", "#buyId");

                            using (new Panel(stream, "Buy {{market.base_symbol}}", "panel panel-success collapse in", false, "buyId"))
                            {
                                P("Once you enter your BitShares account name, we will generate your deposit address and send your {{market.base_symbol}} to you after 1 confirmation.");

                                using (var fm = new FormContainer(stream, HtmlAttributes.method, "post",
                                                                  HtmlAttributes.ajax, true,
                                                                  HtmlAttributes.handler, "OnSubmitAddressBts",
                                                                  HtmlAttributes.action, Routes.kSubmitAddress))
                                {
                                    using (new DivContainer(stream, HtmlAttributes.@class, "form-group"))
                                    {
                                        fm.Label(stream, "Where shall we send your {{market.base_symbol}}?");

                                        fm.Input(stream, HtmlAttributes.type, InputTypes.hidden,
                                                 HtmlAttributes.name, WebForms.kOrderType,
                                                 HtmlAttributes.value, MetaOrderType.buy.ToString());

                                        fm.Input(stream, HtmlAttributes.type, InputTypes.hidden,
                                                 HtmlAttributes.name, WebForms.kReferralId,
                                                 HtmlAttributes.value, refid);

                                        fm.Input(stream, HtmlAttributes.type, InputTypes.hidden,
                                                 HtmlAttributes.name, WebForms.kSymbolPair,
                                                 HtmlAttributes.value, market);

                                        using (new DivContainer(stream, HtmlAttributes.@class, "input-group"))
                                        {
                                            fm.Input(stream, HtmlAttributes.type, InputTypes.text,
                                                     HtmlAttributes.name, WebForms.kReceivingAddress,
                                                     HtmlAttributes.minlength, 1,
                                                     HtmlAttributes.maxlength, 63,
                                                     HtmlAttributes.required, true,
                                                     HtmlAttributes.id, "bitsharesBlurId",
                                                     HtmlAttributes.@class, "form-control submitOnBlur",
                                                     HtmlAttributes.placeholder, "BitShares account name");

                                            using (new Span(stream, HtmlAttributes.@class, "input-group-btn"))
                                            {
                                                Button("Submit", HtmlAttributes.@class, "btn btn-info");
                                            }
                                        }
                                    }

                                    Alert("", "alert alert-danger", "bitsharesErrorId", true);
                                }

                                using (var fm = new FormContainer(stream))
                                {
                                    using (new DivContainer(stream, HtmlAttributes.@class, "form-group has-success unhideBtsId"))
                                    {
                                        fm.Label(stream, "Your bitcoin deposit address");
                                        fm.Input(stream, HtmlAttributes.type, InputTypes.text,
                                                 HtmlAttributes.id, "bitcoinDespositId",
                                                 HtmlAttributes.@class, "form-control",
                                                 HtmlAttributes.@readonly, "readonly",
                                                 HtmlAttributes.style, "cursor:text;");
                                    }

                                    Button("Click to generate QR code", HtmlAttributes.@class, "btn btn-warning btn-xs pull-right unhideBtsId",
                                           HtmlAttributes.onclick, "GenerateQrModal()");
                                    SPAN("Maximum {{market.ask_max | number:8}} {{market.quote_symbol}} per transaction", "maxBtcId", "label label-info");
                                }
                            }
                        }
                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-6"))
                        {
                            Button("Sell {{market.base_symbol}}<br/><span class='badge'>{{market.sell_quantity | number:3}} {{market.base_symbol}}</span><span class='glyphicon glyphicon-arrow-right arrow'></span><span class='badge'>1.00 {{market.quote_symbol}}</span>", HtmlAttributes.@class, "btn btn-danger btn-lg btn-block",
                                   "data-toggle", "collapse",
                                   "aria-expanded", "false",
                                   "aria-controls", "sellId",
                                   "data-target", "#sellId");

                            using (new Panel(stream, "Sell {{market.base_symbol}}", "panel panel-danger collapse in", false, "sellId"))
                            {
                                P("Once you enter your bitcoin receiving address, we will generate your deposit address and send your bitcoins to you the instant we receive your {{market.base_symbol}}.");

                                using (var fm = new FormContainer(stream, HtmlAttributes.method, "post",
                                                                  HtmlAttributes.ajax, true,
                                                                  HtmlAttributes.action, Routes.kSubmitAddress,
                                                                  HtmlAttributes.handler, "OnSubmitAddressBtc"))
                                {
                                    fm.Input(stream, HtmlAttributes.type, InputTypes.hidden,
                                             HtmlAttributes.name, WebForms.kOrderType,
                                             HtmlAttributes.value, MetaOrderType.sell.ToString());

                                    fm.Input(stream, HtmlAttributes.type, InputTypes.hidden,
                                             HtmlAttributes.name, WebForms.kReferralId,
                                             HtmlAttributes.value, refid);

                                    fm.Input(stream, HtmlAttributes.type, InputTypes.hidden,
                                             HtmlAttributes.id, "symbolPairId",
                                             HtmlAttributes.name, WebForms.kSymbolPair,
                                             HtmlAttributes.value, market);

                                    using (new DivContainer(stream, HtmlAttributes.@class, "form-group"))
                                    {
                                        fm.Label(stream, "Where shall we send your bitcoins?");
                                        using (new DivContainer(stream, HtmlAttributes.@class, "input-group"))
                                        {
                                            fm.Input(stream, HtmlAttributes.type, InputTypes.text,
                                                     HtmlAttributes.name, WebForms.kReceivingAddress,
                                                     HtmlAttributes.minlength, 25,
                                                     HtmlAttributes.maxlength, 34,
                                                     HtmlAttributes.required, true,
                                                     HtmlAttributes.id, "bitcoinBlurId",
                                                     HtmlAttributes.@class, "form-control submitOnBlur",
                                                     HtmlAttributes.placeholder, "Bitcoin address from your wallet");

                                            using (new Span(stream, HtmlAttributes.@class, "input-group-btn"))
                                            {
                                                Button("Submit", HtmlAttributes.@class, "btn btn-info");
                                            }
                                        }
                                    }

                                    Alert("", "alert alert-danger", "bitcoinErrorId", true);
                                }

                                using (var fm = new FormContainer(stream))
                                {
                                    using (new DivContainer(stream, HtmlAttributes.@class, "unhideBtcId"))
                                    {
                                        using (new DivContainer(stream, HtmlAttributes.@class, "form-group has-success"))
                                        {
                                            fm.Label(stream, "Your BitShares deposit account");
                                            fm.Input(stream, HtmlAttributes.type, InputTypes.text,
                                                     HtmlAttributes.id, "bitsharesDespositAccountId",
                                                     "ng-model", "sell.sendToAccount",
                                                     HtmlAttributes.@class, "form-control",
                                                     HtmlAttributes.@readonly, "readonly",
                                                     HtmlAttributes.style, "cursor:text;");
                                        }

                                        using (new DivContainer(stream, HtmlAttributes.@class, "form-group has-success"))
                                        {
                                            fm.Label(stream, "Your BitShares deposit memo");
                                            fm.Input(stream, HtmlAttributes.type, InputTypes.text,
                                                     HtmlAttributes.id, "bitsharesMemoId",
                                                     "ng-model", "sell.memo",
                                                     HtmlAttributes.@class, "form-control",
                                                     HtmlAttributes.@readonly, "readonly",
                                                     HtmlAttributes.style, "cursor:text;");
                                        }
                                    }

                                    Button("Click to generate transaction", HtmlAttributes.@class, "btn btn-warning btn-xs pull-right unhideBtcId",
                                           HtmlAttributes.onclick, "GenerateTransactionModal()");
                                    SPAN("Maximum {{market.bid_max | number:8}} {{market.base_symbol}} per transaction", "maxbitBtcId", "label label-info pull-left");
                                }
                            }
                        }
                    }
                }

                //
                // bullet points
                //

                using (new DivContainer(stream, HtmlAttributes.@class, "container",
                                        HtmlAttributes.style, "margin-top:20px"))
                {
                    using (new DivContainer(stream, HtmlAttributes.@class, "row"))
                    {
                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-4"))
                        {
                            H4("<i class=\"glyphicon glyphicon-ok text-info\"></i>  No registration required");
                            P("There is no need to register an account, just tell us where you'd like to receive the coins that you buy or sell.");
                        }

                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-4"))
                        {
                            H4("<i class=\"glyphicon glyphicon-flash text-info\"></i>  Fast transactions");
                            P("Only one confirmation is neccessary for buying or selling, which is around 7 minutes for a buy and around 3 seconds for a sell.");
                        }

                        using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-4"))
                        {
                            H4("<i class=\"glyphicon glyphicon-lock text-info\"></i>  Safe");
                            P("We don't hold any of our customer's funds, so there is nothing to get lost or stolen.");
                        }
                    }
                }

                using (new DivContainer(stream, HtmlAttributes.@class, "bg-primary hidden-xs",
                                        HtmlAttributes.style, "margin-top:20px"))
                {
                    using (new DivContainer(stream, HtmlAttributes.@class, "container"))
                    {
                        using (new DivContainer(stream, HtmlAttributes.style, "margin:30px 0px 30px 0px"))
                        {
                            using (new DivContainer(stream, HtmlAttributes.@class, "row unhideBtsId unhideBtcId",
                                                    HtmlAttributes.id, "myTransactionsId"))
                            {
                                using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-12"))
                                {
                                    H3("Your transactions");

                                    using (new Table(stream, "", 4, 4, "table noMargin", "Market", "Type", "Price", "Amount", "Fee", "Date", "Status", "Notes", "Inbound Tx", "Outbound Tx"))
                                    {
                                        using (var tr = new TR(stream, "ng-repeat", "t in myTransactions"))
                                        {
                                            tr.TD("{{renameSymbolPair(t.symbol_pair)}}");
                                            tr.TD("{{t.order_type}}");
                                            tr.TD("{{t.price}}");
                                            tr.TD("{{t.amount}}");
                                            tr.TD("{{t.fee}}");
                                            tr.TD("{{t.date*1000 | date:'MMM d, HH:mm'}}");
                                            tr.TD("{{t.status}}");
                                            tr.TD("{{t.notes}}");
                                            tr.TD("<a ng-if=\"t.order_type=='" + MetaOrderType.buy + "'\" target=\"_blank\" ng-href=\"https://blockchain.info/tx/{{t.received_txid}}\">Look up</a>" +
                                                  "<a ng-if=\"t.order_type=='" + MetaOrderType.sell + "'\" target=\"_blank\" ng-href=\"http://bitsharesblocks.com/blocks/block?trxid={{t.received_txid}}\">Look up</a>");

                                            tr.TD("<a ng-if=\"t.order_type=='" + MetaOrderType.buy + "' && t.status == '" + MetaOrderStatus.completed + "'\" target=\"_blank\" ng-href=\"http://bitsharesblocks.com/blocks/block?trxid={{t.sent_txid}}\">Look up</a>" +
                                                  "<a ng-if=\"t.order_type=='" + MetaOrderType.buy + "' && t.status == '" + MetaOrderStatus.refunded + "'\" target=\"_blank\" ng-href=\"https://blockchain.info/tx/{{t.sent_txid}}\">Look up</a>" +
                                                  "<a ng-if=\"t.order_type=='" + MetaOrderType.sell + "' && t.status == '" + MetaOrderStatus.completed + "'\" target=\"_blank\" ng-href=\"https://blockchain.info/tx/{{t.sent_txid}}\">Look up</a>" +
                                                  "<a ng-if=\"t.order_type=='" + MetaOrderType.sell + "' && t.status == '" + MetaOrderStatus.refunded + "'\" target=\"_blank\" ng-href=\"http://bitsharesblocks.com/blocks/block?trxid={{t.sent_txid}}\">Look up</a>");
                                        }
                                    }
                                }
                            }

                            using (new DivContainer(stream, HtmlAttributes.@class, "unhideBtsId unhideBtcId"))
                            {
                                HR();
                            }

                            using (new DivContainer(stream, HtmlAttributes.@class, "row"))
                            {
                                using (new DivContainer(stream, HtmlAttributes.@class, "col-sm-12"))
                                {
                                    H3("Recent {{renameSymbolPair(market.symbol_pair)}} transactions");

                                    using (new Table(stream, "", 4, 4, "table noMargin", "Market", "Type", "Price", "Amount", "Fee", "Date"))
                                    {
                                        using (var tr = new TR(stream, "ng-repeat", "t in transactions"))
                                        {
                                            tr.TD("{{renameSymbolPair(t.symbol_pair)}}");
                                            tr.TD("{{t.order_type}}");
                                            tr.TD("{{t.price}}");
                                            tr.TD("{{t.amount}}");
                                            tr.TD("{{t.fee}}");
                                            tr.TD("{{t.date*1000 | date:'MMM d, HH:mm'}}");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                Modal("Generate BitShares transaction", "bitsharesModalId", () =>
                {
                    using (var fm = new FormContainer(stream))
                    {
                        using (new DivContainer(stream, HtmlAttributes.@class, "form-group"))
                        {
                            fm.Label(stream, "Sending amount");

                            using (new DivContainer(stream, HtmlAttributes.@class, "input-group"))
                            {
                                fm.Input(stream, HtmlAttributes.type, InputTypes.number,
                                         HtmlAttributes.name, "amount",
                                         HtmlAttributes.@class, "form-control",
                                         HtmlAttributes.required, true,
                                         HtmlAttributes.id, "gtxAmountId",
                                         "ng-model", "sell.quantity",
                                         HtmlAttributes.placeholder, "bitAsset quantity");

                                SPAN("{{market.base_symbol}}", "", "input-group-addon");
                            }
                        }

                        using (new DivContainer(stream, HtmlAttributes.@class, "form-group"))
                        {
                            fm.Label(stream, "Account name to send from");

                            fm.Input(stream, HtmlAttributes.type, InputTypes.text,
                                     HtmlAttributes.name, "account",
                                     HtmlAttributes.@class, "form-control",
                                     HtmlAttributes.required, true,
                                     HtmlAttributes.id, "gtxAccountId",
                                     "ng-model", "sell.payFrom",
                                     HtmlAttributes.placeholder, "Sending acount");
                        }

                        Href(stream, "Click to open in BitShares",
                             HtmlAttributes.id, "bitsharesLinkId",
                             HtmlAttributes.href, "bts:{{sell.sendToAccount}}/transfer/amount/{{sell.quantity}}/memo/{{sell.memo}}/from/{{sell.payFrom}}/asset/{{(market.base_symbol).TrimStart('bit')}}",
                             HtmlAttributes.style, "display:none",
                             HtmlAttributes.@class, "btn btn-success");
                    }
                }, true, "", "modal", "close", false);

                Modal("Scan for bitcoin address", "qrModalId", () =>
                {
                    using (new DivContainer(stream, "row text-center"))
                    {
                        BaseComponent.IMG(stream, "", HtmlAttributes.@class, "center-block");
                    }
                }, true, "", "modal", "close", false);
            }

            return(null);
        }
Example #9
0
        /// <summary>	Executes the submit address action. </summary>
        ///
        /// <remarks>	Paul, 25/01/2015. </remarks>
        ///
        /// <exception cref="ApiExceptionMessage">		   	Thrown when an API exception message error
        /// 												condition occurs. </exception>
        /// <exception cref="ApiExceptionMissingParameter">	Thrown when an API exception missing
        /// 												parameter error condition occurs. </exception>
        ///
        /// <param name="ctx">  	The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        Task OnSubmitAddress(RequestContext ctx, IDummy dummy)
        {
            CurrencyTypes fromCurrency = RestHelpers.GetPostArg<CurrencyTypes, ApiExceptionMissingParameter>(ctx, WebForms.kFromCurrency);
            CurrencyTypes toCurrency = RestHelpers.GetPostArg<CurrencyTypes, ApiExceptionMissingParameter>(ctx, WebForms.kToCurrency);
            string receivingAddress = RestHelpers.GetPostArg<string, ApiExceptionMissingParameter>(ctx, WebForms.kReceivingAddress);

            SubmitAddressResponse response;

            if (fromCurrency == CurrencyTypes.BTC && toCurrency == CurrencyTypes.bitBTC)
            {
                string accountName = receivingAddress;

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_database.Query<SenderToDepositRow>("SELECT * FROM sender_to_deposit WHERE receiving_address=@s;", accountName).FirstOrDefault();
                if (senderToDeposit == null || !BitsharesWallet.IsValidAccountName(accountName))
                {
                    // no dice, create a new entry

                    // validate bitshares account name
                    try
                    {
                        BitsharesAccount account = m_bitshares.WalletGetAccount(accountName);

                        // generate a new bitcoin address and tie it to this account
                        string depositAdress = m_bitcoin.GetNewAddress();
                        senderToDeposit = InsertSenderToDeposit(account.name, depositAdress);
                    }
                    catch (BitsharesRpcException)
                    {
                        throw new ApiExceptionMessage(accountName + " is not an existing account! Are you sure it is registered?");
                    }
                }

                response = new SubmitAddressResponse { deposit_address = senderToDeposit.deposit_address };
            }
            else if (fromCurrency == CurrencyTypes.bitBTC && toCurrency == CurrencyTypes.BTC)
            {
                string bitcoinAddress = receivingAddress;

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_database.Query<SenderToDepositRow>("SELECT * FROM sender_to_deposit WHERE receiving_address=@s;", bitcoinAddress).FirstOrDefault();
                if (senderToDeposit == null)
                {
                    // validate bitcoin address
                    byte[] check = Util.Base58CheckToByteArray(bitcoinAddress);
                    if (check == null)
                    {
                        throw new ApiExceptionMessage(bitcoinAddress + " is not a valid bitcoin address!");
                    }

                    // generate a memo field to use instead
                    string start = "meta-";
                    string memo = start + bitcoinAddress.Substring(0, BitsharesWallet.kBitsharesMaxMemoLength - start.Length);
                    senderToDeposit = InsertSenderToDeposit(bitcoinAddress, memo);
                }

                response = new SubmitAddressResponse { deposit_address = m_bitsharesAccount, memo = senderToDeposit.deposit_address };
            }
            else
            {
                throw new ApiExceptionUnsupportedTrade(fromCurrency, toCurrency);
            }

            ctx.Respond<SubmitAddressResponse>(response);

            return null;
        }
Example #10
0
        /// <summary>	Executes the get statistics action. </summary>
        ///
        /// <remarks>	Paul, 30/01/2015. </remarks>
        ///
        /// <param name="ctx">  	The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        Task OnGetStats(RequestContext ctx, IDummy dummy)
        {
            uint sinceTid = RestHelpers.GetPostArg<uint, ApiExceptionMissingParameter>(ctx, WebForms.kLimit);

            List<TransactionsRow> lastTransactions = m_database.Query<TransactionsRow>("SELECT * FROM transactions WHERE uid>@uid ORDER BY uid;", sinceTid);
            SiteStatsRow stats =	new SiteStatsRow
                                    {
                                        bid_price = m_bidPrice,
                                        ask_price = m_askPrice,
                                        max_bitassets = m_bitsharesDepositLimit,
                                        max_btc = m_bitcoinDepositLimit
                                    };

            ctx.Respond<StatsPacket>(new StatsPacket { m_lastTransactions = lastTransactions, m_stats = stats });

            return null;
        }
Example #11
0
        public override void HandleRequest(RequestContext context, NameValueCollection query)
        {
            // format id...
            string id;

            try
            {
                var texId = query["id"].Split(':');

                if (texId.Length == 1)
                {
                    id = texId[0];
                }
                else if (texId.Length == 2)
                {
                    id = texId[1];
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                context.Respond("<Error>Invalid input</Error>");
                return;
            }

            // check to see if texture is already loaded first...
            var textures = Program.Resources.Textures;

            if (textures.ContainsKey(id))
            {
                WriteImg(context, textures[id]);
                return;
            }

            context.Respond(404);

            // try to fetch texture from the internet
            // *for testing only. should be disable for production.*

            /*byte[] img;
             * try
             * {
             *  var wLoc = "http://realmofthemadgod.appspot.com/picture/get?id=" + id;
             *  img = new WebClient().DownloadData(wLoc);
             * }
             * catch (Exception e)
             * {
             *  try
             *  {
             *      var wLoc = "http://rotmgtesting.appspot.com/picture/get?id=" + id;
             *      img = new WebClient().DownloadData(wLoc);
             *  }
             *  catch (Exception ee)
             *  {
             *      //Write(context, "<Error>Image not found</Error>");
             *      context.Respond(404);
             *      return;
             *  }
             * }
             * string fLoc = "textures/_" + id + ".png";
             * File.WriteAllBytes(fLoc, img);
             * Program.Resources.AddTexture(id, img);
             * WriteImg(context, img);*/
        }
Example #12
0
        /// <summary>	Executes the submit address action. </summary>
        ///
        /// <remarks>	Paul, 25/01/2015. </remarks>
        ///
        /// <exception cref="ApiExceptionMessage">		    Thrown when an API exception message error
        ///                                                 condition occurs. </exception>
        /// <exception cref="ApiExceptionMissingParameter">	Thrown when an API exception missing
        ///                                                 parameter error condition occurs. </exception>
        ///
        /// <param name="ctx">      The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        Task OnSubmitAddress(RequestContext ctx, IDummy dummy)
        {
            CurrencyTypes fromCurrency     = RestHelpers.GetPostArg <CurrencyTypes, ApiExceptionMissingParameter>(ctx, WebForms.kFromCurrency);
            CurrencyTypes toCurrency       = RestHelpers.GetPostArg <CurrencyTypes, ApiExceptionMissingParameter>(ctx, WebForms.kToCurrency);
            string        receivingAddress = RestHelpers.GetPostArg <string, ApiExceptionMissingParameter>(ctx, WebForms.kReceivingAddress);

            SubmitAddressResponse response;

            if (fromCurrency == CurrencyTypes.BTC && toCurrency == CurrencyTypes.bitBTC)
            {
                string accountName = receivingAddress;

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_database.Query <SenderToDepositRow>("SELECT * FROM sender_to_deposit WHERE receiving_address=@s;", accountName).FirstOrDefault();
                if (senderToDeposit == null || !BitsharesWallet.IsValidAccountName(accountName))
                {
                    // no dice, create a new entry

                    // validate bitshares account name
                    try
                    {
                        BitsharesAccount account = m_bitshares.WalletGetAccount(accountName);

                        // generate a new bitcoin address and tie it to this account
                        string depositAdress = m_bitcoin.GetNewAddress();
                        senderToDeposit = InsertSenderToDeposit(account.name, depositAdress);
                    }
                    catch (BitsharesRpcException)
                    {
                        throw new ApiExceptionMessage(accountName + " is not an existing account! Are you sure it is registered?");
                    }
                }

                response = new SubmitAddressResponse {
                    deposit_address = senderToDeposit.deposit_address
                };
            }
            else if (fromCurrency == CurrencyTypes.bitBTC && toCurrency == CurrencyTypes.BTC)
            {
                string bitcoinAddress = receivingAddress;

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_database.Query <SenderToDepositRow>("SELECT * FROM sender_to_deposit WHERE receiving_address=@s;", bitcoinAddress).FirstOrDefault();
                if (senderToDeposit == null)
                {
                    // validate bitcoin address
                    byte[] check = Util.Base58CheckToByteArray(bitcoinAddress);
                    if (check == null)
                    {
                        throw new ApiExceptionMessage(bitcoinAddress + " is not a valid bitcoin address!");
                    }

                    // generate a memo field to use instead
                    string start = "meta-";
                    string memo  = start + bitcoinAddress.Substring(0, BitsharesWallet.kBitsharesMaxMemoLength - start.Length);
                    senderToDeposit = InsertSenderToDeposit(bitcoinAddress, memo);
                }

                response = new SubmitAddressResponse {
                    deposit_address = m_bitsharesAccount, memo = senderToDeposit.deposit_address
                };
            }
            else
            {
                throw new ApiExceptionUnsupportedTrade(fromCurrency, toCurrency);
            }

            ctx.Respond <SubmitAddressResponse>(response);

            return(null);
        }