Skip to content

Commit

Permalink
DigixGlobal#70 WatchingTransaction::resend_transactions optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
bshevchenko committed Sep 11, 2019
1 parent 57f8a80 commit d42ba3e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/watching_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ def resend(user, watching_transaction, attrs)
end

def resend_transactions
group_size = WatchingTransaction.group(:group_id).count
WatchingTransaction.all.order('created_at ASC').each do |tx|
ok_tx, data = EthereumApi.get_transaction_by_hash(tx.txhash)
unless ok_tx == :ok && data
if WatchingTransaction.where(group_id: tx.group_id).count == 1
if group_size[tx.group_id] == 1
ok_send, txhash = EthereumApi.send_raw_transaction(tx.signed_transaction)
if ok_send == :ok
Rails.logger.info "Resent transaction #{tx.txhash}, new hash is #{txhash}"
Expand All @@ -85,6 +86,7 @@ def resend_transactions
else
Rails.logger.info "Destroying dropped transaction #{tx.txhash}"
tx.destroy
group_size[tx.group_id] -= 1
end
next
end
Expand Down

0 comments on commit d42ba3e

Please sign in to comment.