コード例 #1
0
        public void NewTransactionTest_ChecksIfNewTransactionsAreProperlyHandledAndSavedToList_VerifiesThroughVariablesValues()
        {
            // New transaction is sent manually and checked that the event is raised and the values are the same
            LitecoinClientService litecoinClientService = new LitecoinClientService();

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            bool             eventFired       = false;
            List <Tuple <string, string, decimal, string> > transactionListReceived = new List <Tuple <string, string, decimal, string> >();

            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            List <TransactionSinceBlock> transactionsList = new List <TransactionSinceBlock>();
            TransactionSinceBlock        transaction      = new TransactionSinceBlock();

            transaction.TxId          = "txid123";
            transaction.Address       = "bitcoinaddress123";
            transaction.Amount        = 10;
            transaction.BlockHash     = "blockhash123";
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList.Single().Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList.Single().TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList.Single().Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList.Single().Category, transactionListReceived.Single().Item4, "Category Check");
        }
コード例 #2
0
ファイル: DaemonBase.cs プロジェクト: wildbunny/metaexchange
        /// <summary>	Compute and send the correct amount of bitassets to the depositor
        ///             given the deposit transaction </summary>
        ///
        /// <remarks>	Paul, 22/12/2014. </remarks>
        ///
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	A BitsharesTransactionResponse. </returns>
        protected virtual BitsharesTransactionResponse SendBitAssetsToDepositor(TransactionSinceBlock t)
        {
            // make sure failures after this point do not result in repeated sending
            MarkBitcoinDespositAsCreditedStart(t.TxId);

            if (t.Amount > m_bitcoinDepositLimit)
            {
                throw new RefundBitcoinException("Over " + Numeric.Format2Dps(m_bitcoinDepositLimit) + " BTC!");
            }

            AddressOrAccountName bitsharesAddress = GetBitsharesAddressFromBitcoinDeposit(t);

            BitsharesTransactionResponse bitsharesTrx;
            decimal amount = (1 / m_askPrice) * t.Amount;

            if (bitsharesAddress.m_isAddress)
            {
                bitsharesTrx = m_bitshares.WalletTransferToAddress(amount, m_asset.symbol, m_bitsharesAccount, bitsharesAddress.m_text);
            }
            else
            {
                bitsharesTrx = m_bitshares.WalletTransfer(amount, m_asset.symbol, m_bitsharesAccount, bitsharesAddress.m_text);
            }

            MarkBitcoinDespositAsCreditedEnd(t.TxId, bitsharesTrx.record_id, amount);

            return(bitsharesTrx);
        }
コード例 #3
0
ファイル: MarketBase.cs プロジェクト: wildbunny/metaexchange
        /// <summary>	Refund bitcoin deposit. </summary>
        ///
        /// <remarks>	Paul, 15/01/2015. </remarks>
        ///
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        protected void RefundBitcoinDeposit(TransactionSinceBlock t, string notes, SenderToDepositRow s2d, MetaOrderType orderType)
        {
            m_daemon.MarkTransactionAsRefundedStart(t.TxId, s2d.deposit_address, m_market.symbol_pair, orderType);

            // get public key out of transaction
            string    firstPubKey = GetAllPubkeysFromBitcoinTransaction(t.TxId).First();
            PublicKey pk          = new PublicKey(firstPubKey, m_daemon.m_AddressByteType);

            // refund deposit
            string sentTxid = m_bitcoin.SendToAddress(pk.AddressBase58, t.Amount);

            // mark as such
            m_daemon.MarkTransactionAsRefundedEnd(t.TxId, sentTxid, MetaOrderStatus.refunded, t.Amount, notes);
        }
コード例 #4
0
ファイル: MarketBase.cs プロジェクト: wildbunny/metaexchange
        /// <summary>	Gets bitshares account from bitcoin deposit. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	The bitshares account from bitcoin deposit. </returns>
        protected SenderToDepositRow GetBitsharesAccountFromBitcoinDeposit(TransactionSinceBlock t)
        {
            // look up the deposit address in our map of sender->deposit
            SenderToDepositRow senderToDeposit = m_daemon.m_Database.GetSenderDepositIgnoreReferral(t.Address, m_market.symbol_pair);

            if (senderToDeposit != null)
            {
                return(senderToDeposit);
            }
            else
            {
                return(null);
            }
        }
