Exemplo n.º 1
0
        /// <summary>	Refund bitshares deposit. </summary>
        ///
        /// <remarks>	Paul, 15/01/2015. </remarks>
        ///
        /// <param name="fromAccount">	from account. </param>
        /// <param name="deposit">	    The deposit. </param>
        /// <param name="depositId">    Identifier for the deposit. </param>
        /// <param name="memo">		    The memo. </param>
        protected virtual void RefundBitsharesDeposit(string fromAccount, ulong larimers, string depositId, string memo)
        {
            // make sure failures after this point don't result in multiple refunds
            MarkTransactionAsRefundedStart(depositId);

            BitsharesTransactionResponse response;
            decimal amount = m_asset.GetAmountFromLarimers(larimers);

            try
            {
                BitsharesAccount account = GetAccountFromLedger(fromAccount);
                response = m_bitshares.WalletTransfer(amount, m_asset.symbol, m_bitsharesAccount, fromAccount, memo);
            }
            catch (BitsharesRpcException)
            {
                BitsharesTransaction t = m_bitshares.BlockchainGetTransaction(depositId);

                // get the sender's address from the balance id
                BitsharesOperation op = t.trx.operations.First(o => o.type == BitsharesTransactionOp.withdraw_op_type);

                BitsharesBalanceRecord balance = m_bitshares.GetBalance(op.data.balance_id);
                string senderAddress           = balance.condition.data.owner;


                response = m_bitshares.WalletTransferToAddress(amount, m_asset.symbol, m_bitsharesAccount, senderAddress, memo);
            }

            MarkTransactionAsRefundedEnd(depositId, response.record_id, amount, DaemonTransactionType.bitsharesRefund, memo);
        }
Exemplo n.º 2
0
        /// <summary>	Bitshares transaction to bitcoin address. </summary>
        ///
        /// <remarks>	Paul, 31/01/2015. </remarks>
        ///
        /// <param name="l">	The BitsharesLedgerEntry to process. </param>
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	A string. </returns>
        /*protected override string BitsharesTransactionToBitcoinAddress(BitsharesLedgerEntry l, BitsharesTransaction t)
        {
            // look up the BTS address this transaction was sent to
            BitsharesOperation op = t.trx.operations.First(o => o.type == BitsharesTransactionOp.deposit_op_type);

            string depositAddress = op.data.condition.data.owner;

            // look that address up in our map of sender->deposit address
            SenderToDepositRow senderToDeposit = GetSenderDepositFromDeposit(depositAddress);
            if (senderToDeposit != null)
            {
                return senderToDeposit.sender;
            }
            else
            {
                return null;
            }
        }*/
        /// <summary>	Bitshares transaction to bitcoin address. </summary>
        ///
        /// <remarks>	Paul, 31/01/2015. </remarks>
        ///
        /// <param name="l">	The BitsharesLedgerEntry to process. </param>
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	A string. </returns>
        protected override string BitsharesTransactionToBitcoinAddress(BitsharesLedgerEntry l, BitsharesTransaction t)
        {
            // look up the BTS address this transaction was sent to

            // look that address up in our map of sender->deposit address
            SenderToDepositRow senderToDeposit = GetSenderDepositFromDeposit(l.memo);
            if (senderToDeposit != null)
            {
                return senderToDeposit.receiving_address;
            }
            else
            {
                throw new RefundBitsharesException("Missing memo!");
            }
        }
