# Path: authproxy.py
# class AuthServiceProxy(object):
#     def __init__(self, serviceURL, serviceName=None):
#         self.__serviceURL = serviceURL
#         self.__serviceName = serviceName
#         self.__url = urlparse.urlparse(serviceURL)
#         if self.__url.port is None:
#             port = 80
#         else:
#             port = self.__url.port
#         self.__idcnt = 0
#         authpair = "%s:%s" % (self.__url.username, self.__url.password)
#         self.__authhdr = "Basic %s" % (base64.b64encode(authpair))
#         self.__conn = httplib.HTTPConnection(self.__url.hostname, port, False,
#                              HTTP_TIMEOUT)
# 
#     def __getattr__(self, name):
#         if self.__serviceName != None:
#             name = "%s.%s" % (self.__serviceName, name)
#         return AuthServiceProxy(self.__serviceURL, name)
# 
#     def __call__(self, *args):
#         self.__idcnt += 1
# 
#         postdata = json.dumps({
#             'version': '1.1',
#              'method': self.__serviceName,
#             'params': args,
#             'id': self.__idcnt})
#         try:
#             self.__conn.request('POST', self.__url.path, postdata,
#                 { 'Host' : self.__url.hostname,
#                 'User-Agent' : USER_AGENT,
#                 'Authorization' : self.__authhdr,
#                 'Content-type' : 'application/json' })
#         except EnvironmentError as e:
#             if e.errno == errno.ECONNREFUSED:
#                 raise JSONRPCException({
#                     'code' : -341, 'message' : 'connection refused'})
#             else:
#                 raise # re-raise otherwise
# 
#         httpresp = self.__conn.getresponse()
#         if httpresp is None:
#              raise JSONRPCException({
#                  'code' : -342, 'message' : 'missing HTTP response from server'})
# 
#         resp = json.loads(httpresp.read(), parse_float=decimal.Decimal)
#         if resp['error'] != None:
#             raise JSONRPCException(resp['error'])
#         elif 'result' not in resp:
#              raise JSONRPCException({
#                  'code' : -343, 'message' : 'missing JSON-RPC result'})
#         else:
#             return resp['result']
# 
# class JSONRPCException(Exception):
#     def __init__(self, rpcError):
#         Exception.__init__(self)
#         self.error = rpcError


import qrencode
import urllib
import re
from StringIO import StringIO
from PIL import Image
from PyQt4 import QtGui
from PyQt4 import QtCore
from authproxy import AuthServiceProxy, JSONRPCException
from merchantgui import MerchantGUI
from customerdisplay import CustomerDisplay

    def _new_transaction_received(self, txid):
        # check if we are waiting for a payment
        if self.current_address == "": return

        # check if the txid looks sane before passing it
        # to bitcoind (for security reasons; might be overly
        # paranoid, but can't hurt)
        if re.search("^[a-f0-9]*$", txid) == None: return

        tx_info = self.bitcoind.gettransaction(txid)
        output_addresses = []
        for detail in tx_info['details']:
            output_addresses.append(detail['address'])
        if self.current_address not in output_addresses: return

        msg = "Transaction to %s received." % self.current_address
        (from_green_address, green_address_msg) = self.green_address_check(txid)
        if from_green_address: msg += " " + green_address_msg

        self.merchant_gui.update_status(msg)
        self.customer_display.evaluate_java_script('show_payment_received()')
        self.current_address = ""

    def bluetooth_available(self, bt_addr):
        self.bt_addr = bt_addr

    def new_transaction_via_bluetooth(self, tx):
        try:
            self.bitcoind.sendrawtransaction(tx)

# Path: authproxy.py
# class AuthServiceProxy(object):
#     def __init__(self, serviceURL, serviceName=None):
#         self.__serviceURL = serviceURL
#         self.__serviceName = serviceName
#         self.__url = urlparse.urlparse(serviceURL)
#         if self.__url.port is None:
#             port = 80
#         else:
#             port = self.__url.port
#         self.__idcnt = 0
#         authpair = "%s:%s" % (self.__url.username, self.__url.password)
#         self.__authhdr = "Basic %s" % (base64.b64encode(authpair))
#         self.__conn = httplib.HTTPConnection(self.__url.hostname, port, False,
#                              HTTP_TIMEOUT)
# 
#     def __getattr__(self, name):
#         if self.__serviceName != None:
#             name = "%s.%s" % (self.__serviceName, name)
#         return AuthServiceProxy(self.__serviceURL, name)
# 
#     def __call__(self, *args):
#         self.__idcnt += 1
# 
#         postdata = json.dumps({
#             'version': '1.1',
#              'method': self.__serviceName,
#             'params': args,
#             'id': self.__idcnt})
#         try:
#             self.__conn.request('POST', self.__url.path, postdata,
#                 { 'Host' : self.__url.hostname,
#                 'User-Agent' : USER_AGENT,
#                 'Authorization' : self.__authhdr,
#                 'Content-type' : 'application/json' })
#         except EnvironmentError as e:
#             if e.errno == errno.ECONNREFUSED:
#                 raise JSONRPCException({
#                     'code' : -341, 'message' : 'connection refused'})
#             else:
#                 raise # re-raise otherwise
# 
#         httpresp = self.__conn.getresponse()
#         if httpresp is None:
#              raise JSONRPCException({
#                  'code' : -342, 'message' : 'missing HTTP response from server'})
# 
#         resp = json.loads(httpresp.read(), parse_float=decimal.Decimal)
#         if resp['error'] != None:
#             raise JSONRPCException(resp['error'])
#         elif 'result' not in resp:
#              raise JSONRPCException({
#                  'code' : -343, 'message' : 'missing JSON-RPC result'})
#         else:
#             return resp['result']
# 
# class JSONRPCException(Exception):
#     def __init__(self, rpcError):
#         Exception.__init__(self)
#         self.error = rpcError


# Path: controller.py
import qrencode
import urllib
import re
from StringIO import StringIO
from PIL import Image
from PyQt4 import QtGui
from PyQt4 import QtCore
from authproxy import AuthServiceProxy, JSONRPCException
from merchantgui import MerchantGUI
from customerdisplay import CustomerDisplay


    def _new_transaction_received(self, txid):
        # check if we are waiting for a payment
        if self.current_address == "": return

        # check if the txid looks sane before passing it
        # to bitcoind (for security reasons; might be overly
        # paranoid, but can't hurt)
        if re.search("^[a-f0-9]*$", txid) == None: return

        tx_info = self.bitcoind.gettransaction(txid)
        output_addresses = []
        for detail in tx_info['details']:
            output_addresses.append(detail['address'])
        if self.current_address not in output_addresses: return

        msg = "Transaction to %s received." % self.current_address
        (from_green_address, green_address_msg) = self.green_address_check(txid)
        if from_green_address: msg += " " + green_address_msg

        self.merchant_gui.update_status(msg)
        self.customer_display.evaluate_java_script('show_payment_received()')
        self.current_address = ""

    def bluetooth_available(self, bt_addr):
        self.bt_addr = bt_addr

    def new_transaction_via_bluetooth(self, tx):
        try:
            self.bitcoind.sendrawtransaction(tx)

        except JSONRPCException: