예제 #1
0
        public bool ETHDeposit(ETHDepositFormDTO form)
        {
            var authorization = Request.Headers.Authorization;

            if (authorization?.Parameter == null || authorization.Parameter != YJYGlobal.CALLBACK_AUTH_TOKEN)
            {
                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized,
                                                                            "invalid auth token"));
            }

            if (string.IsNullOrWhiteSpace(form.transactionHash) || string.IsNullOrWhiteSpace(form.from) ||
                string.IsNullOrWhiteSpace(form.ethAmount))
            {
                throw new ArgumentOutOfRangeException(nameof(form));
            }

            form.ethAmount       = form.ethAmount.Trim();
            form.transactionHash = form.transactionHash.Trim();
            form.from            = form.from.Trim();
            form.to = form.to.Trim();

            BigInteger bi;
            var        tryParse = BigInteger.TryParse(form.ethAmount, NumberStyles.None, null, out bi);

            if (!tryParse || bi < new BigInteger(0) || bi > (new BigInteger(1e18) * new BigInteger(1e8)))
            {
                throw new ArgumentOutOfRangeException(nameof(form.ethAmount));
            }

            var deposit = FundService.AddETHDeposit(form.transactionHash, form.@from, form.to, form.ethAmount);

            if (deposit == null)
            {
                return(false);
            }

            try
            {
                var fundService = new FundService(db);
                fundService.AddUserBalanceByETHDeposit(deposit.Id);
            }
            catch (Exception e)
            {
                YJYGlobal.LogExceptionAsWarning(e);
            }

            return(true);
        }