class Lightning::RPC
RPC
client for the `lightningd` daemon.
Attributes
next_id[RW]
socket_path[R]
Public Class Methods
new(socket_path)
click to toggle source
# File lib/lightning/rpc.rb, line 28 def initialize(socket_path) @socket_path = socket_path @next_id = 0 end
Private Instance Methods
call(method, *kargs)
click to toggle source
# File lib/lightning/rpc.rb, line 35 def call(method, *kargs) UNIXSocket.open(socket_path) do |socket| msg = { method: method.to_s, params: kargs, id: next_id } socket.write(msg.to_json) self.next_id += 1 response = '' loop do response << socket.gets break if response.include?("\n\n") end json = JSON.parse(response) raise RPCError.new(json['error']['code'], json['error']['message']) if json['error'] json['result'] end end
method_missing(method, *args)
click to toggle source
# File lib/lightning/rpc.rb, line 55 def method_missing(method, *args) call(method, *args) end