class XRBP::Model::Ledger
Attributes
id[RW]
Public Class Methods
new(opts={})
click to toggle source
Calls superclass method
XRBP::Model::Base::new
# File lib/xrbp/model/ledger.rb, line 8 def initialize(opts={}) @id = opts[:id] super(opts) end
subscribe(opts={}, &bl)
click to toggle source
Subscribe to ledger stream via WebSocket::Connection
@param opts [Hash] options to subscribe to ledger stream with @option opts [WebSocket::Connection] :connection Connection
to use to subscribe to ledger stream
# 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
Public Instance Methods
sync(opts={}, &bl)
click to toggle source
Retreive specified ledger via WebSocket::Connection
@param opts [Hash] options to retrieve ledger with @option opts [WebSocket::Connection] :connection Connection
to use to retrieve ledger
# File lib/xrbp/model/ledger.rb, line 18 def sync(opts={}, &bl) set_opts(opts) connection.cmd(WebSocket::Cmds::Ledger.new(id, full_opts.except(:id)), &bl) end