Exemple #1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);


            //di did not injected into WebApiApplication class, I do not know why :(

            //start sync local hot wallets with db
            Task.Run(async() => await new SyncTaskStarter(new WebAppConnectionStringProvider()).StartSync());

            //start sendbtc queue resolve process
            Task.Run(() => SendBtcQueue.Start());
        }
Exemple #2
0
        public void SendBtc([FromBody] SendBtcParams data)
        {
            Debug.WriteLine("call to api/btcsrv/sendbtc");

            try
            {
                if (!Regex.IsMatch(data.toaddress, "[13][a-km-zA-HJ-NP-Z1-9]{25,34}$"))
                {
                    throw new ApplicationException("btc address is not valid");
                }


                var wallets_btcops = _wcops.GetAll().Select(i => new BtcCliOperations(i)).ToArray();

                var task = new Action(() => {
                    foreach (var wbop in wallets_btcops)
                    {
                        try
                        {
                            var tx = wbop.SendToAddress(data.toaddress, data.amount);

                            //TODO: validate tx we got the correct answer

                            Interlocked.Increment(ref send_cnt_calls);

                            Debug.WriteLine($"call to api/btcsrv/sendbtc completed ({send_cnt_calls}-{tx})");

                            break; //exit when send btc w/o error
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.ToString());

                            Debug.WriteLine("call to api/btcsrv/sendbtc failed");
                        }
                    }
                });

                SendBtcQueue.EnqueueTask(task);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }