示例#1
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 Dictionary <string, BitsharesLedgerEntry> HandleBitsharesDesposits()
        {
            Dictionary <string, BitsharesLedgerEntry> results = new Dictionary <string, BitsharesLedgerEntry>();

            // 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,
                                                                                                              null,
                                                                                                              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)
            {
                // make sure we didn't already send bitcoins for this deposit
                if (!HasDepositBeenCredited(t.trx_id) && !IsTransactionIgnored(t.trx_id))
                {
                    IEnumerable <BitsharesLedgerEntry> deposits = t.ledger_entries.Where(l => l.to_account == m_bitsharesAccount);

                    if (deposits.Count() == 1)
                    {
                        BitsharesLedgerEntry l = deposits.First();
                        results[t.trx_id] = l;
                    }
                    else
                    {
                        // fail with unhandled case
                        throw new UnsupportedTransactionException(t.trx_id);
                    }
                }
            }

            UpdateBitsharesBlock(info.blockchain_head_block_num);

            return(results);
        }
示例#2
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);
        }