# Path: jmbase/jmbase/support.py
# def get_log():
#     """
#     provides joinmarket logging instance
#     :return: log instance
#     """
#     return log
# 
# def bintohex(b):
#     """Convert bytes to a hex string"""
#     return binascii.hexlify(b).decode('utf8')
# 
# EXIT_FAILURE = 1
# 
# def hexbin(func):
#     """ Decorator for functions of taker and maker receiving over
#     the wire AMP arguments that may be in hex or hextxid:n format
#     and converting all to binary.
#     Functions to which this decorator applies should have all arguments
#     be one of:
#     - hex string (keys), converted here to binary
#     - lists of keys or txid:n strings (converted here to binary, or
#       (txidbytes, n))
#     - lists of lists or dicts, to which these rules apply recursively.
#     - any other string (unchanged)
#     - dicts with keys as per above; values are altered recursively according
#       to the rules above.
#     """
#     @wraps(func)
#     def func_wrapper(inst, *args, **kwargs):
#         newargs = []
#         for arg in args:
#             if isinstance(arg, (list, tuple)):
#                 newargs.append(listchanger(arg))
#             elif isinstance(arg, dict):
#                 newargs.append(dictchanger(arg))
#             else:
#                 newargs.append(_convert(arg))
#         return func(inst, *newargs, **kwargs)
# 
#     return func_wrapper
# 
# Path: jmclient/jmclient/cryptoengine.py
# class EngineError(Exception):
#     pass


import base64
import sys
import abc
import atexit
import jmbitcoin as btc
from jmbase import bintohex, hexbin, get_log, EXIT_FAILURE
from jmclient.wallet_service import WalletService
from jmclient.configure import jm_single
from jmclient.support import calc_cj_fee
from jmclient.podle import verify_podle, PoDLE, PoDLEError
from twisted.internet import task
from .cryptoengine import EngineError
            cr_dict = PoDLE.deserialize_revelation(cr)
        except PoDLEError as e:
            reason = repr(e)
            return reject(reason)

        if not verify_podle(cr_dict['P'], cr_dict['P2'], cr_dict['sig'],
                                cr_dict['e'], commitment, index_range=range(tries)):
            reason = "verify_podle failed"
            return reject(reason)
        #finally, check that the proffered utxo is real, old enough, large enough,
        #and corresponds to the pubkey
        res = jm_single().bc_interface.query_utxo_set([cr_dict['utxo']],
                                                      includeconf=True)
        if len(res) != 1 or not res[0]:
            reason = "authorizing utxo is not valid"
            return reject(reason)
        age = jm_single().config.getint("POLICY", "taker_utxo_age")
        if res[0]['confirms'] < age:
            reason = "commitment utxo not old enough: " + str(res[0]['confirms'])
            return reject(reason)
        reqd_amt = int(amount * jm_single().config.getint(
            "POLICY", "taker_utxo_amtpercent") / 100.0)
        if res[0]['value'] < reqd_amt:
            reason = "commitment utxo too small: " + str(res[0]['value'])
            return reject(reason)

        try:
            if not self.wallet_service.pubkey_has_script(
                    cr_dict['P'], res[0]['script']):
                raise EngineError()

# Path: jmbase/jmbase/support.py
# def get_log():
#     """
#     provides joinmarket logging instance
#     :return: log instance
#     """
#     return log
# 
# def bintohex(b):
#     """Convert bytes to a hex string"""
#     return binascii.hexlify(b).decode('utf8')
# 
# EXIT_FAILURE = 1
# 
# def hexbin(func):
#     """ Decorator for functions of taker and maker receiving over
#     the wire AMP arguments that may be in hex or hextxid:n format
#     and converting all to binary.
#     Functions to which this decorator applies should have all arguments
#     be one of:
#     - hex string (keys), converted here to binary
#     - lists of keys or txid:n strings (converted here to binary, or
#       (txidbytes, n))
#     - lists of lists or dicts, to which these rules apply recursively.
#     - any other string (unchanged)
#     - dicts with keys as per above; values are altered recursively according
#       to the rules above.
#     """
#     @wraps(func)
#     def func_wrapper(inst, *args, **kwargs):
#         newargs = []
#         for arg in args:
#             if isinstance(arg, (list, tuple)):
#                 newargs.append(listchanger(arg))
#             elif isinstance(arg, dict):
#                 newargs.append(dictchanger(arg))
#             else:
#                 newargs.append(_convert(arg))
#         return func(inst, *newargs, **kwargs)
# 
#     return func_wrapper
# 
# Path: jmclient/jmclient/cryptoengine.py
# class EngineError(Exception):
#     pass


# Path: jmclient/jmclient/maker.py
import base64
import sys
import abc
import atexit
import jmbitcoin as btc
from jmbase import bintohex, hexbin, get_log, EXIT_FAILURE
from jmclient.wallet_service import WalletService
from jmclient.configure import jm_single
from jmclient.support import calc_cj_fee
from jmclient.podle import verify_podle, PoDLE, PoDLEError
from twisted.internet import task
from .cryptoengine import EngineError

            cr_dict = PoDLE.deserialize_revelation(cr)
        except PoDLEError as e:
            reason = repr(e)
            return reject(reason)

        if not verify_podle(cr_dict['P'], cr_dict['P2'], cr_dict['sig'],
                                cr_dict['e'], commitment, index_range=range(tries)):
            reason = "verify_podle failed"
            return reject(reason)
        #finally, check that the proffered utxo is real, old enough, large enough,
        #and corresponds to the pubkey
        res = jm_single().bc_interface.query_utxo_set([cr_dict['utxo']],
                                                      includeconf=True)
        if len(res) != 1 or not res[0]:
            reason = "authorizing utxo is not valid"
            return reject(reason)
        age = jm_single().config.getint("POLICY", "taker_utxo_age")
        if res[0]['confirms'] < age:
            reason = "commitment utxo not old enough: " + str(res[0]['confirms'])
            return reject(reason)
        reqd_amt = int(amount * jm_single().config.getint(
            "POLICY", "taker_utxo_amtpercent") / 100.0)
        if res[0]['value'] < reqd_amt:
            reason = "commitment utxo too small: " + str(res[0]['value'])
            return reject(reason)

        try:
            if not self.wallet_service.pubkey_has_script(
                    cr_dict['P'], res[0]['script']):
                raise EngineError()

        except EngineError: