lib/graphdb/model/tx_out.rb in bitcoin2graphdb-0.1.0 vs lib/graphdb/model/tx_out.rb in bitcoin2graphdb-0.1.1
- old
+ new
@@ -9,14 +9,17 @@
property :output_type
property :req_sigs, type: Integer
has_one :out, :transaction, type: :transaction, model_class: Transaction
has_many :out, :addresses, type: :address, model_class: Address
+ has_one :out, :out_point, type: :spent_input, model_class: TxIn
validates :value, :presence => true
validates :n, :presence => true
+ scope :with_out_index, -> (n){where(n: n)}
+
def self.create_from_hash(hash)
tx_out = new
tx_out.value = hash['value']
tx_out.n = hash['n']
tx_out.save!
@@ -31,9 +34,18 @@
end
end
end
tx_out.save!
tx_out
+ end
+
+ 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
end
end
end
\ No newline at end of file