コード例 #5
0
ファイル: DaemonBase.cs プロジェクト: wildbunny/metaexchange
        /// <summary>	Refund bitcoin deposit. </summary>
        ///
        /// <remarks>	Paul, 15/01/2015. </remarks>
        ///
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        protected virtual void RefundBitcoinDeposit(TransactionSinceBlock t, string notes)
        {
            MarkTransactionAsRefundedStart(t.TxId);

            // get public key out of transaction
            string    firstPubKey = GetAllPubkeysFromBitcoinTransaction(t.TxId).First();
            PublicKey pk          = new PublicKey(firstPubKey, m_addressByteType);

            // refund deposit
            string sentTxid = m_bitcoin.SendToAddress(pk.AddressBase58, t.Amount);

            // mark as such
            MarkTransactionAsRefundedEnd(t.TxId, sentTxid, t.Amount, DaemonTransactionType.bitcoinRefund, notes);
        }
コード例 #6
0
        /// <summary>	Handles the bitcoin deposit described by t. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        public override void HandleBitcoinDeposit(TransactionSinceBlock t)
        {
            SenderToDepositRow s2d = GetBitsharesAccountFromBitcoinDeposit(t);

            if (t.Confirmations >= DaemonBase.kBitcoinConfirms)
            {
                BuyBitAsset(t, s2d);
            }
            else
            {
                // mark this transaction as pending if it doesn't already exist
                if (m_daemon.m_Database.GetTransaction(t.TxId) == null)
                {
                    m_daemon.m_Database.MarkDespositAsCreditedStart(t.TxId, s2d.deposit_address, m_market.symbol_pair, MetaOrderType.buy, MetaOrderStatus.pending);
                }
            }
        }
コード例 #7
0
ファイル: MarketBase.cs プロジェクト: wildbunny/metaexchange
        /// <summary>	Sends a bit assets to depositor. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="RefundBitcoinException">	Thrown when a Refund Bitcoin error condition
        ///                                             occurs. </exception>
        ///
        /// <param name="t">		The TransactionSinceBlock to process. </param>
        /// <param name="asset">	The asset. </param>
        ///
        /// <returns>	A BitsharesTransactionResponse. </returns>
        protected BitsharesTransactionResponse SendBitAssetsToDepositor(TransactionSinceBlock t, BitsharesAsset asset,
                                                                        SenderToDepositRow s2d, MetaOrderType orderType)
        {
            // make sure failures after this point do not result in repeated sending
            m_daemon.MarkDespositAsCreditedStart(t.TxId, s2d.deposit_address, m_market.symbol_pair, orderType, MetaOrderStatus.processing, TransactionPolicy.REPLACE);

            if (t.Amount > m_market.ask_max)
            {
                throw new RefundBitcoinException("Over " + Numeric.SerialisedDecimal(m_market.ask_max) + " " + asset.symbol + "!");
            }

            string  bitsharesAccount = s2d.receiving_address;
            decimal bitAssetAmountNoFee;

            if (m_flipped)
            {
                // they're sending us BTC, not bitAssets because the market is flipped, this is
                // equivelent to the opposite order type, so we have to use bid here
                bitAssetAmountNoFee = t.Amount * m_market.bid;
            }
            else
            {
                bitAssetAmountNoFee = t.Amount / m_market.ask;
            }

            // when buying, the fee is charged in bitAssets,
            // the amount recorded in the transaction is the amount of bitAssets purchased sans fee

            bitAssetAmountNoFee = asset.Truncate(bitAssetAmountNoFee);

            decimal fee         = (m_market.ask_fee_percent / 100) * bitAssetAmountNoFee;
            decimal amountAsset = bitAssetAmountNoFee - fee;

            amountAsset = asset.Truncate(amountAsset);

            BitsharesTransactionResponse bitsharesTrx = SendBitAssets(amountAsset, asset, bitsharesAccount, "mX: " + orderType + " " + asset.symbol);

            m_daemon.MarkDespositAsCreditedEnd(t.TxId, bitsharesTrx.record_id, MetaOrderStatus.completed, bitAssetAmountNoFee, m_market.ask, fee);

            return(bitsharesTrx);
        }
