public override IPerson GetPerson(params ICardType[][] cardTypesList)
        {
            var mockPerson = new MockPerson();

            foreach (var cardTypes in cardTypesList)
            {
                var wallet = WalletFactory.GetWallet(cardTypes);
                mockPerson.Wallets.Add(wallet);
            }

            return(mockPerson);
        }
Пример #2
0
        private WalletEntity GenerateWallet(WalletFactory _walletFactory, Guid accountId, int idValue, string cryptoCode)
        {
            var wallet = new WalletEntity
            {
                AccountId     = accountId,
                CryptoId      = idValue,
                Balance       = 0M,
                FrozenBalance = 0M,
                Address       = null,
                CryptoCode    = cryptoCode
            };

            return(_walletFactory.Insert(wallet));
        }
Пример #3
0
        public List <string> GetAvailableWallets(int userId)
        {
            var Wallets = Where(p => p.OwnerId == userId);

            var currencies = WalletFactory.GetAllCurrencies();

            foreach (var Wallet in Wallets)
            {
                if (currencies.Contains(Wallet.CurrencyCode.ToLower()))
                {
                    var index = currencies.FindIndex(c => c == Wallet.CurrencyCode.ToLower());
                    currencies.RemoveAt(index);
                }
            }
            return(currencies);
        }
Пример #4
0
        public async Task <IActionResult> CreateWallet([FromBody] WalletForCreateDto walletForListDtos)
        {
            var user = await HttpContext.GetUserAsync(_userManager);

            var wallet = WalletFactory.CreateEmptyWallet(walletForListDtos.CurrencyCode);

            _mapper.Map(walletForListDtos, wallet);
            wallet.OwnerId = user.Id;

            await _repository.Add(wallet);

            await _repository.SaveChangesAsync();

            var walletDto = _mapper.Map <WalletDto>(wallet);

            return(CreatedAtAction(nameof(GetWallet), new { id = walletDto.Id }, walletDto));
        }
        /// <summary>
        /// Function returns Wallet stored in database based on id
        /// </summary>
        /// <returns>IWallet object created based on specified type</returns>
        public IWallet GetWallet(Guid id)
        {
            try
            {
                //using var context = new DbEconomyContext();
                var wallet = context.Wallets
                             .Where(w => !w.Deleted)
                             .Where(w => w.Id == id.ToString())
                             .FirstOrDefault();

                return(wallet.Fill(WalletFactory.GetWallet(new Guid(), new Guid(), (WalletTypes)wallet.Type, string.Empty, false, string.Empty, 0)));
            }
            catch (Exception ex)
            {
                log.Error("Cannot get wallet from Db", ex);
                return(null);
            }
        }
        /// <summary>
        /// Function returns all Wallets stored in database
        /// </summary>
        /// <returns>List of IWallet object created based on specified type</returns>
        public List <IWallet> GetWallets()
        {
            try
            {
                ////using var context = new DbEconomyContext();

                var walllets = new List <IWallet>();

                foreach (var w in context.Wallets.Where(w => !w.Deleted))
                {
                    // todo: add RPC save!!!!!!
                    walllets.Add(w.Fill(WalletFactory.GetWallet(new Guid(), new Guid(), (WalletTypes)w.Type, w.Name, true, w.Host, w.Port)));
                }

                return(walllets);
            }
            catch (Exception ex)
            {
                log.Error("Cannot get wallets list from Db", ex);
                return(null);
            }
        }
        public override async Task <string> UpdateWallet(Guid id, Guid ownerid, string walletName, WalletTypes type, string urlBase, int port, IDbConnectorService dbservice)
        {
            //IDbConnectorService dbservice = new DbConnectorService();

            if (EconomyMainContext.Wallets.TryGetValue(id.ToString(), out var wallet))
            {
                wallet.Name = walletName;
                if (ownerid != Guid.Empty)
                {
                    wallet.Owner = ownerid;
                }
                wallet.Type           = type;
                wallet.BaseURL        = urlBase;
                wallet.ConnectionPort = port;
                Console.WriteLine($"New wallet connection address: {wallet.ConnectionAddress}");

                if (EconomyMainContext.WorkWithDb)
                {
                    if (!dbservice.SaveWallet(wallet))
                    {
                        Console.WriteLine("Cannot save Node to the db!");
                        return("Cannot save Node to the db!");
                    }
                }

                return("OK");
            }
            else
            {
                if (string.IsNullOrEmpty(id.ToString()))
                {
                    id = Guid.NewGuid();
                }

                if (string.IsNullOrEmpty(ownerid.ToString()))
                {
                    ownerid = Guid.NewGuid();
                }

                var wall = WalletFactory.GetWallet(id, ownerid, type, walletName, EconomyMainContext.WorkWithQTRPC, urlBase, port);

                if (wall != null)
                {
                    wall.NewTransaction += Wall_NewTransaction;
                    wall.NewConfirmedTransactionDetailsReceived += WalletHandler_NewTransactionDetailsReceived;

                    EconomyMainContext.Wallets.Add(wall.Id.ToString(), wall);

                    if (EconomyMainContext.WorkWithDb)
                    {
                        if (!dbservice.SaveWallet(wall))
                        {
                            log.Error("Cannot save wallet to the Db!");
                            return("Cannot save wallet to the Db!");
                        }
                    }
                }

                return("OK");
            }
        }
