Class: Bitcoin::Gui::Connection
- Inherits:
-
Object
- Object
- Bitcoin::Gui::Connection
- Defined in:
- lib/bitcoin/gui/connection.rb
Instance Method Summary collapse
-
#initialize(host, port, gui) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(host, port, gui) ⇒ Connection
Returns a new instance of Connection.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bitcoin/gui/connection.rb', line 15 def initialize host, port, gui @gui = gui @gui.node = Bitcoin::Network::CommandClient.connect(host, port, gui) do on_connected do request :info request :monitor, "block", "connection" end on_info do |info| text = "connections: #{info['connections']} | " + "addrs: #{info['addrs']} | uptime: #{info['uptime']}" gui { status_network.push 0, text } EM::defer { sleep(1) && request(:info) } end on_block do |block, depth| gui { status_store.push 0, "Blocks: #{depth}" } end on_connection do |state, data| if state == "connected" gui.conn_view.connected(data) elsif state == "disconnected" gui.conn_view.disconnected(data) end gui do size = 0 v, i = conn_view.model.get_iter_first while v size += 1 v = conn_view.model.iter_next(i.to_ptr) end p = notebook.get_nth_page(2) l = Gtk::Label.new("Connections (#{size})") notebook.set_tab_label(p, l) end end on_disconnected do if @connection_attempts == 4 gui do (:warning, "Node not available", "The bitcoin node is not running " + "or not reachable.\nYou can use the wallet to handle keys but you won't " + "be able to send/receive transactions.", [:ok]) end end gui.status_network.push 0, "Offline" end end end |