class Mastercoin::BitcoinWrapper
Public Class Methods
new(service_url)
click to toggle source
also see: en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list
# File lib/mastercoin-ruby/bitcoin_wrapper.rb, line 9 def initialize(service_url) @uri = URI.parse(service_url) end
Public Instance Methods
http_post_request(post_body)
click to toggle source
# File lib/mastercoin-ruby/bitcoin_wrapper.rb, line 31 def http_post_request(post_body) http = Net::HTTP.new(@uri.host, @uri.port) request = Net::HTTP::Post.new(@uri.request_uri) request.basic_auth @uri.user, @uri.password request.content_type = 'application/json' request.body = post_body http.request(request).body end
method_missing(name, *args)
click to toggle source
# File lib/mastercoin-ruby/bitcoin_wrapper.rb, line 22 def method_missing(name, *args) post_body = { 'method' => name, 'params' => args, 'id' => 'jsonrpc' }.to_json resp = JSON.parse( http_post_request(post_body) ) raise JSONRPCError, resp['error'] if resp['error'] resp['result'] end
unspend_for_address(address)
click to toggle source
# File lib/mastercoin-ruby/bitcoin_wrapper.rb, line 13 def unspend_for_address(address) unspend = self.listunspent.find{|x| x["address"] == address} if unspend.is_a?(Array) return unspend else return [unspend] end end