Exemplo n.º 1
0
 string SubmitAddress(string receivingAddress, MetaOrderType type, string symbolPair = null)
 {
     if (symbolPair == null)
     {
         symbolPair = m_defaultSymbolPair;
     }
     return(Post(Routes.kSubmitAddress, RestHelpers.BuildPostArgs(WebForms.kReceivingAddress, receivingAddress,
                                                                  WebForms.kSymbolPair, symbolPair,
                                                                  WebForms.kOrderType, type)));
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        /// <summary>	Executes the submit address action. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="ApiExceptionUnknownMarket">	Thrown when an API exception unknown market
        ///                                                 error condition occurs. </exception>
        ///
        /// <param name="ctx">      The context. </param>
        /// <param name="dummy">	The dummy. </param>
        ///
        /// <returns>	A Task. </returns>
        Task OnSubmitAddress(RequestContext ctx, IDummyDaemon dummy)
        {
            if (m_suspended)
            {
                throw new ApiExceptionNetworkAlert();
            }
            else
            {
                string        symbolPair       = RestHelpers.GetPostArg <string, ApiExceptionMissingParameter>(ctx, WebForms.kSymbolPair);
                string        receivingAddress = RestHelpers.GetPostArg <string, ApiExceptionMissingParameter>(ctx, WebForms.kReceivingAddress);
                MetaOrderType orderType        = RestHelpers.GetPostArg <MetaOrderType, ApiExceptionMissingParameter>(ctx, WebForms.kOrderType);
                uint          referralUser     = RestHelpers.GetPostArg <uint>(ctx, WebForms.kReferralId);

                if (!m_marketHandlers.ContainsKey(symbolPair))
                {
                    throw new ApiExceptionUnknownMarket(symbolPair);
                }

                // prevent our own deposit addresses from being used as receiving addresses
                if (m_dataAccess.GetSenderDepositFromDeposit(receivingAddress, symbolPair, referralUser) != null)
                {
                    throw new ApiExceptionInvalidAddress("<internal deposit address>");
                }
                else if (m_bitsharesAccount == receivingAddress)
                {
                    throw new ApiExceptionInvalidAccount(m_bitsharesAccount);
                }

                // get the handler for this market
                MarketBase market = m_marketHandlers[symbolPair];

                // get the response and send it
                SubmitAddressResponse response = market.OnSubmitAddress(receivingAddress, orderType, referralUser);

                //ctx.Respond<SubmitAddressResponse>(response);
                m_api.SendCorsResponse <SubmitAddressResponse>(ctx, response);
            }

            return(null);
        }
Exemplo n.º 4
0
        // ------------------------------------------------------------------------------------------------------------

        /// <summary>	Inserts a transaction. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="symbolPair">   The symbol pair. </param>
        /// <param name="orderType">    Type of the order. </param>
        /// <param name="receivedTxid">	The received txid. </param>
        /// <param name="sentTxid">	    The sent txid. </param>
        /// <param name="amount">	    The amount. </param>
        /// <param name="type">		    The type. </param>
        /// <param name="notes">	    (Optional) the notes. </param>
        public void InsertTransaction(string symbolPair, string depositAddress, MetaOrderType orderType,
                                      string receivedTxid, string sentTxid, decimal amount, decimal price, decimal fee,
                                      MetaOrderStatus status, DateTime date, string notes = null, TransactionPolicy policy = TransactionPolicy.INSERT)
        {
            string verb;

            if (policy == TransactionPolicy.INSERT || policy == TransactionPolicy.REPLACE)
            {
                verb = policy.ToString();
            }
            else if (policy == TransactionPolicy.IGNORE)
            {
                verb = "INSERT IGNORE";
            }
            else
            {
                throw new NotImplementedException();
            }

            m_database.Statement(verb + " INTO transactions (received_txid, deposit_address, sent_txid, symbol_pair, amount, price, fee, date, status, notes, order_type) VALUES(@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k);",
                                 receivedTxid, depositAddress, sentTxid, symbolPair, amount, price, fee, date, status, notes, orderType);
        }
Exemplo n.º 5
0
 public abstract void MarkTransactionAsRefundedStart(string receivedTxid, string depositAddress, string symbolPair, MetaOrderType orderType);
Exemplo n.º 6
0
        /// <summary>	Refund bitshares deposit. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="fromAccount">	from account. </param>
        /// <param name="larimers">   	The larimers. </param>
        /// <param name="depositId">  	Identifier for the deposit. </param>
        /// <param name="memo">		  	The memo. </param>
        /// <param name="asset">	  	The asset. </param>
        protected void RefundBitsharesDeposit(string fromAccount, ulong larimers, string depositId, string memo, BitsharesAsset asset, string depositAddress, MetaOrderType orderType)
        {
            decimal amount = asset.GetAmountFromLarimers(larimers);

            // make sure failures after this point don't result in multiple refunds
            m_daemon.MarkTransactionAsRefundedStart(depositId, depositAddress, m_market.symbol_pair, orderType);

            BitsharesTransactionResponse response = SendBitAssets(amount, asset, fromAccount, memo, false);
            //BitsharesTransactionResponse response = m_bitshares.WalletTransfer(amount, asset.symbol, m_bitsharesAccount, fromAccount, memo);

            m_daemon.MarkTransactionAsRefundedEnd(depositId, response.record_id, MetaOrderStatus.refunded, amount, memo);
        }
Exemplo n.º 7
0
 public abstract SubmitAddressResponse OnSubmitAddress(string receivingAddress, MetaOrderType orderType, uint referralUser);
Exemplo n.º 8
0
        /// <summary>	Refund bitshares deposit. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="fromAccount">	from account. </param>
        /// <param name="larimers">     The larimers. </param>
        /// <param name="depositId">    Identifier for the deposit. </param>
        /// <param name="memo">		    The memo. </param>
        /// <param name="asset">	    The asset. </param>
        protected void RefundBitsharesDeposit(string fromAccount, ulong larimers, string depositId, string memo, BitsharesAsset asset, string depositAddress, MetaOrderType orderType)
        {
            decimal amount = asset.GetAmountFromLarimers(larimers);

            // make sure failures after this point don't result in multiple refunds
            m_daemon.MarkTransactionAsRefundedStart(depositId, depositAddress, m_market.symbol_pair, orderType);

            BitsharesTransactionResponse response = SendBitAssets(amount, asset, fromAccount, memo, false);

            //BitsharesTransactionResponse response = m_bitshares.WalletTransfer(amount, asset.symbol, m_bitsharesAccount, fromAccount, memo);

            m_daemon.MarkTransactionAsRefundedEnd(depositId, response.record_id, MetaOrderStatus.refunded, amount, memo);
        }
Exemplo n.º 9
0
 public abstract SubmitAddressResponse OnSubmitAddress(string receivingAddress, MetaOrderType orderType, uint referralUser);
Exemplo n.º 10
0
 public void MarkTransactionAsRefundedStart(string receivedTxid, string depositAddress, string symbolPair, MetaOrderType orderType)
 {
     if (!IsPartTransaction(receivedTxid))
     {
         MarkTransactionStart(receivedTxid, depositAddress, symbolPair, orderType);
     }
 }
Exemplo n.º 11
0
 public void MarkTransactionAsRefundedStart(string receivedTxid, string depositAddress, string symbolPair, MetaOrderType orderType)
 {
     if (!IsPartTransaction(receivedTxid))
     {
         MarkTransactionStart(receivedTxid, depositAddress, symbolPair, orderType);
     }
 }
Exemplo n.º 12
0
        // ------------------------------------------------------------------------------------------------------------
        /// <summary>	Inserts a transaction. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="symbolPair">  	The symbol pair. </param>
        /// <param name="orderType">   	Type of the order. </param>
        /// <param name="receivedTxid">	The received txid. </param>
        /// <param name="sentTxid">	   	The sent txid. </param>
        /// <param name="amount">	   	The amount. </param>
        /// <param name="type">		   	The type. </param>
        /// <param name="notes">	   	(Optional) the notes. </param>
        void InsertTransaction(	string symbolPair, string depositAddress, MetaOrderType orderType, 
								string receivedTxid, string sentTxid, decimal amount, decimal price, decimal fee,
								MetaOrderStatus status, DateTime date, string notes = null)
        {
            m_dataAccess.InsertTransaction(symbolPair, depositAddress, orderType, receivedTxid, sentTxid, amount, price, fee, status, date, notes);
        }
Exemplo n.º 13
0
 /// <summary>	Mark transaction start. </summary>
 ///
 /// <remarks>	Paul, 11/02/2015. </remarks>
 ///
 /// <param name="receivedTxid">  	The received txid. </param>
 /// <param name="depositAddress">	The deposit address. </param>
 /// <param name="symbolPair">	 	The symbol pair. </param>
 /// <param name="orderType">	 	Type of the order. </param>
 /// <param name="amount">		 	The amount. </param>
 void MarkTransactionStart(string receivedTxid, string depositAddress, string symbolPair, MetaOrderType orderType)
 {
     m_dataAccess.MarkTransactionStart(receivedTxid, depositAddress, symbolPair, orderType);
 }
Exemplo n.º 14
0
 string SubmitAddress(string receivingAddress, MetaOrderType type, string symbolPair=null)
 {
     if (symbolPair == null)
     {
         symbolPair = m_defaultSymbolPair;
     }
     return Post(Routes.kSubmitAddress, RestHelpers.BuildPostArgs(WebForms.kReceivingAddress, receivingAddress,
                                                                 WebForms.kSymbolPair, symbolPair,
                                                                 WebForms.kOrderType, type));
 }
Exemplo n.º 15
0
 public override void MarkTransactionAsRefundedStart(string receivedTxid, string depositAddress, string symbolPair, MetaOrderType orderType)
 {
     m_dataAccess.MarkTransactionAsRefundedStart(receivedTxid, depositAddress, symbolPair, orderType);
 }
Exemplo n.º 16
0
 public abstract void MarkTransactionAsRefundedStart(string receivedTxid, string depositAddress, string symbolPair, MetaOrderType orderType);
Exemplo n.º 17
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;
        }
