module XRBP::DSL

The DSL namespace can be included in client logic to provide an easy-to-use mechanism to read and write XRP data.

@example Retrieve ledger, subscribe to updates

include XRBP::DSL

puts "Genesis ledger: "
puts ledger(32570)

websocket_msg do |msg|
  puts "Ledger received:"
  puts msg
end

subscribe_to_ledgers

Public Instance Methods

account_info(id) click to toggle source

Return info for the specified account id

@param id [String] account id to query @return [Hash, nil] the account info or nil otherwise

# File lib/xrbp/dsl/accounts.rb, line 7
def account_info(id)
  websocket.add_plugin :autoconnect unless websocket.plugin?(:autoconnect)
  websocket.add_plugin :command_dispatcher unless websocket.plugin?(:command_dispatcher)
  websocket.cmd(WebSocket::Cmds::AccountInfo.new(id))
end
ledger(id=nil) click to toggle source

Return ledger object for the specified id

@param id [Integer] id of the ledger to query @return [Hash, nil] the ledger object retrieved or nil otherwise

# File lib/xrbp/dsl/ledgers.rb, line 7
def ledger(id=nil)
  websocket.add_plugin :autoconnect unless websocket.plugin?(:autoconnect)
  websocket.add_plugin :command_dispatcher unless websocket.plugin?(:command_dispatcher)
  websocket.cmd(WebSocket::Cmds::Ledger.new(id))
end
subscribe_to_ledgers() click to toggle source

Subscribed to the ledger stream.

After calling this, :ledger events will be emitted via the websocket connection object.

# File lib/xrbp/dsl/ledgers.rb, line 17
def subscribe_to_ledgers
  websocket.add_plugin :autoconnect unless websocket.plugin?(:autoconnect)
  websocket.add_plugin :command_dispatcher unless websocket.plugin?(:command_dispatcher)
  websocket.cmd(WebSocket::Cmds::Subscribe.new(:streams => ["ledger"]))
end
validators() click to toggle source

Return list of all validators

@return [Array<Hash>] list of validators retrieved

# File lib/xrbp/dsl/validators.rb, line 6
def validators
  Model::Validator.all :connection => webclient
end
webclient() click to toggle source

Client which may be used to access HTTP resources

# File lib/xrbp/dsl/webclient.rb, line 4
def webclient
  @webclient ||= WebClient::Connection.new
end
websocket() click to toggle source

Client which may be used to access websocket endpoints.

By default a RoundRobin strategy will be used to cycle through specified endpoints.

# File lib/xrbp/dsl/websocket.rb, line 13
def websocket
  @websocket ||= WebSocket::RoundRobin.new *websocket_endpoints
end
websocket_endpoints() click to toggle source

Default websocket endpoints. Override to specify different ones.

# File lib/xrbp/dsl/websocket.rb, line 5
def websocket_endpoints
  ["wss://s1.ripple.com:443", "wss://s2.ripple.com:443"]
end
websocket_msg(&bl) click to toggle source

Register a callback to be invoked when messages are received via websocket connections

# File lib/xrbp/dsl/websocket.rb, line 19
def websocket_msg(&bl)
  websocket.on :message, &bl
end
websocket_wait() click to toggle source

Block until all websocket connections are closed

# File lib/xrbp/dsl/websocket.rb, line 24
def websocket_wait
  websocket.wait_for_close
end