コード例 #8
0
ファイル: DaemonBase.cs プロジェクト: wildbunny/metaexchange
        /// <summary>	Take the given transaction, pull out the first input and get the public key,
        ///             turn that into a bitshares address </summary>
        ///
        /// <remarks>	Paul, 22/12/2014. </remarks>
        ///
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	The bitshares address from bitcoin deposit. </returns>
        protected virtual AddressOrAccountName GetBitsharesAddressFromBitcoinDeposit(TransactionSinceBlock t)
        {
            IEnumerable <string> allPubKeys = GetAllPubkeysFromBitcoinTransaction(t.TxId);

            // this is probably ok to leave out because if the user imports their whole wallet, they will likely
            // have all the PKs they need since bitcoin pregenerates 100 or so of them. worst case the user
            // can re-import their wallet into bitshares to get access to missing transcations

            /*if (allPubKeys.Distinct().Count() > 1)
             * {
             *      // can't handle more than one sender case
             *      throw new MultiplePublicKeysException();
             * }*/

            string          publicKey = allPubKeys.First();
            BitsharesPubKey btsPk     = BitsharesPubKey.FromBitcoinHex(publicKey, m_addressByteType);

            return(new AddressOrAccountName {
                m_text = btsPk.m_Address, m_isAddress = true
            });
        }
コード例 #9
0
        /// <summary>	Buy bit asset. </summary>
        ///
        /// <remarks>	Paul, 16/02/2015. </remarks>
        ///
        /// <param name="t">    The TransactionSinceBlock to process. </param>
        /// <param name="s2d">	The 2D. </param>
        protected virtual void BuyBitAsset(TransactionSinceBlock t, SenderToDepositRow s2d)
        {
            decimal oldAsk = m_market.ask;

            try
            {
                if (m_market.price_discovery)
                {
                    //
                    // adjust prices based on order
                    //

                    decimal informed = t.Amount / m_market.ask_max;
                    m_market.ask = m_prices.GetAskForBuy(informed);
                }

                SendBitAssetsToDepositor(t, m_asset, s2d, MetaOrderType.buy);

                if (m_market.price_discovery)
                {
                    // update database with new prices
                    m_isDirty = true;
                }
            }
            catch (Exception e)
            {
                // lets hear about what went wrong
                m_daemon.LogGeneralException(e.ToString());

                // also lets now ignore this transaction so we don't keep failing
                RefundBitcoinDeposit(t, e.Message, s2d, MetaOrderType.buy);

                // restore this
                m_market.ask = oldAsk;
            }
        }
コード例 #10
0
ファイル: MarketBase.cs プロジェクト: wildbunny/metaexchange
 public abstract void HandleBitcoinDeposit(TransactionSinceBlock t);
