Sha256: a390e7611c5b035fca707c47760c6ff94a7025d26a62616356aaaeef57eddf06
Contents?: true
Size: 1.11 KB
Versions: 15
Compression:
Stored size: 1.11 KB
Contents
# *-* encoding: utf-8 *-* require 'net/http' require 'uri' require 'json' require 'yaml' module Mastercoin class BitcoinWrapper # also see: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list def initialize(service_url) @uri = URI.parse(service_url) end 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 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 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 class JSONRPCError < RuntimeError; end end end
Version data entries
15 entries across 15 versions & 1 rubygems