Class: XRBP::Model::Ledger
- Extended by:
- Base::ClassMethods
- Defined in:
- lib/xrbp/model/ledger.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Attributes included from Base::ClassMethods
Attributes inherited from Base
Class Method Summary collapse
-
.subscribe(opts = {}, &bl) ⇒ Object
Subscribe to ledger stream via WebSocket::Connection.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Ledger
constructor
A new instance of Ledger.
-
#sync(opts = {}, &bl) ⇒ Object
Retreive specified ledger via WebSocket::Connection.
Methods included from Base::ClassMethods
Methods inherited from Base
Constructor Details
#initialize(opts = {}) ⇒ Ledger
Returns a new instance of Ledger.
8 9 10 11 |
# File 'lib/xrbp/model/ledger.rb', line 8 def initialize(opts={}) @id = opts[:id] super(opts) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/xrbp/model/ledger.rb', line 6 def id @id end |
Class Method Details
.subscribe(opts = {}, &bl) ⇒ Object
Subscribe to ledger stream via WebSocket::Connection
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xrbp/model/ledger.rb', line 28 def self.subscribe(opts={}, &bl) set_opts(opts) conn = connection conn.cmd(WebSocket::Cmds::Subscribe.new(:streams => ["ledger"]), &bl) conn.on :message do |*args| c,msg = args.size > 1 ? [args[0], args[1]] : [nil, args[0]] begin i = JSON.parse(msg.to_s) if i["ledger_hash"] && i["ledger_index"] if c conn.emit :ledger, c, i else conn.emit :ledger, i conn.parent.emit :ledger, conn, i if conn.parent end end rescue end end end |