コード例 #11
0
        public void PollCnfirmationTest_ChecksIfNewConfirmationsAreProperlyAddedAndEventsAreRaised_VerifiesThroughVariablesValues()
        {
            // New transaction is sent manually and checked that the event is raised and the values are the same
            // Then confirmations are checked and it is made sure that events are being raised properly
            LitecoinClientService litecoinClientService = new LitecoinClientService();

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            bool             eventFired       = false;
            List <Tuple <string, string, decimal, string> > transactionListReceived = new List <Tuple <string, string, decimal, string> >();

            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            List <TransactionSinceBlock> transactionsList = new List <TransactionSinceBlock>();
            TransactionSinceBlock        transaction      = new TransactionSinceBlock();

            transaction.TxId          = "txid123";
            transaction.Address       = "bitcoinaddress123";
            transaction.Amount        = 10;
            transaction.BlockHash     = "blockhash123";
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList.Single().Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList.Single().TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList.Single().Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList.Single().Category, transactionListReceived.Single().Item4, "Category Check");

            string txId = null;
            int    receivedConfirmations = 0;

            eventFired = false;
            manualResetEvent.Reset();
            // Handler for event which is raised when enough confirmations are available
            litecoinClientService.DepositConfirmed += delegate(string transactionId, int confirmations)
            {
                eventFired            = true;
                txId                  = transactionId;
                receivedConfirmations = confirmations;
                manualResetEvent.Set();
            };

            GetTransactionResponse getTransactionResponse = new GetTransactionResponse();

            getTransactionResponse.TxId          = "txid123";
            getTransactionResponse.Confirmations = 7;
            int index = 0;
            List <Tuple <string, int> > depositList = new List <Tuple <string, int> >();
            MethodInfo methodInfo = litecoinClientService.GetType().GetMethod("AddNewConfirmation", BindingFlags.NonPublic |
                                                                              BindingFlags.Instance);

            methodInfo.Invoke(litecoinClientService, new object[] { getTransactionResponse, index, depositList });
            manualResetEvent.WaitOne();

            Assert.IsTrue(eventFired);
            Assert.AreEqual(getTransactionResponse.TxId, txId);
            Assert.AreEqual(getTransactionResponse.Confirmations, receivedConfirmations);
        }
