Class: Bitcoin::Node::SPV

Inherits:
Object
  • 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

Initialize spv settings “‘ruby config = Bitcoin::Node::Configuration.new(network: :mainnet) spv = Bitcoin::Node::SPV.new(config) spv.run ““

Parameters:



24
25
26
27
28
29
30
31
32
33
# File 'lib/bitcoin/node/spv.rb', line 24

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



71
72
73
# File 'lib/bitcoin/node/spv.rb', line 71

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

#broadcast(tx) ⇒ Object

broadcast a transaction



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

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

#delete_observer(observer) ⇒ Object



75
76
77
# File 'lib/bitcoin/node/spv.rb', line 75

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.



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

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

#filter_clearObject

clear bloom filter.



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

def filter_clear
  pool.filter_clear
end

#runObject

open the node.



36
37
38
39
40
41
42
43
44
45
# File 'lib/bitcoin/node/spv.rb', line 36

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.



48
49
50
51
# File 'lib/bitcoin/node/spv.rb', line 48

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