예제 #1
0
def db_class(db_dir, name):
    """Returns a DB engine class."""
    for db_class in util.subclasses(Storage):
        if db_class.__name__.lower() == name.lower():
            db_class.import_module()
            return partial(db_class, db_dir)
    raise RuntimeError(f'unrecognised DB engine "{name}"')
예제 #2
0
 def lookup_xverbytes(verbytes):
     """Return a (is_xpub, coin_class) pair given xpub/xprv verbytes."""
     # Order means BTC testnet will override NMC testnet
     for coin in subclasses(Coin):
         if verbytes == coin.XPUB_VERBYTES:
             return True, coin
         if verbytes == coin.XPRV_VERBYTES:
             return False, coin
     raise CoinError('version bytes unrecognised')
예제 #3
0
    def lookup_coin_class(cls, name, net):
        """Return a coin class given name and network.

        Raise an exception if unrecognised."""
        req_attrs = ['TX_COUNT', 'TX_COUNT_HEIGHT', 'TX_PER_BLOCK']
        for coin in subclasses(Coin):
            if (coin.NAME.lower() == name.lower()
                    and coin.NET.lower() == net.lower()):
                coin_req_attrs = req_attrs.copy()
                missing = [
                    attr for attr in coin_req_attrs if not hasattr(coin, attr)
                ]
                if missing:
                    raise CoinError(
                        f'coin {name} missing {missing} attributes')
                return coin
        raise CoinError(f'unknown coin {name} and network {net} combination')