コード例 #12
0
        public void MultipleTransactionsAndPartialConfirmationsTest_CheckIfMultipleTransactionsAndConfirmationsAreAddedAsExpectedToTheList_VerifyThroughCariablesValues()
        {
            // 4 Transactions are sent one after the other, and every time DepositArrived event is raised, its values are checked.
            // When all 4 transactions have been sent, we check the private _pendingTransactions field that it contains exactly
            // the elements that we sent and in the same order
            // Not all transactions are updated to 7 confirmations
            LitecoinClientService litecoinClientService = new LitecoinClientService();

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            bool             eventFired       = false;
            List <Tuple <string, string, decimal, string> > transactionListReceived = new List <Tuple <string, string, decimal, string> >();

            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            List <TransactionSinceBlock> transactionsList = new List <TransactionSinceBlock>();
            TransactionSinceBlock        transaction      = new TransactionSinceBlock();

            transaction.TxId          = "txid1";
            transaction.Address       = "bitcoinaddress1";
            transaction.Amount        = 1;
            transaction.BlockHash     = "blockhash1";
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList[0].Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList[0].TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList[0].Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList[0].Category, transactionListReceived.Single().Item4, "Category Check");

            // Second new transaction
            manualResetEvent.Reset();
            eventFired = false;
            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            transaction               = new TransactionSinceBlock();
            transaction.TxId          = "txid2";
            transaction.Address       = "bitcoinaddress2";
            transaction.Amount        = 2;
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList[1].Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList[1].TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList[1].Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList[1].Category, transactionListReceived.Single().Item4, "Category Check");

            // Third new transaction
            manualResetEvent.Reset();
            eventFired = false;
            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            transaction               = new TransactionSinceBlock();
            transaction.TxId          = "txid3";
            transaction.Address       = "bitcoinaddress3";
            transaction.Amount        = 3;
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList[2].Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList[2].TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList[2].Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList[2].Category, transactionListReceived.Single().Item4, "Category Check");

            // Fourth new transaction
            manualResetEvent.Reset();
            eventFired = false;
            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            transaction               = new TransactionSinceBlock();
            transaction.TxId          = "txid4";
            transaction.Address       = "bitcoinaddress4";
            transaction.Amount        = 4;
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList[3].Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList[3].TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList[3].Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList[3].Category, transactionListReceived.Single().Item4, "Category Check");

            FieldInfo fieldInfo = litecoinClientService.GetType().GetField("_pendingTransactions",
                                                                           BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.IsNotNull(fieldInfo);
            List <Tuple <string, int> > pendingTransactions = fieldInfo.GetValue(litecoinClientService) as List <Tuple <string, int> >;

            Assert.IsNotNull(pendingTransactions);
            Assert.AreEqual(transactionsList[0].TxId, pendingTransactions[0].Item1, "TxId Check");
            Assert.AreEqual(transactionsList[0].Confirmations, pendingTransactions[0].Item2, "Confirmations Check");

            Assert.AreEqual(transactionsList[1].TxId, pendingTransactions[1].Item1, "TxId Check");
            Assert.AreEqual(transactionsList[1].Confirmations, pendingTransactions[1].Item2, "Confirmations Check");

            Assert.AreEqual(transactionsList[2].TxId, pendingTransactions[2].Item1, "TxId Check");
            Assert.AreEqual(transactionsList[2].Confirmations, pendingTransactions[2].Item2, "Confirmations Check");

            Assert.AreEqual(transactionsList[3].TxId, pendingTransactions[3].Item1, "TxId Check");
            Assert.AreEqual(transactionsList[3].Confirmations, pendingTransactions[3].Item2, "Confirmations Check");

            //----------------Confirmations Start----------------------

            // Confirmation on index 0
            eventFired = false;
            manualResetEvent.Reset();
            string txId = null;
            int    receivedConfirmations = 0;

            // Handler for event which is raised when enough confirmations are available
            litecoinClientService.DepositConfirmed += delegate(string transactionId, int confirmations)
            {
                eventFired            = true;
                txId                  = transactionId;
                receivedConfirmations = confirmations;
                manualResetEvent.Set();
            };

            // Create a new TransactionResponse and send to AddNEwConfrimation method
            GetTransactionResponse getTransactionResponse = new GetTransactionResponse();

            getTransactionResponse.TxId          = "txid1";
            getTransactionResponse.Confirmations = 7;
            int index = 0;
            List <Tuple <string, int> > confirmedDeposits = new List <Tuple <string, int> >();
            MethodInfo methodInfo = litecoinClientService.GetType().GetMethod("AddNewConfirmation", BindingFlags.NonPublic |
                                                                              BindingFlags.Instance);

            // Invoke private method AddNewConfirmations and send TransactionResponse, the index of _pendingTransactions list
            // to which to add the confirmation to and the depositList instance that shows confirmedDeposits
            methodInfo.Invoke(litecoinClientService, new object[] { getTransactionResponse, index, confirmedDeposits });
            manualResetEvent.WaitOne();

            Assert.IsTrue(eventFired);
            Assert.AreEqual(getTransactionResponse.TxId, txId);
            Assert.AreEqual(getTransactionResponse.Confirmations, receivedConfirmations);
            Assert.AreEqual(1, confirmedDeposits.Count);

            // Confirmation on index 1
            eventFired = false;
            manualResetEvent.Reset();
            txId = null;
            receivedConfirmations = 0;
            // Handler for event which is raised when enough confirmations are available
            litecoinClientService.DepositConfirmed += delegate(string transactionId, int confirmations)
            {
                eventFired            = true;
                txId                  = transactionId;
                receivedConfirmations = confirmations;
                manualResetEvent.Set();
            };

            // Create a new TransactionResponse and send to AddNEwConfrimation method
            getTransactionResponse               = new GetTransactionResponse();
            getTransactionResponse.TxId          = "txid2";
            getTransactionResponse.Confirmations = 2;
            index = 1;

            // Invoke private method AddNewConfirmations and send TransactionResponse, the index of _pendingTransactions list
            // to which to add the confirmation to and the depositList instance that shows confirmedDeposits
            methodInfo.Invoke(litecoinClientService, new object[] { getTransactionResponse, index, confirmedDeposits });
            manualResetEvent.WaitOne();

            Assert.IsTrue(eventFired);
            Assert.AreEqual(getTransactionResponse.TxId, txId);
            Assert.AreEqual(getTransactionResponse.Confirmations, receivedConfirmations);
            Assert.AreEqual(1, confirmedDeposits.Count);

            // Confirmation on index 2
            eventFired = false;
            manualResetEvent.Reset();
            txId = null;
            receivedConfirmations = 0;
            // Handler for event which is raised when enough confirmations are available
            litecoinClientService.DepositConfirmed += delegate(string transactionId, int confirmations)
            {
                eventFired            = true;
                txId                  = transactionId;
                receivedConfirmations = confirmations;
                manualResetEvent.Set();
            };

            // Create a new TransactionResponse and send to AddNEwConfrimation method
            getTransactionResponse               = new GetTransactionResponse();
            getTransactionResponse.TxId          = "txid3";
            getTransactionResponse.Confirmations = 3;
            index = 2;

            // Invoke private method AddNewConfirmations and send TransactionResponse, the index of _pendingTransactions list
            // to which to add the confirmation to and the depositList instance that shows confirmedDeposits
            methodInfo.Invoke(litecoinClientService, new object[] { getTransactionResponse, index, confirmedDeposits });
            manualResetEvent.WaitOne();

            Assert.IsTrue(eventFired);
            Assert.AreEqual(getTransactionResponse.TxId, txId);
            Assert.AreEqual(getTransactionResponse.Confirmations, receivedConfirmations);
            Assert.AreEqual(1, confirmedDeposits.Count);

            // Confirmation on index 3
            eventFired = false;
            manualResetEvent.Reset();
            txId = null;
            receivedConfirmations = 0;
            // Handler for event which is raised when enough confirmations are available
            litecoinClientService.DepositConfirmed += delegate(string transactionId, int confirmations)
            {
                eventFired            = true;
                txId                  = transactionId;
                receivedConfirmations = confirmations;
                manualResetEvent.Set();
            };

            // Create a new TransactionResponse and send to AddNEwConfrimation method
            getTransactionResponse               = new GetTransactionResponse();
            getTransactionResponse.TxId          = "txid4";
            getTransactionResponse.Confirmations = 7;
            index = 3;

            // Invoke private method AddNewConfirmations and send TransactionResponse, the index of _pendingTransactions list
            // to which to add the confirmation to and the depositList instance that shows confirmedDeposits
            methodInfo.Invoke(litecoinClientService, new object[] { getTransactionResponse, index, confirmedDeposits });
            manualResetEvent.WaitOne();

            Assert.IsTrue(eventFired);
            Assert.AreEqual(getTransactionResponse.TxId, txId);
            Assert.AreEqual(getTransactionResponse.Confirmations, receivedConfirmations);
            Assert.AreEqual(2, confirmedDeposits.Count);

            Assert.AreEqual(transactionsList[0].TxId, pendingTransactions[0].Item1, "Address Check");
            Assert.AreEqual(7, pendingTransactions[0].Item2, "TxId Check");

            Assert.AreEqual(transactionsList[1].TxId, pendingTransactions[1].Item1, "Address Check");
            Assert.AreEqual(2, pendingTransactions[1].Item2, "TxId Check");

            Assert.AreEqual(transactionsList[2].TxId, pendingTransactions[2].Item1, "Address Check");
            Assert.AreEqual(3, pendingTransactions[2].Item2, "TxId Check");

            Assert.AreEqual(transactionsList[3].TxId, pendingTransactions[3].Item1, "Address Check");
            Assert.AreEqual(7, pendingTransactions[3].Item2, "TxId Check");
        }
