/// <summary> /// This method calls the get_discussions_by_blog method from Steem API and returns the mapped list of <see cref="DiscussionListViewModel" /> models /// </summary> /// <param name="accountName">The name of the account to get posts for</param> /// <returns>List of <see cref="DiscussionListViewModel" /> models</returns> private List <DiscussionListViewModel> GetAccountPosts(string accountName) { var postCountToGet = 30; var posts = new List <DiscussionListViewModel>(); try { using (var csteemd = new CSteemd(ConfigurationHelper.HostName)) { var steemResponse = csteemd.get_discussions_by_blog(accountName, postCountToGet); var discussionList = new List <GetDiscussionModel>(); if (steemResponse != null && steemResponse.Count > 0) { foreach (var item in steemResponse) { var disc = item.ToObject <GetDiscussionModel>(); var post = DiscussionMapper.ToDiscussionListViewModel(disc, accountName); posts.Add(post); } } } } catch (Exception ex) { _log.Error(ex); } return(posts); }
private BqPostModel GetBqPost(string accountName, string permlink) { var blogPost = new BqPostModel(); try { using (var csteemd = new CSteemd(ConfigurationHelper.HostName)) { var response = csteemd.get_discussion(accountName, permlink); if (response != null) { var discModel = response.ToObject <GetDiscussionModel>(); blogPost = response.ToObject <BqPostModel>(); blogPost.id = discModel.post_id; blogPost.created = discModel.created.ToString("yyyy-MM-dd HH:mm:ss"); } } } catch (Exception ex) { _log.Error(ex); } return(blogPost); }
/// <summary> /// This method calls the getAccounts method from Steem /// </summary> /// <param name="accountName">The name of the account</param> /// <returns>Returns the results mapped to <see cref="GetAccountsModel" /> class</returns> private GetAccountsModel GetAccountDetails(string accountName) { var account = new GetAccountsModel(); try { if (!String.IsNullOrEmpty(accountName)) { using (var csteemd = new CSteemd(ConfigurationHelper.HostName)) { // account details var response = csteemd.get_accounts(new ArrayList() { accountName }); if (response != null) { var accountResult = response.ToObject <List <GetAccountsModel> >(); account = accountResult.FirstOrDefault(); } } } } catch (Exception ex) { _log.Error(ex); } return(account); }
/// <summary> /// This method gets the dynamic global properties from Steem /// </summary> /// <returns>Returns the retrieved data mapped to <see cref="GetDynamicGlobalPropertiesModel" /> class</returns> private GetDynamicGlobalPropertiesModel GetDynamicGlobalProperties() { var model = new GetDynamicGlobalPropertiesModel(); try { using (var csteemd = new CSteemd(ConfigurationHelper.HostName)) { var response = csteemd.get_dynamic_global_properties(); if (response != null) { var result = response.ToObject <GetDynamicGlobalPropertiesModel>(); if (result != null) { model = response.ToObject <GetDynamicGlobalPropertiesModel>(); } } } } catch (Exception ex) { _log.Error(ex); } return(model); }
/// <summary> /// Gets the vote details of given permlink to determine vote creation date /// </summary> /// <param name="author">The author of the post</param> /// <param name="permlink">The permlink of the post</param> /// <param name="upvoteAccount">The account name of the voter</param> /// <returns></returns> private DateTime?GetVoteDateOfMostRecentUpvote(string author, string permlink, string upvoteAccount) { DateTime?voteDate = null; using (var csteemd = new CSteemd(ConfigurationHelper.HostName)) { var response = csteemd.find_votes(author, permlink); if (response != null) { var findVotesModel = new FindVotesModel(); foreach (var item in response["votes"]) { findVotesModel.Items.Add(item.ToObject <FindVotesItemModel>()); } var upvoteModel = findVotesModel.Items.FirstOrDefault(x => x.voter == upvoteAccount); if (upvoteModel != null) { voteDate = upvoteModel.last_update; } } } return(voteDate); }
/// <summary> /// This method gets the post details response from Steem API /// </summary> /// <param name="accountName">The name of the account</param> /// <param name="permlink">The permlink of the post</param> /// <returns>Returns the result mapped to <see cref="GetDiscussionModel" /></returns> private GetDiscussionModel GetDiscussion(string accountName, string permlink) { var blogPost = new GetDiscussionModel(); try { using (var csteemd = new CSteemd(ConfigurationHelper.HostName)) { var response = csteemd.get_discussion(accountName, permlink); if (response != null) { blogPost = response.ToObject <GetDiscussionModel>(); } } } catch (Exception ex) { _log.Error(ex); } return(blogPost); }
/// <summary> /// This method makes subsequent calls to get_account_history on Steem in order to collect sufficient amount of data to run validation on /// The batchSize parameter defines the limit of the transactions we want to be returned from Steem API. /// The web.config setting HistoryTransactionLimit contains the max value of transactions we set in order to prevent calling the Steem API a lot of times /// Based on the "op" variable in the returned transactions, the values will be mapped to corresponding classes and added to result set to return. /// </summary> /// <param name="accountName">The name of the account</param> /// <param name="result">The result set to be enriched with transaction data</param> private void GetAccountHistoryDetails(string accountName, CurationDetailsViewModel result) { try { // get posts var posts = GetAccountPosts(accountName); if (posts != null && posts.Any()) { result.LastRetrievedPostDate = posts.LastOrDefault().CreatedAt; } result.Author.PendingPostPayout = CalculationHelper.CalculatePendingPostPayout(accountName, posts); result.Posts = posts; var limit = Convert.ToInt32(ConfigurationHelper.HistoryTransactionLimit); uint batchSize = 1000; var start = -1; int transactionsRetrieved = 0; _log.Info(string.Format("Batchsize: {0}", batchSize)); using (var csteemd = new CSteemd(ConfigurationHelper.HostName)) { // stop if the max amount of transactions are reached! while (transactionsRetrieved < limit) { _log.Info(string.Format("Retrieving next batch...Retrieved transaction count: {0}. Value start: {1}", transactionsRetrieved, start)); var responseHistory = csteemd.get_account_history(accountName, start, batchSize); // store last transaction datetime, so that we know until what data time value we got the transactions result.LastTransactionDate = responseHistory[0][1]["timestamp"].ToObject <DateTime>(); _log.Info(string.Format("Stored last transaction datetime: {0}", result.LastTransactionDate.ToString("dd-MM-yyyy HH:mm"))); var totalCount = responseHistory.Count(); // get_account_history returns last result first, but we want most recent first, so we start from the last element of the response to loop for (var i = totalCount - 1; i >= 0; i--) { var el = responseHistory[i]; // get the index of the last transaction in the list to make the next call start from this index if (transactionsRetrieved == 0) { var firstIndex = el[0].ToString(); Int32.TryParse(firstIndex, out start); } var transaction = el[1].ToObject <TransactionModel>(); var operation = el[1]["op"]; var operationType = operation[0].ToString(); var actionViewModel = new ActionViewModel(); actionViewModel.TimeStamp = el[1]["timestamp"].ToObject <DateTime>(); if (operationType == "vote" && result.Votes.Count < ConfigurationHelper.VoteTransactionCount) { var operationModel = operation[1].ToObject <OperationVoteViewModel>(); if (operationModel.voter == accountName) { actionViewModel.Type = "vote"; actionViewModel.Details = operationModel; result.Votes.Add(actionViewModel); } } else if (operationType == "comment") { var operationModel = operation[1].ToObject <OperationCommentViewModel>(); if (!String.IsNullOrEmpty(operationModel.parent_author)) // post { actionViewModel.Type = "comment"; actionViewModel.Details = operationModel; if (result.Comments.Count < ConfigurationHelper.CommentTransactionCount && operationModel.author == accountName) { result.Comments.Add(actionViewModel); } } } // if the required amount of counts are reached, stop if (result.Comments.Count == ConfigurationHelper.CommentTransactionCount) { break; } } transactionsRetrieved += (int)batchSize; start -= (int)batchSize; } } } catch (Exception ex) { _log.Error(ex); } }