示例#1
0
 public void Create(DepositFactory factory)
 {
     Deposit = factory.Invoke(
         location: this
         );
 }
示例#2
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();
            }
        }