Exemplo n.º 1
0
        public void OnMixer(HouseTransaction tran)
        {
            // set up randomized partial fund (in partial amounts) from house account to recipient
            //var userAccount = AccountMap[tran.RecipientWallet];

            /*
             * This logic sends creates two small payments to recipients
             * For example, Alice sent 12.5 to Bob
             * House account will send (randomized two payments) 7.5 and 5.0 to Bob's generated account
             *
             */
            double newAmtToTransfer = tran.Amount;

            if (tran.Amount.Equals(tran.TotalAmount))
            {
                int    r          = randomizer.Next(100);
                double multiplier = (double)r / 100;
                newAmtToTransfer = tran.TotalAmount * multiplier;
            }

            lock (_lockHouseAccount)
            {
                _houseAccount -= newAmtToTransfer;
            }
            var tranTime = DateTime.Now;

            var remainingAmount = tran.Amount - newAmtToTransfer;

            if (newAmtToTransfer > 0)
            {
                var mixingFee = Math.Round(_mixingFeeMultiplier * newAmtToTransfer, 4, MidpointRounding.AwayFromZero);
                lock (_lockMixerAccount)
                {
                    _mixerAccount    += mixingFee;
                    newAmtToTransfer -= mixingFee;
                    Log.DebugFormat("Mixing fee charged {0} to recipient {1}", mixingFee, tran.RecipientWallet.UserAccount);
                }
                Log.DebugFormat("Amount {0} transfered from HouseAccount to Recipient {1}", newAmtToTransfer, tran.RecipientWallet.UserAccount);

                var postTran = new Transaction();
                postTran.amount      = newAmtToTransfer.ToString();
                postTran.fromAddress = tran.FromAddress;
                postTran.toAddress   = tran.RecipientWallet.GetRemittanceAddress();
                postTran.timestamp   = tranTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
                requestResponse.SendTransaction(postTran);
            }
            // send fund/amount from house account to generated account
            if (remainingAmount > 0)
            {
                HouseTransaction newTran = new HouseTransaction();
                newTran.Amount          = remainingAmount;
                newTran.TotalAmount     = tran.TotalAmount;
                newTran.FromAddress     = _houseAddress;
                newTran.RecipientWallet = tran.RecipientWallet;
                newTran.Timestamp       = tranTime;
                MixerQueue.Insert(newTran);
            }
        }
Exemplo n.º 2
0
        public void OnNewTransaction(Transaction tran)
        {
            // find generated address from "toAddress" field
            Wallet userWallet = AccountWalletMap[tran.toAddress];

            // return if wallet not found
            if (userWallet == null)
            {
                return;
            }

            // this transaction is created by UI, so ignore it
            if (string.IsNullOrWhiteSpace(tran.fromAddress) || _houseAddress.Equals(tran.fromAddress))
            {
                return;
            }
            // send money to house account
            // increment house account value by adding new coins
            if (Double.TryParse(tran.amount, out Double amt))
            {
                lock (_lockHouseAccount)
                {
                    _houseAccount += amt;
                }
                var tranTime = DateTime.Now;
                Log.DebugFormat("Amount {0} transfered from Sender {1} to HouseAccount", tran.amount, tran.fromAddress);
                var postTran = new Transaction();
                postTran.amount      = tran.amount;
                postTran.fromAddress = tran.fromAddress;  // use srcAddr if sender needs to be unknown on the transaction
                postTran.toAddress   = _houseAddress;
                postTran.timestamp   = tranTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
                requestResponse.SendTransaction(postTran);

                // send fund/amount from house account to generated account
                HouseTransaction newTran = new HouseTransaction();
                newTran.Amount          = amt;
                newTran.TotalAmount     = amt;
                newTran.FromAddress     = _houseAddress;
                newTran.RecipientWallet = userWallet;
                newTran.Timestamp       = tranTime;
                MixerQueue.Insert(newTran);
            }
        }