Beispiel #1
0
        public long Insert(TokenTransaction cust)
        {
            using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
            {
                sqlConnection.Open();

                var _customer = new TokenTransaction()
                {
                    GUID            = Guid.NewGuid().ToString(),
                    RECORD_STATUS   = 1,
                    INSERT_DATE     = DateTime.Now,
                    INSERT_USER     = cust.INSERT_USER,
                    UPDATE_DATE     = DateTime.Now,
                    UPDATE_USER     = cust.UPDATE_USER,
                    CUSTOMER_NUMBER = cust.CUSTOMER_NUMBER,
                    TOKEN           = cust.TOKEN
                };

                var customerGuid = sqlConnection.Insert <TokenTransaction>(_customer);

                sqlConnection.Close();

                return(customerGuid);
            }
        }
        public async Task <IEnumerable <ErcAddressHistoryModel> > GetTokenHistory(TokenTransaction addressTransactions)
        {
            var transactionResponseRaw = await _ethereumSamuraiApi.ApiErc20TransferHistoryGetErc20TransfersPostAsync(
                new GetErc20TransferHistoryRequest(addressTransactions.Address, null, new List <string>()
            {
                addressTransactions.TokenAddress
            }),
                addressTransactions.Start,
                addressTransactions.Count);

            List <ErcAddressHistoryModel> result = MapErcHistoryFromResponse(transactionResponseRaw);

            return(result);
        }
Beispiel #3
0
        public async Task <IActionResult> Payment(string bagName)
        {
            User loggedInUser = await this.userManager.GetUserAsync(base.User);

            int idBag       = 0;
            int tokenAmount = 0;

            switch (bagName)
            {
            case "4.99":
            {
                idBag       = 1;
                tokenAmount = 5;
            }
            break;

            case "9.99":
            {
                idBag       = 2;
                tokenAmount = 10;
            }
            break;

            case "17.99":
            {
                idBag       = 3;
                tokenAmount = 20;
            }
            break;
            }

            TokenTransaction transaction = new TokenTransaction()
            {
                bagId        = idBag,
                userId       = loggedInUser.Id,
                purchaseDate = DateTime.Now,
            };

            await this.context.TokenTransactions.AddAsync(transaction);

            await this.context.SaveChangesAsync();

            loggedInUser.tokens += tokenAmount;
            await this.userManager.UpdateAsync(loggedInUser);

            await signInManager.RefreshSignInAsync(loggedInUser);

            return(Json(true));
        }
