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_save ⇒ Object
20 21 22 23 24 25 |
# File 'lib/txcatcher/models/transaction.rb', line 20 def after_save self.deposits.each do |d| d.transaction = self d.save end end |
#before_validation ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/txcatcher/models/transaction.rb', line 6 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
31 32 33 34 35 36 37 |
# File 'lib/txcatcher/models/transaction.rb', line 31 def confirmations if self.block_height TxCatcher.current_block_height - self.block_height + 1 else 0 end end |
#tx_hash ⇒ Object
27 28 29 |
# File 'lib/txcatcher/models/transaction.rb', line 27 def tx_hash @tx_hash || parse_transaction end |