lib/cosgrove/utils.rb in cosgrove-0.0.3.5 vs lib/cosgrove/utils.rb in cosgrove-0.0.4.0pre1

- old
+ new

@@ -87,18 +87,10 @@ when :golos then @golos_stream ||= Radiator::Stream.new(chain_options(chain)) when :test then @test_stream ||= Radiator::Stream.new(chain_options(chain)) end end - def steem_data_head_block_number - begin - SteemData::AccountOperation.order(timestamp: -1).limit(1).first.block - rescue - -1 - end - end - def properties(chain) api(chain).get_dynamic_global_properties.result end def head_block_number(chain) @@ -147,13 +139,13 @@ author = find_account(author_name) offset = offset.to_i posts = if op == 'latest' - SteemData::Post.root_posts.where(author: author.name).order(created: :desc) + SteemApi::Comment.where(depth: 0, author: author.name).order(created: :desc) elsif op == 'first' - SteemData::Post.root_posts.where(author: author.name).order(created: :asc) + SteemApi::Comment.where(depth: 0, author: author.name).order(created: :asc) else [] end if posts.any? && !!(post = posts[offset.to_i.abs]) @@ -173,11 +165,11 @@ author_name = options[:author_name] permlink = options[:permlink] parent_permlink = options[:parent_permlink] post = if chain == :steem - posts = SteemData::Post.root_posts.where(author: author_name) + posts = SteemApi::Comment.where(depth: 0, author: author_name) posts = posts.where(permlink: permlink) if !!permlink posts = posts.where(parent_permlink: parent_permlink) if !!parent_permlink posts.first end @@ -213,23 +205,15 @@ def find_author(options) chain = options[:chain] author_name = options[:author_name] - author = SteemData::Account.where(name: author_name).last + author = SteemApi::Account.where(name: author_name).first if author.nil? - author = begin - SteemApi::Account.where(name: author_name).last - rescue => e - puts e - end - end - - if author.nil? author = api(chain).get_accounts([author_name]) do |accounts, errors| - accounts.last + accounts.first end end author end @@ -240,12 +224,13 @@ to = options[:to] memo_key = options[:memo].to_s.strip op = case chain when :steem - transfers = SteemData::AccountOperation.type('transfer'). - where(account: steem_account, from: from, to: steem_account, memo: {'$regex' => ".*#{memo_key}.*"}) + transfers = SteemApi::Tx::Transfer. + where(from: from, to: steem_account). + where("memo LIKE ?", "%#{memo_key}%") if transfers.any? transfers.last else SteemApi::Tx::Transfer. @@ -259,11 +244,11 @@ where(to: to). where("memo LIKE ?", "%#{memo_key}%").last end if op.nil? - # Fall back to RPC. The transaction is so new, SteemData hasn't seen it - # yet, SteemData is behind, or there is no such transfer. + # Fall back to RPC. The transaction is so new, SteemApi hasn't seen it + # yet, SteemApi is behind, or there is no such transfer. api(chain).get_account_history(steem_account, -1, 10000) do |history, error| if !!error ap error return "Try again later."