Class: Bitcoin::Node::SPV
Overview
SPV class
Instance Attribute Summary collapse
-
#bloom ⇒ Object
Returns the value of attribute bloom.
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
-
#running ⇒ Object
Returns the value of attribute running.
-
#server ⇒ Object
Returns the value of attribute server.
-
#wallet ⇒ Object
Returns the value of attribute wallet.
Instance Method Summary collapse
- #add_observer(observer) ⇒ Object
-
#broadcast(tx) ⇒ Object
broadcast a transaction.
- #delete_observer(observer) ⇒ Object
-
#filter_add(element) ⇒ Object
add filter element to bloom filter.
-
#filter_clear ⇒ Object
clear bloom filter.
-
#initialize(configuration) ⇒ SPV
constructor
A new instance of SPV.
-
#run ⇒ Object
open the node.
-
#shutdown ⇒ Object
close the node.
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
#bloom ⇒ Object
Returns the value of attribute bloom.
14 15 16 |
# File 'lib/bitcoin/node/spv.rb', line 14 def bloom @bloom end |
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
7 8 9 |
# File 'lib/bitcoin/node/spv.rb', line 7 def chain @chain end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/bitcoin/node/spv.rb', line 11 def configuration @configuration end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/bitcoin/node/spv.rb', line 9 def logger @logger end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
8 9 10 |
# File 'lib/bitcoin/node/spv.rb', line 8 def pool @pool end |
#running ⇒ Object
Returns the value of attribute running.
10 11 12 |
# File 'lib/bitcoin/node/spv.rb', line 10 def running @running end |
#server ⇒ Object
Returns the value of attribute server.
12 13 14 |
# File 'lib/bitcoin/node/spv.rb', line 12 def server @server end |
#wallet ⇒ Object
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_clear ⇒ Object
clear bloom filter.
59 60 61 |
# File 'lib/bitcoin/node/spv.rb', line 59 def filter_clear pool.filter_clear end |
#run ⇒ Object
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 |
#shutdown ⇒ Object
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 |