Пример #1
0
    def _set_config(self, **kwargs):
        # A fast way to set defaults for the kwargs then set them as attributes
        self.config = dict(maxsize=10,
                           tx_fee=0,
                           min_confirms=6,
                           enabled=True,
                           account="",
                           logger_name="coin_rpc",
                           log_level="INFO")
        self.config.update(kwargs)

        required_conf = ['coinserv', 'currency_code']
        error = False
        for req in required_conf:
            if req not in self.config:
                print("{} is a required configuration variable".format(req))
                error = True

        coinserv_required_conf = ['username', 'password', 'address', 'port']
        for req in coinserv_required_conf:
            if req not in self.coinserv:
                print(
                    "{} is a required coinserv configuration variable".format(
                        req))
                error = True

        if error:
            raise CoinRPCException({
                'code':
                -1,
                'message':
                'Errors occurred while configuring '
                'CoinRPC obj'
            })
Пример #2
0
def rpc_conn(func, *args, **kwargs):
    """
    Catches all uncaught exceptions and coerces them to a CoinRPCException
    """
    try:
        res = func(*args, **kwargs)
    except Exception as e:
        raise CoinRPCException(
            {'code': -1, 'message': 'Unhandled error in \'{}\': {}'.
            format(e.__class__.__name__, e)})
    else:
        return res
Пример #3
0
    def __init__(self, config, logger=None):
        if not config:
            raise CoinRPCException(
                {'code': -1, 'message': 'Invalid configuration file'})

        self._set_config(**config)

        if logger:
            self.logger = logger
        else:
            logging.Formatter.converter = datetime.time.gmtime
            self.logger = logging.getLogger(self.config['logger_name'])
            self.logger.setLevel(getattr(logging, self.config['log_level']))

        self.conn = CoinserverRPC("http://{0}:{1}@{2}:{3}/"
            .format(self.coinserv['username'], self.coinserv['password'],
                    self.coinserv['address'], self.coinserv['port'],
                    pool_kwargs=dict(maxsize=self.maxsize)))