コード例 #13
0
        public void MultipleTransactionsTest_CheckIfMultipleTransactionsAreAddedAsExpectedToTheList_VerifyThroughCariablesValues()
        {
            // 4 Transactions are sent one after the other, and every time DepositArrived event is raised, its values are checked.
            // When all 4 transactions have been sent, we check the private _pendingTransactions field that it contains exactly
            // the elements theat we sent and in the same order
            LitecoinClientService litecoinClientService = new LitecoinClientService();

            ManualResetEvent manualResetEvent = new ManualResetEvent(false);
            bool             eventFired       = false;
            List <Tuple <string, string, decimal, string> > transactionListReceived = new List <Tuple <string, string, decimal, string> >();

            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            List <TransactionSinceBlock> transactionsList = new List <TransactionSinceBlock>();
            TransactionSinceBlock        transaction      = new TransactionSinceBlock();

            transaction.TxId          = "txid1";
            transaction.Address       = "bitcoinaddress1";
            transaction.Amount        = 1;
            transaction.BlockHash     = "blockhash1";
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList[0].Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList[0].TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList[0].Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList[0].Category, transactionListReceived.Single().Item4, "Category Check");

            // Second new transaction
            manualResetEvent.Reset();
            eventFired = false;
            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            transaction               = new TransactionSinceBlock();
            transaction.TxId          = "txid2";
            transaction.Address       = "bitcoinaddress2";
            transaction.Amount        = 2;
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList[1].Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList[1].TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList[1].Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList[1].Category, transactionListReceived.Single().Item4, "Category Check");

            // Third new transaction
            manualResetEvent.Reset();
            eventFired = false;
            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            transaction               = new TransactionSinceBlock();
            transaction.TxId          = "txid3";
            transaction.Address       = "bitcoinaddress3";
            transaction.Amount        = 3;
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList[2].Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList[2].TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList[2].Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList[2].Category, transactionListReceived.Single().Item4, "Category Check");

            // Fourth new transaction
            manualResetEvent.Reset();
            eventFired = false;
            litecoinClientService.DepositArrived += delegate(string currency, List <Tuple <string, string, decimal, string> > newTransactions)
            {
                eventFired = true;
                transactionListReceived = newTransactions;
                manualResetEvent.Set();
            };
            transaction               = new TransactionSinceBlock();
            transaction.TxId          = "txid4";
            transaction.Address       = "bitcoinaddress4";
            transaction.Amount        = 4;
            transaction.Category      = "receive";
            transaction.Confirmations = 0;
            transactionsList.Add(transaction);
            litecoinClientService.CheckNewTransactions(transactionsList);

            manualResetEvent.WaitOne();
            Assert.IsTrue(eventFired);
            Assert.AreEqual(transactionsList[3].Address, transactionListReceived.Single().Item1, "Address Check");
            Assert.AreEqual(transactionsList[3].TxId, transactionListReceived.Single().Item2, "TxId Check");
            Assert.AreEqual(transactionsList[3].Amount, transactionListReceived.Single().Item3, "Amount Check");
            Assert.AreEqual(transactionsList[3].Category, transactionListReceived.Single().Item4, "Category Check");

            FieldInfo fieldInfo = litecoinClientService.GetType().GetField("_pendingTransactions",
                                                                           BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.IsNotNull(fieldInfo);
            List <Tuple <string, int> > pendingTransactions = fieldInfo.GetValue(litecoinClientService) as List <Tuple <string, int> >;

            Assert.IsNotNull(pendingTransactions);
            Assert.AreEqual(transactionsList[0].TxId, pendingTransactions[0].Item1, "Address Check");
            Assert.AreEqual(transactionsList[0].Confirmations, pendingTransactions[0].Item2, "TxId Check");

            Assert.AreEqual(transactionsList[1].TxId, pendingTransactions[1].Item1, "Address Check");
            Assert.AreEqual(transactionsList[1].Confirmations, pendingTransactions[1].Item2, "TxId Check");

            Assert.AreEqual(transactionsList[2].TxId, pendingTransactions[2].Item1, "Address Check");
            Assert.AreEqual(transactionsList[2].Confirmations, pendingTransactions[2].Item2, "TxId Check");

            Assert.AreEqual(transactionsList[3].TxId, pendingTransactions[3].Item1, "Address Check");
            Assert.AreEqual(transactionsList[3].Confirmations, pendingTransactions[3].Item2, "TxId Check");
        }
コード例 #14
0
        /// <summary>	Gets bitshares address from bitcoin deposit. </summary>
        ///
        /// <remarks>	Paul, 25/01/2015. </remarks>
        ///
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	The bitshares address from bitcoin deposit. </returns>
        protected override AddressOrAccountName GetBitsharesAddressFromBitcoinDeposit(TransactionSinceBlock t)
        {
            // look up the deposit address in our map of sender->deposit
            SenderToDepositRow senderToDeposit = GetSenderDepositFromDeposit(t.Address);

            if (senderToDeposit != null)
            {
                return(new AddressOrAccountName {
                    m_text = senderToDeposit.receiving_address, m_isAddress = false
                });
            }
            else
            {
                return(null);
            }
        }