Exemplo n.º 3
0
        /// <summary>	Handles the bitshares desposits. </summary>
        ///
        /// <remarks>	Paul, 16/12/2014. </remarks>
        ///
        /// <exception cref="UnsupportedTransactionException">	Thrown when an Unsupported Transaction
        ///                                                     error condition occurs. </exception>
        protected virtual void HandleBitsharesDesposits()
        {
            // which block do we start from
            uint lastBlockBitshares = GetLastBitsharesBlock();

            // which block do we end on
            GetInfoResponse info = m_bitshares.GetInfo();

            if (lastBlockBitshares == 0)
            {
                // default to current block
                lastBlockBitshares = info.blockchain_head_block_num;
            }

            // get all relevant bitshares deposits
            List <BitsharesWalletTransaction> assetTransactions = m_bitshares.WalletAccountTransactionHistory(m_bitsharesAccount,
                                                                                                              m_bitsharesAsset,
                                                                                                              0,
                                                                                                              lastBlockBitshares,
                                                                                                              info.blockchain_head_block_num);

            IEnumerable <BitsharesWalletTransaction> assetDeposits = assetTransactions.Where(t => t.is_confirmed &&
                                                                                             t.ledger_entries.Any(l => l.to_account == m_bitsharesAccount &&
                                                                                                                  l.from_account != l.to_account &&
                                                                                                                  l.memo != kFundingMemo &&
                                                                                                                  l.from_account != BitsharesWallet.kNetworkAccount));

            foreach (BitsharesWalletTransaction t in assetDeposits)
            {
                IEnumerable <BitsharesLedgerEntry> deposits = t.ledger_entries.Where(l => l.to_account == m_bitsharesAccount);

                if (deposits.Count() == 1)
                {
                    BitsharesLedgerEntry l = deposits.First();

                    // make sure we didn't already send bitcoins for this deposit
                    if (!HasBitsharesDepositBeenCredited(t.trx_id) && !IsTransactionIgnored(t.trx_id))
                    {
                        try
                        {
                            ///
                            /// STILL NEED A WAY TO GET SENDER BITCOIN ADDRESS FOR UNREGISTERED ACCOUNTS
                            ///
                            // look up the transaction proper
                            BitsharesTransaction fullT = m_bitshares.BlockchainGetTransaction(t.trx_id);

                            // get the btc address
                            string btcAddress = BitsharesTransactionToBitcoinAddress(l, fullT);

                            try
                            {
                                SendBitcoinsToDepositor(btcAddress, t.trx_id, l.amount.amount);
                            }
                            catch (Exception e)
                            {
                                // problem sending bitcoins, lets log it
                                LogException(t.trx_id, e.Message, DateTime.UtcNow, DaemonTransactionType.bitsharesDeposit);

                                // also lets now ignore this transaction so we don't keep failing
                                RefundBitsharesDeposit(l.from_account, l.amount.amount, t.trx_id, e.Message);
                            }
                        }
                        catch (RefundBitsharesException r)
                        {
                            // were unable to get a bitcoin address from the bitshares account, so refund the transaction
                            RefundBitsharesDeposit(l.from_account, l.amount.amount, t.trx_id, r.Message);
                        }
                    }
                }
                else
                {
                    // fail with unhandled case
                    throw new UnsupportedTransactionException(t.trx_id);
                }
            }

            UpdateBitsharesBlock(info.blockchain_head_block_num);
        }
Exemplo n.º 4
0
        /// <summary>	This is virtual because implementors might like a different way  </summary>
        ///
        /// <remarks>	Paul, 16/12/2014. </remarks>
        ///
        /// <param name="account">	The account. </param>
        ///
        /// <returns>	A string. </returns>

        /*protected virtual string BitsharesTransactionToBitcoinAddress(BitsharesLedgerEntry l)
         * {
         *      // THIS CANNOT WORK DUE TO MEMO SIZE = 19 bytes!!!!!!!
         *
         *
         *      // expect the BTC address to be inside the memo somewhere
         *      string[] memo = l.memo.Split(' ');
         *      AddressBase address = null;
         *      foreach (string s in memo)
         *      {
         *              try
         *              {
         *                      address = new AddressBase(s);
         *                      break;
         *              }
         *              catch (ArgumentException){}
         *      }
         *
         *      if (address == null)
         *      {
         *              throw new RefundBitsharesException("Unable to find desired bitcoin address in transction memo!");
         *      }
         *
         *      return address.AddressBase58;
         * }*/

        /// <summary>	Bitshares transaction to bitcoin address. </summary>
        ///
        /// <remarks>	Paul, 25/01/2015. </remarks>
        ///
        /// <exception cref="RefundBitsharesException">	Thrown when a Refund Bitshares error condition
        ///                                             occurs. </exception>
        ///
        /// <param name="l">	The BitsharesLedgerEntry to process. </param>
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	A string. </returns>
        protected virtual string BitsharesTransactionToBitcoinAddress(BitsharesLedgerEntry l, BitsharesTransaction t)
        {
            try
            {
                // get the public key of the sender
                BitsharesAccount account = GetAccountFromLedger(l.from_account);

                // turn into into a bitshares address
                return(BitsharesAccountToBitcoinAddress(account));
            }
            catch (BitsharesRpcException)
            {
                throw new RefundBitsharesException("Unregistered acct!");
            }
        }
