Class: Tapyrus::OutPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/tapyrus/out_point.rb

Overview

outpoint class

Constant Summary collapse

COINBASE_HASH =
"0000000000000000000000000000000000000000000000000000000000000000"
COINBASE_INDEX =
4_294_967_295

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tx_hash, index = -1)) ⇒ OutPoint

Returns a new instance of OutPoint.



10
11
12
13
# File 'lib/tapyrus/out_point.rb', line 10

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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



8
9
10
# File 'lib/tapyrus/out_point.rb', line 8

def index
  @index
end

#tx_hashObject (readonly)

Returns the value of attribute tx_hash.



7
8
9
# File 'lib/tapyrus/out_point.rb', line 7

def tx_hash
  @tx_hash
end

Class Method Details

.create_coinbase_outpointObject



27
28
29
# File 'lib/tapyrus/out_point.rb', line 27

def self.create_coinbase_outpoint
  new(COINBASE_HASH, COINBASE_INDEX)
end

.from_txid(txid, index) ⇒ Object



15
16
17
# File 'lib/tapyrus/out_point.rb', line 15

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

Instance Method Details

#==(other) ⇒ Object



35
36
37
# File 'lib/tapyrus/out_point.rb', line 35

def ==(other)
  to_payload == other&.to_payload
end

#coinbase?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/tapyrus/out_point.rb', line 19

def coinbase?
  tx_hash == COINBASE_HASH
end

#to_payloadObject



23
24
25
# File 'lib/tapyrus/out_point.rb', line 23

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

#txidObject

convert hash to txid



40
41
42
# File 'lib/tapyrus/out_point.rb', line 40

def txid
  tx_hash.rhex
end

#valid?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/tapyrus/out_point.rb', line 31

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