Class: Istox::BlockchainReceiptService

Inherits:
Object
  • Object
show all
Defined in:
lib/istox/helpers/blockchain_receipt_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_blockchain_receipt_klassObject



8
9
10
# File 'lib/istox/helpers/blockchain_receipt_service.rb', line 8

def self.get_blockchain_receipt_klass
    @@blockchain_receipt_klass
end

.init(blockchain_receipt_klass) ⇒ Object



4
5
6
# File 'lib/istox/helpers/blockchain_receipt_service.rb', line 4

def self.init(blockchain_receipt_klass)
    @@blockchain_receipt_klass = blockchain_receipt_klass
end

Instance Method Details

#create!(tx_message, model, sid, action) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/istox/helpers/blockchain_receipt_service.rb', line 12

def create!(tx_message, model, sid, action)
    raise "Have you forgetten to init blockchain receipt service?" if ::Istox::BlockchainReceiptService.get_blockchain_receipt_klass == nil

    blockchain_receipt_klass = ::Istox::BlockchainReceiptService.get_blockchain_receipt_klass
    klass = class_eval("::#{blockchain_receipt_klass.name}")
    unless klass <= ::Istox::BlockchainReceipt
    raise RuntimeError, "#{blockchain_receipt_klass.name} does not inherit istox blockchain receipt"
    end

    # delete the previous existing blockchain receipts
    klass.where(resource_name: model.class.name,
                            resource_id: model.id).destroy_all

    (0...tx_message.txnCount).each do |i|
        blockchain_receipt = klass.new(
            sid: sid,
            txid: tx_message.uuid,
            resource_name: model.class.name,
            resource_id: model.id,
            resource_action: action
        )
        blockchain_receipt.save!
    end
end