Ejemplo n.º 1
0
        /// <summary>	Handles the command. </summary>
        ///
        /// <remarks>	Paul, 26/02/2015. </remarks>
        ///
        /// <param name="l">	    The BitsharesLedgerEntry to process. </param>
        /// <param name="handler">	The handler. </param>
        /// <param name="market">   The market. </param>
        ///
        /// <returns>	true if it succeeds, false if it fails. </returns>
        public bool HandleCommand(BitsharesLedgerEntry l, MarketBase handler, MarketRow market, string trxid)
        {
            if (m_adminUsernames.Contains(l.from_account))
            {
                try
                {
                    string[] parts = l.memo.Split(' ');

                    if (l.memo.StartsWith(kSetPricesMemoStart))
                    {
                        HandlePriceSetting(parts, l, handler, market);
                        return(true);
                    }
                    else if (l.memo.StartsWith(kWithdrawMemo))
                    {
                        // process withdrawal
                        if (parts[0] == kWithdrawMemo)
                        {
                            // make sure we didn't already process this transaction!
                            if (!m_dataAccess.IsWithdrawalProcessed(trxid))
                            {
                                decimal       amount = decimal.Parse(parts[1]);
                                CurrenciesRow type   = CurrencyHelpers.FromSymbol(parts[2], m_allCurrencies);
                                string        to;

                                string txid;
                                if (!CurrencyHelpers.IsBitsharesAsset(type))
                                {
                                    to = m_dataAccess.GetStats().bitcoin_withdraw_address;
                                    Debug.Assert(to != null);

                                    txid = m_bitcoin.SendToAddress(to, amount);
                                }
                                else
                                {
                                    to = l.from_account;
                                    BitsharesTransactionResponse response = m_bitshares.WalletTransfer(amount, CurrencyHelpers.ToBitsharesSymbol(type), m_bitsharesAccount, to);
                                    txid = response.record_id;
                                }

                                // log in DB
                                m_dataAccess.InsertWithdrawal(trxid, txid, type.ToString(), amount, to, DateTime.UtcNow);
                            }

                            return(true);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogGeneralException(e.ToString());
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public void IsBitsharesAsset()
        {
            for (int i = 0; i < (int)CurrencyTypesDep.max; i++)
            {
                CurrencyTypesDep type    = (CurrencyTypesDep)i;
                CurrenciesRow    newType = m_currencies[type.ToString()];

                Assert.AreEqual(CurrencyHelpersDep.IsBitsharesAsset(type), CurrencyHelpers.IsBitsharesAsset(newType));
            }
        }
Ejemplo n.º 3
0
        /// <summary>	Creates handler for market. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="UnexpectedCaseException">	Thrown when an Unexpected Case error condition
        ///                                             occurs. </exception>
        ///
        /// <param name="market">	The market. </param>
        ///
        /// <returns>	The new handler for market. </returns>
        MarketBase CreateHandlerForMarket(MarketRow market)
        {
            CurrenciesRow @base, quote;

            CurrencyHelpers.GetBaseAndQuoteFromSymbolPair(market.symbol_pair, m_allCurrencies, out @base, out quote);

            if (CurrencyHelpers.IsBitsharesAsset(@base) && !CurrencyHelpers.IsBitsharesAsset(quote))
            {
                return(new InternalMarket(this, market, m_bitshares, m_bitcoin, m_bitsharesAccount, @base));
            }
            else if (!CurrencyHelpers.IsBitsharesAsset(@base) && CurrencyHelpers.IsBitsharesAsset(quote))
            {
                return(new InternalMarket(this, market, m_bitshares, m_bitcoin, m_bitsharesAccount, @quote));
            }
            else
            {
                throw new UnexpectedCaseException();
            }
        }