public async Task <List <WalletTransaction> > GetWalletTransactionsSince(TransactionDataType transactionDataType, int currencyId, int walletTimeoutMinutes, int searchBlockLength) { try { using (var context = _exchangeDataContextFactory.CreateReadOnlyContext()) { var currency = await context.Currency.FirstOrDefaultNoLockAsync(c => c.Id == currencyId); var walletConnection = new WalletConnector(currency.WalletHost, currency.WalletPort, currency.WalletUser, currency.WalletPass, Math.Max(walletTimeoutMinutes, 1) * 60000); var blockHash = await walletConnection.GetBlockHashAsync(searchBlockLength); var walletTransactions = await walletConnection.GetTransactionsAsync(blockHash, transactionDataType); return(walletTransactions.Select(x => new WalletTransaction { Timestamp = x.Time.ToDateTime(), Account = x.Account, Amount = Math.Abs(x.Amount), Txid = x.Txid, Type = Extensions.ToTransactionType(x.Category), Address = x.Address, Confirmations = x.Confirmations }) .OrderByDescending(x => x.Timestamp).ToList()); } } catch (Exception e) { _log.Exception("[GetWalletTransactions] - An exception occured while Loading Wallet Transactions", e); } return(new List <WalletTransaction>()); }
/// <summary> /// To the transaction string. /// </summary> /// <param name="type">The type.</param> /// <returns></returns> public static string ToTransactionString(this TransactionDataType type) { switch (type) { case TransactionDataType.All: return(string.Empty); case TransactionDataType.Deposit: return("receive"); case TransactionDataType.Withdraw: return("send"); case TransactionDataType.Transfer: return("move"); case TransactionDataType.Mined: return("generate"); case TransactionDataType.Savings: return("savings"); default: break; } return(string.Empty); }
private List <TransactionData> GetWalletTransactions(Currency currency, TransactionDataType type, int timeout) { try { var lastHash = type == TransactionDataType.Withdraw ? currency.LastWithdrawBlockHash : currency.LastBlockHash; var connector = new WalletConnector(currency.WalletHost, currency.WalletPort, currency.WalletUser, currency.WalletPass, timeout); var deposits = new List <TransactionData>(connector.GetTransactions(lastHash, type)); return(deposits.Where(x => x.Amount > 0).ToList()); } catch (Exception ex) { Log.Exception("An exception occured querying wallet transactions. Currency: {0}", ex, currency.Symbol); } return(null); }
/// <summary> /// Gets the transactions. /// </summary> /// <param name="lastblock"></param> /// <param name="transactionType">the type of transaction.</param> /// <returns>a List of Transactions</returns> public IEnumerable <TransactionData> GetTransactions(string lastblock = "", TransactionDataType transactionType = TransactionDataType.All) { var transactionData = string.IsNullOrEmpty(lastblock) ? ExecuteWalletFunction <ListSinceBlockData>(WalletFunctionType.ListSinceBlock) : ExecuteWalletFunction <ListSinceBlockData>(WalletFunctionType.ListSinceBlock, lastblock); if (transactionData == null || transactionData.Transactions == null || !transactionData.Transactions.Any()) { return(new List <TransactionData>()); } if (transactionType != TransactionDataType.All) { return(transactionData.Transactions .Where(x => x.Category.Equals(transactionType.ToTransactionString())) .OrderBy(x => x.Time)); } return(transactionData.Transactions.OrderBy(x => x.Time)); }
public async Task <IEnumerable <TransactionItem> > GetTransactionItemsForAddressAsync(TransactionDataType type, string address) { using (var db = new SqliteConnection($"Data Source={DataFile}")) { const string sql = "SELECT i.* " + "FROM 'BlockTransactionItem' i " + "WHERE i.'Address' = @Address " + "AND i.'Type' = @Type"; var items = await db.QueryAsync <TransactionItem>(sql, new { Address = address.FromHex(), Type = type }); return(items); } }
/// <summary> /// Gets the transactions async. /// </summary> /// <param name="lastblock"></param> /// <param name="transactionType">Type of the transaction.</param> /// <returns></returns> public Task <IEnumerable <TransactionData> > GetTransactionsAsync(string lastblock = "", TransactionDataType transactionType = TransactionDataType.All) { return(Task.Factory.StartNew <IEnumerable <TransactionData> >(() => GetTransactions(lastblock, transactionType))); }
private async Task <List <TransactionData> > GetTransactions(Currency currency, TransactionDataType type) { var deposits = GetWalletTransactions(currency, type, 5000); if (deposits != null) { return(deposits); } await Task.Delay(1000).ConfigureAwait(false); deposits = GetWalletTransactions(currency, type, 10000); if (deposits != null) { return(deposits); } await Task.Delay(1000).ConfigureAwait(false); deposits = GetWalletTransactions(currency, type, 60000); if (deposits != null) { return(deposits); } return(null); }