Sha256: a74862ecca4c9527ecc6c97187732677992f1d1c6a1593510a063373ce60d6d7

Contents?: true

Size: 773 Bytes

Versions: 8

Compression:

Stored size: 773 Bytes

Contents

module Tapyrus

  # outpoint class
  class OutPoint

    COINBASE_HASH = '0000000000000000000000000000000000000000000000000000000000000000'
    COINBASE_INDEX = 4294967295

    attr_reader :tx_hash
    attr_reader :index

    def initialize(tx_hash, index = -1)
      @tx_hash = tx_hash
      @index = index
    end

    def self.from_txid(txid, index)
      self.new(txid.rhex, index)
    end

    def coinbase?
      tx_hash == COINBASE_HASH
    end

    def to_payload
      [tx_hash.htb, index].pack('a32V')
    end

    def self.create_coinbase_outpoint
      new(COINBASE_HASH, COINBASE_INDEX)
    end

    def valid?
      index >= 0 && (!coinbase? && tx_hash != COINBASE_HASH)
    end

    # convert hash to txid
    def txid
      tx_hash.rhex
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tapyrus-0.2.7 lib/tapyrus/out_point.rb
tapyrus-0.2.6 lib/tapyrus/out_point.rb
tapyrus-0.2.5 lib/tapyrus/out_point.rb
tapyrus-0.2.4 lib/tapyrus/out_point.rb
tapyrus-0.2.3 lib/tapyrus/out_point.rb
tapyrus-0.2.2 lib/tapyrus/out_point.rb
tapyrus-0.2.1 lib/tapyrus/out_point.rb
tapyrus-0.2.0 lib/tapyrus/out_point.rb