Class: Istox::BlockchainStatusHandler
- Inherits:
-
Object
- Object
- Istox::BlockchainStatusHandler
- Defined in:
- lib/istox/consumers/blockchain_status_handler.rb
Class Method Summary collapse
-
.chainhub_response_event(transaction) ⇒ Object
format of transaction { type: ‘CHAINHUB_RESPONSE_EVENT’, uuid:‘123’, //original request uuid sent from backend success:true, //status of the whole request in true/false message:”, //In case of error, the message contain the error reason txnCount:1, //Number of blockchain transactions from the original request txnHashes:[] //Hashes for all transactions that has been submitted and mined by the blockchain for verification purpose }.
Class Method Details
.chainhub_response_event(transaction) ⇒ Object
format of transaction
type: 'CHAINHUB_RESPONSE_EVENT',
uuid:'123', //original request uuid sent from backend
success:true, //status of the whole request in true/false
message:'', //In case of error, the message contain the error reason
txnCount:1, //Number of blockchain transactions from the original request
txnHashes:[] //Hashes for all transactions that has been submitted and mined by the blockchain for verification purpose
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 41 42 43 44 45 46 47 |
# File 'lib/istox/consumers/blockchain_status_handler.rb', line 14 def chainhub_response_event(transaction) receipt = ::Istox::BlockchainReceipt.where(txid: transaction.uuid).first if receipt.blank? puts 'Transaction doesn\'t belong to this backend, skipping...' return end status = transaction.success ? 'confirmed' : 'failed' receipt.update!(status: status, message: transaction., txhash: transaction.txnHashes.present? ? transaction.txnHashes.join(',') : nil) resource = begin class_eval("::#{receipt.resource_name}", __FILE__, __LINE__).find(receipt.resource_id) rescue NameError puts 'Class not found, skipping...' return end return if resource_handled?(receipt) if status == 'confirmed' resource.handle_confirm(receipt) mark_resource_handled(receipt) publish_to_frontend(resource, true, receipt, receipt.sid) elsif status == 'failed' resource.handle_fail(receipt) mark_resource_handled(receipt) publish_to_frontend(resource, false, receipt, receipt.sid) end end |