Class: Bitcoin::Node::SPV
- Inherits:
-
Object
- Object
- Bitcoin::Node::SPV
- Defined in:
- lib/bitcoin/node/spv.rb
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
Initialize spv settings “‘ruby config = Bitcoin::Node::Configuration.new(network: :mainnet) spv = Bitcoin::Node::SPV.new(config) spv.run ““.
-
#run ⇒ Object
open the node.
-
#shutdown ⇒ Object
close the node.
Constructor Details
#initialize(configuration) ⇒ SPV
Initialize spv settings “‘ruby config = Bitcoin::Node::Configuration.new(network: :mainnet) spv = Bitcoin::Node::SPV.new(config) spv.run ““
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
#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
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_clear ⇒ Object
clear bloom filter.
67 68 69 |
# File 'lib/bitcoin/node/spv.rb', line 67 def filter_clear pool.filter_clear end |
#run ⇒ Object
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 |
#shutdown ⇒ Object
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 |