Exemplo n.º 18
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;
        }
Exemplo n.º 19
0
        // ------------------------------------------------------------------------------------------------------------
        /// <summary>	Inserts a transaction. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="symbolPair">  	The symbol pair. </param>
        /// <param name="orderType">   	Type of the order. </param>
        /// <param name="receivedTxid">	The received txid. </param>
        /// <param name="sentTxid">	   	The sent txid. </param>
        /// <param name="amount">	   	The amount. </param>
        /// <param name="type">		   	The type. </param>
        /// <param name="notes">	   	(Optional) the notes. </param>
        public void InsertTransaction(	string symbolPair, string depositAddress, MetaOrderType orderType, 
										string receivedTxid, string sentTxid, decimal amount, decimal price, decimal fee,
										MetaOrderStatus status, DateTime date, string notes = null, TransactionPolicy policy = TransactionPolicy.INSERT)
        {
            string verb;
            if (policy == TransactionPolicy.INSERT || policy == TransactionPolicy.REPLACE)
            {
                verb = policy.ToString();
            }
            else if (policy == TransactionPolicy.IGNORE)
            {
                verb = "INSERT IGNORE";
            }
            else
            {
                throw new NotImplementedException();
            }

            m_database.Statement(	verb + " INTO transactions (received_txid, deposit_address, sent_txid, symbol_pair, amount, price, fee, date, status, notes, order_type) VALUES(@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k);",
                                    receivedTxid, depositAddress, sentTxid, symbolPair, amount, price, fee, date, status, notes, orderType);
        }