Пример #8
0
        private void MiningReceived(WalletFactory _walletFactory, DepositFactory _depositFactory, WalletStatementFactory _walletStatementFactory, TransactionFactory _transactionFactory,
                                    long requestId, string transactionId, Guid accountId, decimal amount)
        {
            if (RedisHelper.KeyExists(miningReceivedKey + requestId))//防止没写进数据库之前,相同的请求调用
            {
                throw new CommonException(20001, "Error: Repeated requests");
            }

            var excistDeposit = _depositFactory.GetByRequestId(accountId, requestId);

            if (excistDeposit != null)
            {
                throw new CommonException(20001, "Error: Repeated requests");
            }

            RedisHelper.StringSet(miningReceivedKey + requestId, "1", new TimeSpan(0, 0, 30));

            var crypto = new CryptocurrencyDAC().GetByCode("FIII");

            if (crypto == null)
            {
                throw new CommonException(20000, "Error: Invalid cryptocurrency");
            }

            var wallet = _walletFactory.GetByAccountId(accountId, crypto.Id);

            var timestamp = DateTime.UtcNow;

            using (var scope = new TransactionScope())
            {
                if (wallet == null)
                {
                    wallet = GenerateWallet(_walletFactory, accountId, crypto.Id, crypto.Code);
                }

                var deposit = new Deposit
                {
                    AccountId     = accountId,
                    WalletId      = wallet.Id,
                    FromType      = DepositFromType.PosMining,
                    ToAddress     = wallet.Address,
                    Amount        = amount,
                    Status        = TransactionStatus.Confirmed,
                    Timestamp     = timestamp,
                    RequestId     = requestId,
                    OrderNo       = NumberGenerator.GenerateUnixOrderNo(),
                    TransactionId = transactionId,
                    CryptoCode    = crypto.Code
                };
                _depositFactory.Insert(deposit);
                _transactionFactory.Insert(new UserTransaction
                {
                    Id         = Guid.NewGuid(),
                    AccountId  = accountId,
                    CryptoId   = crypto.Id,
                    CryptoCode = crypto.Code,
                    Type       = UserTransactionType.Deposit,
                    DetailId   = deposit.Id.ToString(),
                    Status     = (byte)deposit.Status,
                    Timestamp  = deposit.Timestamp,
                    Amount     = amount,
                    OrderNo    = deposit.OrderNo
                });
                _walletFactory.Increase(wallet.Id, amount);
                //_walletFactory.DecreaseFreeze(wallet.Id, -amount);
                _walletStatementFactory.Insert(new WalletStatement
                {
                    Action        = Entities.UserWalletStatementAction.AwardDeposit,
                    Amount        = amount,
                    Balance       = wallet.Balance + amount,
                    FrozenAmount  = 0,
                    FrozenBalance = wallet.FrozenBalance,
                    Remark        = null,
                    Timestamp     = timestamp,
                    WalletId      = wallet.Id
                });
                scope.Complete();
            }
        }
Пример #9
0
        public int GetAllCurrenciesAmount()
        {
            var amount = WalletFactory.GetAllCurrencies().Count;

            return(amount);
        }
Пример #10
0
        private void AccountMiningConfirmed(int cryptoId, MiningConfirmedModel model, WalletFactory _walletFactory, WalletStatementFactory _walletStatementFactory)
        {
            var wallet = _walletFactory.GetByAccountId(model.AccountId, cryptoId);

            if (wallet == null)
            {
                MiningConfirmedFaild(model, "Wallet is null");
                return;
            }
            if (wallet.FrozenBalance < model.Amount)
            {
                MiningConfirmedFaild(model, "Insufficient frozenbalance");
                return;
            }
            try
            {
                _walletFactory.Unfreeze(wallet.Id, model.Amount);
                _walletStatementFactory.Insert(new WalletStatement
                {
                    Action        = UserWalletStatementAction.AwardDeposit,
                    Amount        = model.Amount,
                    Balance       = wallet.Balance + model.Amount,
                    FrozenAmount  = -model.Amount,
                    FrozenBalance = wallet.FrozenBalance - model.Amount,
                    Remark        = null,
                    Timestamp     = DateTime.UtcNow,
                    WalletId      = wallet.Id
                });
            }
            catch (Exception ex)
            {
                MiningConfirmedFaild(model, (ex.InnerException == null ? ex.Message : ex.InnerException.Message));
            }
        }