Exemplo n.º 1
0
        private static async Task <bool> ProcessWithdraw(Withdrawal wd)
        {
            WithdrawInfo result = new WithdrawInfo();

            if (await repository.Contains(wd.HashStr))
            {
                result = await repository.Get(wd.HashStr);
            }
            else
            {
                result.Asset     = wd.Asset;
                result.HashStr   = wd.HashStr;
                result.Timestamp = DateTime.Now;
                await repository.Save(result);
            }

            if (wd.Asset == "BTC")
            {
                result.TxHash = await btcConnector.WithdrawBtc(wd.HashStr, wd.TargetWallet, wd.Size);
            }
            else
            {
                await ethConnector.WithdrawEth(wd.HashStr, wd.TargetWallet, wd.Size, wd.Asset);
            }

            result.Status = WithdrawStatus.Sent;

            withdrwawalDictionary.Add(wd.HashStr, wd);
            await repository.Save(result);

            return(true);
        }
        private async Task<List<WithdrawInfo>> GetWithdraws(NewFilterInput filter)
        {
            var withdraws = new List<WithdrawInfo>();
            var log = await logWithdrawEvent.GetAllChanges<LogWithdrawalEvent>(filter);

            if (log.Count > 0)
            {
                foreach (var d in log)
                {
                    if (assetDictionary.ContainsKey(d.Event.AssetId))
                    {
                        var withdraw = new WithdrawInfo();
                        withdraw.HashStr = d.Event.WithdrawHash;
                        withdraw.TxHash = d.Log.TransactionHash;
                        withdraw.BlockNumber = d.Log.BlockNumber.HexValue;
                        withdraw.Timestamp = DateTime.Now;
                        withdraw.Asset = assetDictionary[d.Event.AssetId];
                        withdraw.Status = WithdrawStatus.Confirmed;
                        withdraws.Add(withdraw);
                    }
                }
            }

            return withdraws;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 申请提现,增加用户总提现
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Add(WithdrawInfo entity)
        {
            int id = 0;

            using (SqlConnection conn = new SqlConnection(connectString))
            {
                conn.Open();
                using (var transaction = conn.BeginTransaction())
                {
                    try
                    {
                        //增加提现申请
                        string sql = @"INSERT INTO [Withdraw]([Distributor_Id],[Amount],[Time],[Status]) VALUES(@Distributor_Id,@Amount,@Time,@Status);
                                SELECT SCOPE_IDENTITY()";
                        id = conn.Query <int>(sql, entity, transaction).Single();
                        if (id > 0)
                        {
                            //增加用户总提现
                            sql = @"UPDATE [Usr] SET [Total_Withdraw]=[Total_Withdraw]+@Withdraw WHERE [Id]=@Distributor_Id";
                            int row = conn.Execute(sql, new { @Withdraw = entity.Amount, @Distributor_Id = entity.Distributor_Id }, transaction);
                            if (row > 0)
                            {
                                transaction.Commit();
                            }
                            else
                            {
                                id = 0;
                                transaction.Rollback();
                            }
                        }
                        else
                        {
                            transaction.Rollback();
                        }
                    }
                    catch (Exception ex)
                    {
                        id = 0;
                        transaction.Rollback();
                    }
                }


                return(id);
            }
        }
Exemplo n.º 4
0
        private static async void WithdrawListener(Miner miner, CryptoConnector connector, string btcSecret, string ethSecret, NodeConfig conf)
        {
            var withdrwawalDictionary = new Dictionary <string, Withdrawal>();
            var ethConnector          = new EthereumOracleConnector(ethSecret, conf.ETHEndpoint, conf.OracleETHAddres);
            var btcConnector          = new BitcoinOracleConnector(conf.Network, conf.BTCEndpoint, btcSecret);

            while (await reader.WaitToReadAsync())
            {
                var chain = await reader.ReadAsync();

                chain = chain.Get(5);
                if (chain != null)
                {
                    foreach (var wd in chain.CurrentBlock.Withdrawals)
                    {
                        try
                        {
                            if (!withdrwawalDictionary.ContainsKey(wd.HashStr) && !(await repository.Contains(wd.HashStr)))
                            {
                                WithdrawInfo result = null;

                                if (wd.Asset == "BTC")
                                {
                                    result = await btcConnector.WithdrawBtc(wd.HashStr, wd.TargetWallet, wd.Size);
                                }
                                else
                                {
                                    result = await ethConnector.WithdrawEth(wd.HashStr, wd.TargetWallet, wd.Size, wd.Asset);
                                }

                                if (result != null)
                                {
                                    withdrwawalDictionary.Add(wd.HashStr, wd);
                                    result.HashStr = wd.HashStr;
                                    await repository.Save(result);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error("Failed to withdrawal... \n" + e.ToString());
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public WithdrawInfo ProcessWithdraw(TransactionInformation transaction)
        {
            try
            {
                var withdraw = new WithdrawInfo();
                withdraw.HashStr     = GetScriptString(transaction.Transaction);
                withdraw.TxHash      = transaction.TransactionId.ToString();
                withdraw.BlockNumber = transaction.Height.ToString();
                withdraw.Timestamp   = DateTime.Now;
                withdraw.Asset       = "BTC";
                lastBlockWithdraws   = transaction.Height;
                return(withdraw);
            }
            catch (Exception e)
            {
                Log.Error("Failed to process withdraw : " + e.ToString());
            }

            return(null);
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = RequestHelper.GetQueryString <int>("ID");
                entity = WithdrawBLL.Read(id);
                //当前分销商
                distributor = UserBLL.Read(entity.Distributor_Id);
                if (entity.Id <= 0 || distributor.Id <= 0)
                {
                    ScriptHelper.Alert("参数错误", RequestHelper.RawUrl);
                }

                entity.UserName = HttpUtility.UrlDecode(distributor.UserName, System.Text.Encoding.UTF8);
                entity.RealName = distributor.RealName;
                entity.Mobile   = distributor.Mobile;

                //审核操作记录
                actions = Withdraw_OperateBLL.ReadListByWithdraw(entity.Id);
            }
        }
Exemplo n.º 7
0
        private async Task <List <WithdrawInfo> > GetWithdraws(NewFilterInput filter)
        {
            var withdraws = new List <WithdrawInfo>();
            var log       = await logWithdrawEvent.GetAllChanges <LogWithdrawalEvent>(filter);

            if (log.Count > 0)
            {
                foreach (var d in log)
                {
                    var withdraw = new WithdrawInfo();
                    withdraw.HashStr     = d.Event.WithdrawHash;
                    withdraw.TxHash      = d.Log.TransactionHash;
                    withdraw.BlockNumber = d.Log.BlockNumber.HexValue;
                    withdraw.Timestamp   = DateTime.Now;
                    withdraw.Asset       = d.Event.Symbol;
                    withdraws.Add(withdraw);
                }
            }

            return(withdraws);
        }
Exemplo n.º 8
0
    public bool TryPassTime(int amount, Effect.DelayLength length, out WithdrawInfo withdrawInfo)
    {
        withdrawInfo = new WithdrawInfo
        {
            nowInWithdraw = _withdrawStarted,
            wasInWithdraw = _withdrawStarted
        };

        if (!_withdrawStarted)
        {
            if (_withdrawDelayLength != length)
            {
                return(false);
            }

            _withdrawDelay -= amount;
            if (_withdrawDelay <= 0)
            {
                _withdrawStarted           = true;
                withdrawInfo.nowInWithdraw = true;
            }
        }
        else
        {
            if (_withdrawLength != length)
            {
                return(false);
            }

            _addictWithdraw -= amount;
            if (_addictWithdraw <= 0)
            {
                withdrawInfo.withdrawEnding = true;
            }
        }

        return(true);
    }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseWithdrawOrderCondition"/>.
 /// </summary>
 protected BaseWithdrawOrderCondition()
 {
     IsWithdraw   = false;
     WithdrawInfo = new WithdrawInfo();
 }
Exemplo n.º 10
0
        public long Withdraw(string currency, decimal volume, WithdrawInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            var request = CreateRequest(Method.POST);

            switch (info.Type)
            {
            case WithdrawTypes.BankWire:
            {
                if (info.BankDetails == null)
                {
                    throw new InvalidOperationException(LocalizedStrings.BankDetailsIsMissing);
                }

                request
                .AddParameter("amount", volume)
                .AddParameter("account_currency", info.BankDetails.Currency.To <string>())
                .AddParameter("name", info.BankDetails.AccountName)
                .AddParameter("IBAN", info.BankDetails.Iban)
                .AddParameter("BIC", info.BankDetails.Bic)
                .AddParameter("address", info.CompanyDetails?.Address)
                .AddParameter("postal_code", info.CompanyDetails?.PostalCode)
                .AddParameter("city", info.CompanyDetails?.City)
                .AddParameter("country", info.CompanyDetails?.Country)
                .AddParameter("type", volume)
                .AddParameter("bank_name", info.BankDetails.Name)
                .AddParameter("bank_address", info.BankDetails.Address)
                .AddParameter("bank_postal_code", info.BankDetails.PostalCode)
                .AddParameter("bank_city", info.BankDetails.City)
                .AddParameter("bank_country", info.BankDetails.Country)
                .AddParameter("currency", currency)
                .AddParameter("comment", info.Comment);

                var     url      = CreateUrl("withdrawal/open");
                dynamic response = MakeRequest <object>(url, ApplySecret(request, url));

                if (response.id == null)
                {
                    throw new InvalidOperationException();
                }

                return((long)response.id);
            }

            case WithdrawTypes.Crypto:
            {
                request
                .AddParameter("amount", volume)
                .AddParameter("address", info.CryptoAddress);

                string methodName;
                string version;

                switch (currency.To <CurrencyTypes>())
                {
                case CurrencyTypes.BTC:
                {
                    methodName = "bitcoin_withdrawal";
                    version    = string.Empty;

                    request
                    .AddParameter("instant", info.Express ? 1 : 0);

                    break;
                }

                case CurrencyTypes.LTC:
                case CurrencyTypes.ETH:
                case CurrencyTypes.BCH:
                case CurrencyTypes.XRP:
                {
                    methodName = $"{currency}_withdrawal".ToLowerInvariant();
                    version    = "v2/";

                    if (!info.Comment.IsEmpty())
                    {
                        request.AddParameter("destination_tag", info.Comment);
                    }

                    break;
                }

                default:
                    throw new NotSupportedException(LocalizedStrings.Str1212Params.Put(currency));
                }

                var     url      = CreateUrl(methodName, version);
                dynamic response = MakeRequest <object>(url, ApplySecret(request, url));

                if (response.id == null)
                {
                    throw new InvalidOperationException();
                }

                return((long)response.id);
            }

            default:
                throw new NotSupportedException(LocalizedStrings.WithdrawTypeNotSupported.Put(info.Type));
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseWithdrawOrderCondition"/>.
 /// </summary>
 protected BaseWithdrawOrderCondition()
 {
     WithdrawInfo = new WithdrawInfo();
 }
Exemplo n.º 12
0
 public static int Add(WithdrawInfo entity)
 {
     return(dal.Add(entity));
 }