Class: Bitcoin::OutPoint
Overview
outpoint class
Constant Summary collapse
- COINBASE_HASH =
'0000000000000000000000000000000000000000000000000000000000000000'
- COINBASE_INDEX =
4294967295
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Class Method Summary collapse
Instance Method Summary collapse
- #coinbase? ⇒ Boolean
-
#initialize(hash, index = -1)) ⇒ OutPoint
constructor
A new instance of OutPoint.
- #to_payload ⇒ Object
-
#txid ⇒ Object
convert hash to txid.
- #valid? ⇒ Boolean
Constructor Details
#initialize(hash, index = -1)) ⇒ OutPoint
Returns a new instance of OutPoint.
12 13 14 15 |
# File 'lib/bitcoin/out_point.rb', line 12 def initialize(hash, index = -1) @hash = hash @index = index end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
9 10 11 |
# File 'lib/bitcoin/out_point.rb', line 9 def hash @hash end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
10 11 12 |
# File 'lib/bitcoin/out_point.rb', line 10 def index @index end |
Class Method Details
.create_coinbase_outpoint ⇒ Object
29 30 31 |
# File 'lib/bitcoin/out_point.rb', line 29 def self.create_coinbase_outpoint new(COINBASE_HASH, COINBASE_INDEX) end |
.from_txid(txid, index) ⇒ Object
17 18 19 |
# File 'lib/bitcoin/out_point.rb', line 17 def self.from_txid(txid, index) self.new(txid.rhex, index) end |
Instance Method Details
#coinbase? ⇒ Boolean
21 22 23 |
# File 'lib/bitcoin/out_point.rb', line 21 def coinbase? hash == COINBASE_HASH && index == COINBASE_INDEX end |
#to_payload ⇒ Object
25 26 27 |
# File 'lib/bitcoin/out_point.rb', line 25 def to_payload [hash.htb, index].pack('a32V') end |
#txid ⇒ Object
convert hash to txid
38 39 40 |
# File 'lib/bitcoin/out_point.rb', line 38 def txid hash.rhex end |
#valid? ⇒ Boolean
33 34 35 |
# File 'lib/bitcoin/out_point.rb', line 33 def valid? index >= 0 && (!coinbase? && hash != COINBASE_HASH) end |