class Bitcoin::RPC::HttpServer
Bitcoinrb RPC
server.
Attributes
logger[RW]
node[R]
Public Class Methods
new(node)
click to toggle source
# File lib/bitcoin/rpc/http_server.rb, line 15 def initialize(node) @node = node @logger = Bitcoin::Logger.create(:debug) end
run(node, port = 8332)
click to toggle source
# File lib/bitcoin/rpc/http_server.rb, line 25 def self.run(node, port = 8332) EM.start_server('0.0.0.0', port, HttpServer, node) end
Public Instance Methods
parse_json_params()
click to toggle source
parse request parameter. @return [Array] the array of command and args
# File lib/bitcoin/rpc/http_server.rb, line 57 def parse_json_params params = JSON.parse(@http_post_content) [params['method'], params['params']] end
post_init()
click to toggle source
Calls superclass method
# File lib/bitcoin/rpc/http_server.rb, line 20 def post_init super logger.debug 'start http server.' end
process_http_request()
click to toggle source
process http request.
# File lib/bitcoin/rpc/http_server.rb, line 30 def process_http_request operation = proc { command, args = parse_json_params logger.debug("process http request. command = #{command}") begin send(command, *args).to_json rescue Exception => e e end } callback = proc{ |result| response = EM::DelegatedHttpResponse.new(self) if result.is_a?(Exception) response.status = 500 response.content = result.message else response.status = 200 response.content = result end response.content_type 'application/json' response.send_response } EM.defer(operation, callback) end