Class: Graphdb::Model::TxOut

Inherits:
ActiveNodeBase show all
Includes:
Extensions::OpenAssets::TxOut
Defined in:
lib/graphdb/model/tx_out.rb

Class Method Summary collapse

Methods included from Extensions::OpenAssets::TxOut

#apply_oa_attributes, prepended

Methods inherited from ActiveNodeBase

remove_module

Class Method Details

.create_from_hash(hash) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/graphdb/model/tx_out.rb', line 21

def self.create_from_hash(hash)
  tx_out = new
  tx_out.value = hash['value']
  tx_out.n = hash['n']
  tx_out.save!
  if hash['scriptPubKey']
    tx_out.script_pubkey_asm = hash['scriptPubKey']['asm']
    tx_out.script_pubkey_hex = hash['scriptPubKey']['hex']
    tx_out.output_type = hash['scriptPubKey']['type']
    tx_out.req_sigs = hash['scriptPubKey']['reqSigs']
    if hash['scriptPubKey']['addresses']
      hash['scriptPubKey']['addresses'].each do |a|
        tx_out.addresses << Address.find_or_create(a)
      end
    end
  end
  tx_out.save!
  tx_out
end

.find_by_outpoint(txid, n) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/graphdb/model/tx_out.rb', line 41

def self.find_by_outpoint(txid, n)
  tx = Graphdb::Model::Transaction.with_txid(txid).first
  if tx
    tx.outputs.each{|o|
      return o if o.n == n
    }
  end
end