Exemplo n.º 20
0
        // ------------------------------------------------------------------------------------------------------------

        /// <summary>	Inserts a transaction. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="symbolPair">   The symbol pair. </param>
        /// <param name="orderType">    Type of the order. </param>
        /// <param name="receivedTxid">	The received txid. </param>
        /// <param name="sentTxid">	    The sent txid. </param>
        /// <param name="amount">	    The amount. </param>
        /// <param name="type">		    The type. </param>
        /// <param name="notes">	    (Optional) the notes. </param>
        void InsertTransaction(string symbolPair, string depositAddress, MetaOrderType orderType,
                               string receivedTxid, string sentTxid, decimal amount, decimal price, decimal fee,
                               MetaOrderStatus status, DateTime date, string notes = null)
        {
            m_dataAccess.InsertTransaction(symbolPair, depositAddress, orderType, receivedTxid, sentTxid, amount, price, fee, status, date, notes);
        }
Exemplo n.º 21
0
        public void MarkDespositAsCreditedStart(string receivedTxid, string depositAddress, string symbolPair, 
												MetaOrderType orderType, MetaOrderStatus status = MetaOrderStatus.processing,
												TransactionPolicy policy = TransactionPolicy.INSERT)
        {
            MarkTransactionStart(receivedTxid, depositAddress, symbolPair, orderType, status, policy);
        }