Exemplo n.º 5
0
        /// <summary>	Bitshares transaction to bitcoin address. </summary>
        ///
        /// <remarks>	Paul, 31/01/2015. </remarks>
        ///
        /// <param name="l">	The BitsharesLedgerEntry to process. </param>
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	A string. </returns>

        /*protected override string BitsharesTransactionToBitcoinAddress(BitsharesLedgerEntry l, BitsharesTransaction t)
         * {
         *      // look up the BTS address this transaction was sent to
         *      BitsharesOperation op = t.trx.operations.First(o => o.type == BitsharesTransactionOp.deposit_op_type);
         *
         *      string depositAddress = op.data.condition.data.owner;
         *
         *      // look that address up in our map of sender->deposit address
         *      SenderToDepositRow senderToDeposit = GetSenderDepositFromDeposit(depositAddress);
         *      if (senderToDeposit != null)
         *      {
         *              return senderToDeposit.sender;
         *      }
         *      else
         *      {
         *              return null;
         *      }
         * }*/

        /// <summary>	Bitshares transaction to bitcoin address. </summary>
        ///
        /// <remarks>	Paul, 31/01/2015. </remarks>
        ///
        /// <param name="l">	The BitsharesLedgerEntry to process. </param>
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	A string. </returns>
        protected override string BitsharesTransactionToBitcoinAddress(BitsharesLedgerEntry l, BitsharesTransaction t)
        {
            // look up the BTS address this transaction was sent to

            // look that address up in our map of sender->deposit address
            SenderToDepositRow senderToDeposit = GetSenderDepositFromDeposit(l.memo);

            if (senderToDeposit != null)
            {
                return(senderToDeposit.receiving_address);
            }
            else
            {
                throw new RefundBitsharesException("Missing memo!");
            }
        }
Exemplo n.º 6
0
        /// <summary>	This is virtual because implementors might like a different way  </summary>
        ///
        /// <remarks>	Paul, 16/12/2014. </remarks>
        ///
        /// <param name="account">	The account. </param>
        ///
        /// <returns>	A string. </returns>
        /*protected virtual string BitsharesTransactionToBitcoinAddress(BitsharesLedgerEntry l)
        {
            // THIS CANNOT WORK DUE TO MEMO SIZE = 19 bytes!!!!!!!

            // expect the BTC address to be inside the memo somewhere
            string[] memo = l.memo.Split(' ');
            AddressBase address = null;
            foreach (string s in memo)
            {
                try
                {
                    address = new AddressBase(s);
                    break;
                }
                catch (ArgumentException){}
            }

            if (address == null)
            {
                throw new RefundBitsharesException("Unable to find desired bitcoin address in transction memo!");
            }

            return address.AddressBase58;
        }*/
        /// <summary>	Bitshares transaction to bitcoin address. </summary>
        ///
        /// <remarks>	Paul, 25/01/2015. </remarks>
        ///
        /// <exception cref="RefundBitsharesException">	Thrown when a Refund Bitshares error condition
        /// 											occurs. </exception>
        ///
        /// <param name="l">	The BitsharesLedgerEntry to process. </param>
        /// <param name="t">	The TransactionSinceBlock to process. </param>
        ///
        /// <returns>	A string. </returns>
        protected virtual string BitsharesTransactionToBitcoinAddress(BitsharesLedgerEntry l, BitsharesTransaction t)
        {
            try
            {
                // get the public key of the sender
                BitsharesAccount account = GetAccountFromLedger(l.from_account);

                // turn into into a bitshares address
                return BitsharesAccountToBitcoinAddress(account);
            }
            catch (BitsharesRpcException)
            {
                throw new RefundBitsharesException("Unregistered acct!");
            }
        }