4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/istox/consumers/blockchain_status_handler.rb', line 4
def txn_status_changed(transactions)
transactions.each do |transaction|
if ::Istox::BlockchainReceipt.find_by_txid(transaction[:id]).nil?
puts 'Transaction not found, skipping...'
next
end
find_resource(transaction) do |receipt, resource_name, resource_id, resource_action, sid|
resource = begin
class_eval("::#{resource_name}").find(resource_id)
rescue => e
puts e.inspect
next
end
receipt_list = get_receipt_list(resource, resource_name)
next if !allowed_statuses?(transaction)
next if receipt_handled?(receipt_list)
if confirmed?(transaction)
next if resource.outcome == 'pending'
if resource.outcome == 'confirmed'
resource.handle_confirm(resource_action)
publish_to_frontend(resource, true, receipt, sid, receipt_list) do
update_receipts(receipt_list)
end
end
end
if failed?(transaction)
resource.handle_fail(resource_action)
publish_to_frontend(resource, false, receipt, sid, receipt_list) { update_receipts(receipt_list) }
end
end
end
end
|