Exemplo n.º 22
0
 /// <summary>	Mark transaction start. </summary>
 ///
 /// <remarks>	Paul, 11/02/2015. </remarks>
 ///
 /// <param name="receivedTxid">     The received txid. </param>
 /// <param name="depositAddress">	The deposit address. </param>
 /// <param name="symbolPair">	    The symbol pair. </param>
 /// <param name="orderType">	    Type of the order. </param>
 /// <param name="amount">		    The amount. </param>
 void MarkTransactionStart(string receivedTxid, string depositAddress, string symbolPair, MetaOrderType orderType)
 {
     m_dataAccess.MarkTransactionStart(receivedTxid, depositAddress, symbolPair, orderType);
 }
Exemplo n.º 23
0
        /// <summary>	Mark transaction start. </summary>
        ///
        /// <remarks>	Paul, 11/02/2015. </remarks>
        ///
        /// <param name="receivedTxid">  	The received txid. </param>
        /// <param name="depositAddress">	The deposit address. </param>
        /// <param name="symbolPair">	 	The symbol pair. </param>
        /// <param name="orderType">	 	Type of the order. </param>
        /// <param name="amount">		 	The amount. </param>
        public void MarkTransactionStart(	string receivedTxid, string depositAddress, string symbolPair, 
											MetaOrderType orderType, MetaOrderStatus status = MetaOrderStatus.processing,
											TransactionPolicy policy = TransactionPolicy.INSERT)
        {
            InsertTransaction(symbolPair, depositAddress, orderType, receivedTxid, null, 0, 0, 0, status, DateTime.UtcNow, null, policy);
        }
Exemplo n.º 24
0
 /// <summary>	Mark transaction start. </summary>
 ///
 /// <remarks>	Paul, 11/02/2015. </remarks>
 ///
 /// <param name="receivedTxid">     The received txid. </param>
 /// <param name="depositAddress">	The deposit address. </param>
 /// <param name="symbolPair">	    The symbol pair. </param>
 /// <param name="orderType">	    Type of the order. </param>
 /// <param name="amount">		    The amount. </param>
 public void MarkTransactionStart(string receivedTxid, string depositAddress, string symbolPair,
                                  MetaOrderType orderType, MetaOrderStatus status = MetaOrderStatus.processing,
                                  TransactionPolicy policy = TransactionPolicy.INSERT)
 {
     InsertTransaction(symbolPair, depositAddress, orderType, receivedTxid, null, 0, 0, 0, status, DateTime.UtcNow, null, policy);
 }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
