Class: Bitcoin::Node::SPV

Inherits:
Object show all
Defined in:
lib/bitcoin/node/spv.rb

Overview

SPV class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ SPV

Returns a new instance of SPV.



16
17
18
19
20
21
22
23
24
25
# File 'lib/bitcoin/node/spv.rb', line 16

def initialize(configuration)
  @chain = Bitcoin::Store::SPVChain.new
  @configuration = configuration
  @pool = Bitcoin::Network::Pool.new(self, @chain, @configuration)
  @logger = Bitcoin::Logger.create(:debug)
  @running = false
  @wallet = Bitcoin::Wallet::Base.current_wallet
  # TODO : optimize bloom filter parameters
  setup_filter
end

Instance Attribute Details

#bloomObject

Returns the value of attribute bloom.



14
15
16
# File 'lib/bitcoin/node/spv.rb', line 14

def bloom
  @bloom
end

#chainObject (readonly)

Returns the value of attribute chain.



7
8
9
# File 'lib/bitcoin/node/spv.rb', line 7

def chain
  @chain
end

#configurationObject (readonly)

Returns the value of attribute configuration.



11
12
13
# File 'lib/bitcoin/node/spv.rb', line 11

def configuration
  @configuration
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/bitcoin/node/spv.rb', line 9

def logger
  @logger
end

#poolObject (readonly)

Returns the value of attribute pool.



8
9
10
# File 'lib/bitcoin/node/spv.rb', line 8

def pool
  @pool
end

#runningObject

Returns the value of attribute running.



10
11
12
# File 'lib/bitcoin/node/spv.rb', line 10

def running
  @running
end

#serverObject

Returns the value of attribute server.



12
13
14
# File 'lib/bitcoin/node/spv.rb', line 12

def server
  @server
end

#walletObject

Returns the value of attribute wallet.



13
14
15
# File 'lib/bitcoin/node/spv.rb', line 13

def wallet
  @wallet
end

Instance Method Details

#add_observer(observer) ⇒ Object



63
64
65
# File 'lib/bitcoin/node/spv.rb', line 63

def add_observer(observer)
  pool.add_observer(observer)
end

#broadcast(tx) ⇒ Object

broadcast a transaction



46
47
48
49
# File 'lib/bitcoin/node/spv.rb', line 46

def broadcast(tx)
  pool.broadcast(tx)
  logger.debug "broadcast tx: #{tx.to_payload.bth}"
end

#delete_observer(observer) ⇒ Object



67
68
69
# File 'lib/bitcoin/node/spv.rb', line 67

def delete_observer(observer)
  pool.delete_observer(observer)
end

#filter_add(element) ⇒ Object

add filter element to bloom filter.

String

element. the hex string of txid, public key, public key hash or outpoint.



53
54
55
56
# File 'lib/bitcoin/node/spv.rb', line 53

def filter_add(element)
  bloom.add(element)
  pool.filter_add(element)
end

#filter_clearObject

clear bloom filter.



59
60
61
# File 'lib/bitcoin/node/spv.rb', line 59

def filter_clear
  pool.filter_clear
end

#runObject

open the node.



28
29
30
31
32
33
34
35
36
37
# File 'lib/bitcoin/node/spv.rb', line 28

def run
  # TODO need process running check.
  return if running
  logger.debug 'SPV node start running.'
  EM.run do
    # EM.start_server('0.0.0.0', Bitcoin.chain_params.default_port, Bitcoin::Network::InboundConnector, self)
    pool.start
    @server = Bitcoin::RPC::HttpServer.run(self, configuration.port)
  end
end

#shutdownObject

close the node.



40
41
42
43
# File 'lib/bitcoin/node/spv.rb', line 40

def shutdown
  pool.terminate
  logger.debug 'SPV node shutdown.'
end