Sha256: c73140b026822d926282491d08e841a475c9af0cd4723711ae6a88f3419b4e33

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

module Graphdb
  module Model
    class TxIn < ActiveNodeBase

      property :txid
      property :vout, type: Integer
      property :script_sig_asm
      property :script_sig_hex
      property :coinbase
      property :sequence

      has_one :out, :transaction, type: :transaction, model_class: 'Graphdb::Model::Transaction'
      has_one :in, :out_point, origin: :out_point, model_class: 'Graphdb::Model::TxOut'

      validates :sequence, :presence => true

      after_create :add_out_point_rel

      def self.create_from_hash(hash)
        tx_in = new
        tx_in.txid = hash['txid']
        tx_in.vout = hash['vout']
        if hash['scriptSig']
          tx_in.script_sig_asm = hash['scriptSig']['asm']
          tx_in.script_sig_hex = hash['scriptSig']['hex']
        end
        tx_in.coinbase = hash['coinbase']
        tx_in.sequence = hash['sequence']
        tx_in.save!
        tx_in
      end

      private
      def add_out_point_rel
        return if self.txid.nil? && self.vout.nil?
        tx_out = Graphdb::Model::TxOut.find_by_outpoint(self.txid, self.vout)
        if tx_out
          self.out_point = tx_out
          save!
        end
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bitcoin2graphdb-0.4.1 lib/graphdb/model/tx_in.rb
bitcoin2graphdb-0.4.0 lib/graphdb/model/tx_in.rb
bitcoin2graphdb-0.3.9 lib/graphdb/model/tx_in.rb
bitcoin2graphdb-0.3.8 lib/graphdb/model/tx_in.rb
bitcoin2graphdb-0.3.7 lib/graphdb/model/tx_in.rb
bitcoin2graphdb-0.3.6 lib/graphdb/model/tx_in.rb
bitcoin2graphdb-0.3.5 lib/graphdb/model/tx_in.rb
bitcoin2graphdb-0.3.4 lib/graphdb/model/tx_in.rb