Example #1
0
        /// <summary>	Sends the bitcoins to depositor. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="RefundBitsharesException">	Thrown when a Refund Bitshares error condition
        ///                                             occurs. </exception>
        ///
        /// <param name="btcAddress">	The btc address. </param>
        /// <param name="trxId">	    Identifier for the trx. </param>
        /// <param name="amount">	    The amount. </param>
        /// <param name="asset">	    The asset. </param>
        ///
        /// <returns>	A string. </returns>
        protected virtual string SendBitcoinsToDepositor(string btcAddress, string trxId, ulong amount, BitsharesAsset asset,
                                                         string depositAddress, MetaOrderType orderType, bool burnUia)
        {
            // make sure failures after this point dont result in multiple credits
            m_daemon.MarkDespositAsCreditedStart(trxId, depositAddress, m_market.symbol_pair, orderType);

            decimal bitAssetAmount = asset.GetAmountFromLarimers(amount);

            if (bitAssetAmount > m_market.bid_max)
            {
                throw new RefundBitsharesException("Over " + Numeric.SerialisedDecimal(m_market.bid_max) + " " + asset.symbol + "!");
            }

            // get the BTC amount we need to transfer
            decimal btcNoFee;

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

            // when selling, the fee is charged in BTC,
            // the amount recorded in the transaction is the amount of bitAssets sans fee, obv

            decimal fee      = (m_market.bid_fee_percent / 100) * btcNoFee;
            decimal btcTotal = Numeric.TruncateDecimal(btcNoFee - fee, 8);

            // do the transfer
            string txid = m_bitcoin.SendToAddress(btcAddress, btcTotal, "mX: " + orderType + " " + asset.symbol);

            // mark this in our records
            m_daemon.MarkDespositAsCreditedEnd(trxId, txid, MetaOrderStatus.completed, bitAssetAmount, m_market.bid, fee);

            if (burnUia)
            {
                // make sure we were the issuer for this asset before we start burning it!
                BitsharesAccount account = m_bitshares.WalletGetAccount(m_bitsharesAccount);
                if (asset.issuer_id == account.id)
                {
                    m_bitshares.WalletBurn(bitAssetAmount, asset.symbol, m_bitsharesAccount, BurnForOrAgainst.@for, m_bitsharesAccount);
                }
            }

            return(txid);
        }
Example #2
0
 /// <summary>	Gets account from ledger. </summary>
 ///
 /// <remarks>	Paul, 15/01/2015. </remarks>
 ///
 /// <param name="l">	The BitsharesLedgerEntry to process. </param>
 ///
 /// <returns>	The account from ledger. </returns>
 BitsharesAccount GetAccountFromLedger(string fromAccount)
 {
     return(m_bitshares.WalletGetAccount(fromAccount));
 }