Class: Bitcoin::Wallet::UtxoHandler

Inherits:
Concurrent::Actor::Context
  • Object
show all
Defined in:
lib/bitcoin/wallet/utxo_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spv, publisher) ⇒ UtxoHandler

Returns a new instance of UtxoHandler.



6
7
8
9
10
11
12
13
14
# File 'lib/bitcoin/wallet/utxo_handler.rb', line 6

def initialize(spv, publisher)
  @watchings = []
  @pendings = []
  @spv = spv
  @spv.add_observer(self)

  @utxo_db = spv.wallet.utxo_db
  @publisher = publisher
end

Instance Attribute Details

#pendingsObject (readonly)

Returns the value of attribute pendings.



4
5
6
# File 'lib/bitcoin/wallet/utxo_handler.rb', line 4

def pendings
  @pendings
end

#publisherObject (readonly)

Returns the value of attribute publisher.



4
5
6
# File 'lib/bitcoin/wallet/utxo_handler.rb', line 4

def publisher
  @publisher
end

#spvObject (readonly)

Returns the value of attribute spv.



4
5
6
# File 'lib/bitcoin/wallet/utxo_handler.rb', line 4

def spv
  @spv
end

#utxo_dbObject (readonly)

Returns the value of attribute utxo_db.



4
5
6
# File 'lib/bitcoin/wallet/utxo_handler.rb', line 4

def utxo_db
  @utxo_db
end

#watchingsObject (readonly)

Returns the value of attribute watchings.



4
5
6
# File 'lib/bitcoin/wallet/utxo_handler.rb', line 4

def watchings
  @watchings
end

Instance Method Details

#on_message(message) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bitcoin/wallet/utxo_handler.rb', line 20

def on_message(message)
  case message
  when Bitcoin::Grpc::WatchTxConfirmedRequest
    spv.filter_add(message.tx_hash)
    watchings << message
  when Bitcoin::Grpc::WatchUtxoSpentRequest
    outpoint = Bitcoin::OutPoint.new(message.tx_hash, message.output_index)
    spv.filter_add(outpoint.to_payload.bth)
    watchings << message
  when :watchings
    watchings
  end
end

#update(event, data) ⇒ Object



16
17
18
# File 'lib/bitcoin/wallet/utxo_handler.rb', line 16

def update(event, data)
  send(event, data)
end