class Tapyrus::Node::SPV
SPV
class
Attributes
bloom[RW]
chain[R]
configuration[R]
logger[R]
pool[R]
running[RW]
server[RW]
wallet[RW]
Public Class Methods
new(configuration)
click to toggle source
# 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
Public Instance Methods
add_observer(observer)
click to toggle source
# File lib/tapyrus/node/spv.rb, line 62 def add_observer(observer) pool.add_observer(observer) end
broadcast(tx)
click to toggle source
broadcast a transaction
# 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)
click to toggle source
# File lib/tapyrus/node/spv.rb, line 66 def delete_observer(observer) pool.delete_observer(observer) end
filter_add(element)
click to toggle source
add filter element to bloom filter.
String
-
element. the hex string of txid, public key, public key hash or outpoint.
# File lib/tapyrus/node/spv.rb, line 52 def filter_add(element) bloom.add(element) pool.filter_add(element) end
filter_clear()
click to toggle source
clear bloom filter.
# File lib/tapyrus/node/spv.rb, line 58 def filter_clear pool.filter_clear end
run()
click to toggle source
open the node.
# 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()
click to toggle source
close the node.
# File lib/tapyrus/node/spv.rb, line 39 def shutdown pool.terminate logger.debug 'SPV node shutdown.' end
Private Instance Methods
setup_filter()
click to toggle source
# File lib/tapyrus/node/spv.rb, line 72 def setup_filter @bloom = Tapyrus::BloomFilter.create_filter(512, 0.01) wallet.watch_targets.each { |t| bloom.add(t.htb) } if wallet end