0
 public override void MarkTransactionAsRefundedStart(string receivedTxid, string depositAddress, string symbolPair, MetaOrderType orderType)
 {
     m_dataAccess.MarkTransactionAsRefundedStart(receivedTxid, depositAddress, symbolPair, orderType);
 }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        /// <summary>	Executes the submit address action. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <exception cref="ApiExceptionMessage">	    Thrown when an API exception message error
        ///                                             condition occurs. </exception>
        /// <exception cref="UnexpectedCaseException">	Thrown when an Unexpected Case error condition
        ///                                             occurs. </exception>
        ///
        /// <param name="receivingAddress">	The receiving address. </param>
        /// <param name="orderType">	    Type of the order. </param>
        ///
        /// <returns>	A SubmitAddressResponse. </returns>
        public override SubmitAddressResponse OnSubmitAddress(string receivingAddress, MetaOrderType orderType, uint referralUser)
        {
            SubmitAddressResponse response;

            if (orderType == MetaOrderType.buy)
            {
                string accountName = receivingAddress;
                bool   isPublicKey = BitsharesPubKey.IsValidPublicKey(accountName);

                // check for theoretical validity

                if (!isPublicKey && !BitsharesWallet.IsValidAccountName(accountName))
                {
                    throw new ApiExceptionInvalidAccount(accountName);
                }

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_daemon.GetSenderDepositFromReceiver(accountName, m_market.symbol_pair, referralUser);
                if (senderToDeposit == null)
                {
                    // no dice, create a new entry

                    // check for actual validity
                    string rcA;

                    if (!isPublicKey)
                    {
                        BitsharesAccount account = m_bitshares.GetAccount(accountName);
                        if (account == null)
                        {
                            throw new ApiExceptionInvalidAccount(accountName);
                        }

                        rcA = account.name;
                    }
                    else
                    {
                        rcA = accountName;
                    }

                    // generate a new bitcoin address and tie it to this account
                    string depositAdress = m_bitcoin.GetNewAddress();
                    senderToDeposit = m_daemon.InsertSenderToDeposit(rcA, depositAdress, m_market.symbol_pair, referralUser);
                }

                response = new SubmitAddressResponse
                {
                    deposit_address   = senderToDeposit.deposit_address,
                    receiving_address = senderToDeposit.receiving_address
                };
            }
            else if (orderType == MetaOrderType.sell)
            {
                string bitcoinAddress = receivingAddress;

                // validate bitcoin address
                byte[] check = Util.Base58CheckToByteArray(bitcoinAddress);
                if (check == null)
                {
                    throw new ApiExceptionInvalidAddress(bitcoinAddress);
                }

                // try and retrieve a previous entry
                SenderToDepositRow senderToDeposit = m_daemon.GetSenderDepositFromReceiver(bitcoinAddress, m_market.symbol_pair, referralUser);
                if (senderToDeposit == null)
                {
                    // generate a memo field to use instead
                    senderToDeposit = m_daemon.InsertSenderToDeposit(bitcoinAddress, MarketBase.CreateMemo(bitcoinAddress, m_market.symbol_pair, referralUser), m_market.symbol_pair, referralUser);
                }

                response = new SubmitAddressResponse
                {
                    deposit_address   = m_bitsharesAccount,
                    receiving_address = senderToDeposit.receiving_address,
                    memo = senderToDeposit.deposit_address
                };
            }
            else
            {
                throw new UnexpectedCaseException();
            }

            return(response);
        }
Exemplo n.º 29
0
 public void MarkDespositAsCreditedStart(string receivedTxid, string depositAddress, string symbolPair,
                                         MetaOrderType orderType, MetaOrderStatus status = MetaOrderStatus.processing,
                                         TransactionPolicy policy = TransactionPolicy.INSERT)
 {
     m_dataAccess.MarkDespositAsCreditedStart(receivedTxid, depositAddress, symbolPair, orderType, status, policy);
 }
Exemplo n.º 30
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);
        }