Class: Tapyrus::Node::SPV
- Inherits:
-
Object
- Object
- Tapyrus::Node::SPV
- Defined in:
- lib/tapyrus/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
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.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tapyrus/node/spv.rb', line 14 def initialize(configuration) @chain = Tapyrus::Store::SPVChain.new @configuration = configuration @pool = Tapyrus::Network::Pool.new(self, @chain, @configuration) @logger = Tapyrus::Logger.create(:debug) @running = false @wallet = Tapyrus::Wallet::Base.current_wallet # TODO : optimize bloom filter parameters setup_filter end |
Instance Attribute Details
#bloom ⇒ Object
Returns the value of attribute bloom.
12 13 14 |
# File 'lib/tapyrus/node/spv.rb', line 12 def bloom @bloom end |
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
5 6 7 |
# File 'lib/tapyrus/node/spv.rb', line 5 def chain @chain end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
9 10 11 |
# File 'lib/tapyrus/node/spv.rb', line 9 def configuration @configuration end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/tapyrus/node/spv.rb', line 7 def logger @logger end |
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
6 7 8 |
# File 'lib/tapyrus/node/spv.rb', line 6 def pool @pool end |
#running ⇒ Object
Returns the value of attribute running.
8 9 10 |
# File 'lib/tapyrus/node/spv.rb', line 8 def running @running end |
#server ⇒ Object
Returns the value of attribute server.
10 11 12 |
# File 'lib/tapyrus/node/spv.rb', line 10 def server @server end |
#wallet ⇒ Object
Returns the value of attribute wallet.
11 12 13 |
# File 'lib/tapyrus/node/spv.rb', line 11 def wallet @wallet end |
Instance Method Details
#add_observer(observer) ⇒ Object
62 63 64 |
# File 'lib/tapyrus/node/spv.rb', line 62 def add_observer(observer) pool.add_observer(observer) end |
#broadcast(tx) ⇒ Object
broadcast a transaction
45 46 47 48 |
# File 'lib/tapyrus/node/spv.rb', line 45 def broadcast(tx) pool.broadcast(tx) logger.debug "broadcast tx: #{tx.to_hex}" end |
#delete_observer(observer) ⇒ Object
66 67 68 |
# File 'lib/tapyrus/node/spv.rb', line 66 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.
52 53 54 55 |
# File 'lib/tapyrus/node/spv.rb', line 52 def filter_add(element) bloom.add(element) pool.filter_add(element) end |
#filter_clear ⇒ Object
clear bloom filter.
58 59 60 |
# File 'lib/tapyrus/node/spv.rb', line 58 def filter_clear pool.filter_clear end |
#run ⇒ Object
open the node.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tapyrus/node/spv.rb', line 27 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', Tapyrus.chain_params.default_port, Tapyrus::Network::InboundConnector, self) pool.start @server = Tapyrus::RPC::HttpServer.run(self, configuration.port) end end |
#shutdown ⇒ Object
close the node.
39 40 41 42 |
# File 'lib/tapyrus/node/spv.rb', line 39 def shutdown pool.terminate logger.debug "SPV node shutdown." end |