Class: BSV::Network::UTXO

Inherits:
Object
  • Object
show all
Defined in:
lib/bsv/network/utxo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tx_hash:, tx_pos:, satoshis: nil, value: nil, height: nil) ⇒ UTXO

Returns a new instance of UTXO.

Parameters:

  • tx_hash (String)

    transaction ID

  • tx_pos (Integer)

    output index

  • satoshis (Integer) (defaults to: nil)

    output value in satoshis (accepts value as alias)

  • height (Integer, nil) (defaults to: nil)

    block height (0 or nil = unconfirmed)

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# File 'lib/bsv/network/utxo.rb', line 12

def initialize(tx_hash:, tx_pos:, satoshis: nil, value: nil, height: nil)
  @tx_hash = tx_hash
  @tx_pos = tx_pos
  @satoshis = satoshis || value
  raise ArgumentError, 'satoshis or value is required' if @satoshis.nil?

  @height = height
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



6
7
8
# File 'lib/bsv/network/utxo.rb', line 6

def height
  @height
end

#satoshisObject (readonly)

Returns the value of attribute satoshis.



6
7
8
# File 'lib/bsv/network/utxo.rb', line 6

def satoshis
  @satoshis
end

#tx_hashObject (readonly)

Returns the value of attribute tx_hash.



6
7
8
# File 'lib/bsv/network/utxo.rb', line 6

def tx_hash
  @tx_hash
end

#tx_posObject (readonly)

Returns the value of attribute tx_pos.



6
7
8
# File 'lib/bsv/network/utxo.rb', line 6

def tx_pos
  @tx_pos
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



21
22
23
24
25
# File 'lib/bsv/network/utxo.rb', line 21

def ==(other)
  other.is_a?(self.class) &&
    tx_hash == other.tx_hash &&
    tx_pos == other.tx_pos
end

#hashObject



29
30
31
# File 'lib/bsv/network/utxo.rb', line 29

def hash
  [tx_hash, tx_pos].hash
end