Class: TxCatcher::Transaction
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- TxCatcher::Transaction
- Defined in:
- lib/txcatcher/models/transaction.rb
Instance Method Summary collapse
Instance Method Details
#after_create ⇒ Object
22 23 24 25 26 27 |
# File 'lib/txcatcher/models/transaction.rb', line 22 def after_create self.deposits.each do |d| d.transaction = self d.save end end |
#before_validation ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/txcatcher/models/transaction.rb', line 8 def before_validation return if !self.new? || !self.deposits.empty? parse_transaction assign_transaction_attrs @tx_hash["vout"].uniq { |out| out["n"] }.each do |out| amount = Satoshi.new(out["value"], from_unit: :btc).to_i if out["value"] address = out["scriptPubKey"]["addresses"]&.first # Do not create a new deposit unless it actually makes sense to create one if address && amount && amount > 0 self.deposits << Deposit.new(amount: amount, address_string: address) end end end |
#confirmations ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/txcatcher/models/transaction.rb', line 33 def confirmations if self.block_height TxCatcher.current_block_height - self.block_height + 1 else 0 end end |
#tx_hash ⇒ Object
29 30 31 |
# File 'lib/txcatcher/models/transaction.rb', line 29 def tx_hash @tx_hash || parse_transaction end |