Sha256: 5c5cc6dc45eac3a5836af40b15b3ef195c7a35bc5f497d1889810772ec0ead2d

Contents?: true

Size: 800 Bytes

Versions: 1

Compression:

Stored size: 800 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 && index == COINBASE_INDEX
    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

1 entries across 1 versions & 1 rubygems

Version Path
tapyrus-0.1.0 lib/tapyrus/out_point.rb