Beispiel #4
0
        public bool Delete(TokenTransaction cust)
        {
            try
            {
                using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
                {
                    sqlConnection.Open();
                    sqlConnection.Delete <TokenTransaction>(cust);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #5
0
        public static bool checkToken(string token, long customerNumber)
        {
            tokenTransactionService = new TokenTransactionService();
            byte[]   data = Convert.FromBase64String(token);
            DateTime when = DateTime.FromBinary(BitConverter.ToInt64(data, 0));

            if (when < DateTime.UtcNow.AddMinutes(-4))
            {
                TokenTransaction tt = new TokenTransaction();
                tt = tokenTransactionService.SelectByCustomerNumber(customerNumber);

                tokenTransactionService.Delete(tt);

                return(false);
            }

            return(true);
        }
Beispiel #6
0
        public static string CreateToken(long customerNumber)
        {
            tokenTransactionService = new TokenTransactionService();
            byte[] time  = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
            byte[] key   = Guid.NewGuid().ToByteArray();
            string token = Convert.ToBase64String(time.Concat(key).ToArray());

            TokenTransaction tt = new TokenTransaction
            {
                INSERT_USER     = "******",
                UPDATE_USER     = "******",
                CUSTOMER_NUMBER = customerNumber,
                TOKEN           = token
            };

            tokenTransactionService.Insert(tt);

            return(token);
        }
Beispiel #7
0
        public TokenTransaction SelectByCustomerNumber(long customerNumber)
        {
            TokenTransaction _customer = null;

            using (var sqlConnection = new SqlConnection(Constant.DatabaseConnection))
            {
                sqlConnection.Open();
                IEnumerable <TokenTransaction> customer = sqlConnection.Query <TokenTransaction>("select * from TOKEN_TRANSACTION where CUSTOMER_NUMBER = @id and RECORD_STATUS = 1", new { id = customerNumber });
                if (customer.Count() == 0)
                {
                    throw new Exception(CommonDefinitions.CUSTOMER_NOT_FOUND);
                }
                else
                {
                    _customer = customer.FirstOrDefault();
                }
            }

            return(_customer);
        }
Beispiel #8
0
        public async Task <TokenTransaction> GetTokenData(Web3.Models.DTOs.Transaction transaction, MongoRepository <Token> tokenRepository, MongoRepository <Price> priceRepository)
        {
            var input = transaction.Input;

            if (string.IsNullOrEmpty(input))
            {
                return(null);
            }

            if (input.Length < 10)
            {
                return(null);
            }

            var token = await GetToken(transaction, tokenRepository);

            if (token == null)
            {
                return(null);
            }

            var price = await GetPriceAsync(token, priceRepository);

            var method = GetMethod(input.Substring(0, 10));

            if (string.IsNullOrEmpty(method))
            {
                return(null);
            }

            var parameters = GetParameters(input.Substring(10));

            if (parameters.Length == 0)
            {
                throw new Exception("No parameters found in the input.");
            }

            TokenTransaction tokenTransaction = null;

            switch (method)
            {
            case "approve":
                tokenTransaction = new TokenTransaction()
                {
                    Method          = method,
                    ContractAddress = token.Address,
                    Name            = token.Name,
                    Symbol          = token.Symbol,
                    From            = transaction.From,
                    To       = GetAddressFromInputParameter(parameters[0]),
                    Value    = parameters[1],
                    Decimals = token.Decimals,
                    PriceBtc = price != null ? price.PriceBtc : 0,
                    PriceUsd = price != null ? price.PriceUsd : 0,
                    PriceEur = price != null ? price.PriceEur : 0,
                };
                break;

            case "transfer":
                tokenTransaction = new TokenTransaction()
                {
                    Method          = method,
                    ContractAddress = token.Address,
                    Name            = token.Name,
                    Symbol          = token.Symbol,
                    From            = transaction.From,
                    To       = GetAddressFromInputParameter(parameters[0]),
                    Value    = parameters[1],
                    Decimals = token.Decimals,
                    PriceBtc = price != null ? price.PriceBtc : 0,
                    PriceUsd = price != null ? price.PriceUsd : 0,
                    PriceEur = price != null ? price.PriceEur : 0,
                };
                break;

            case "transferFrom":
                tokenTransaction = new TokenTransaction()
                {
                    Method          = method,
                    ContractAddress = token.Address,
                    Name            = token.Name,
                    Symbol          = token.Symbol,
                    From            = GetAddressFromInputParameter(parameters[0]),
                    To       = GetAddressFromInputParameter(parameters[1]),
                    Value    = parameters[2],
                    Decimals = token.Decimals,
                    PriceBtc = price != null ? price.PriceBtc : 0,
                    PriceUsd = price != null ? price.PriceUsd : 0,
                    PriceEur = price != null ? price.PriceEur : 0,
                };
                break;

            case "sweep":
                tokenTransaction = new TokenTransaction()
                {
                    Method          = method,
                    ContractAddress = GetAddressFromInputParameter(parameters[0]),
                    Name            = token.Name,
                    Symbol          = token.Symbol,
                    From            = transaction.To,
                    To       = transaction.From,
                    Value    = parameters[1],
                    Decimals = token.Decimals,
                    PriceBtc = price != null ? price.PriceBtc : 0,
                    PriceUsd = price != null ? price.PriceUsd : 0,
                    PriceEur = price != null ? price.PriceEur : 0,
                };
                break;

            case "mint":
                tokenTransaction = new TokenTransaction()
                {
                    Method          = method,
                    ContractAddress = token.Address,
                    Name            = token.Name,
                    Symbol          = token.Symbol,
                    From            = token.Address,
                    To       = GetAddressFromInputParameter(parameters[0]),
                    Value    = parameters[1],
                    Decimals = token.Decimals,
                    PriceBtc = price != null ? price.PriceBtc : 0,
                    PriceUsd = price != null ? price.PriceUsd : 0,
                    PriceEur = price != null ? price.PriceEur : 0,
                };
                break;
            }

            return(tokenTransaction);
        }