Example #1
0
        /// <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;
        }
Example #2
0
        /// <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);
        }