def main():
    '''Set up logging and run the server.'''
    log_fmt = Env.default('LOG_FORMAT', '%(levelname)s:%(name)s:%(message)s')
    logging.basicConfig(level=logging.INFO, format=log_fmt)
    logging.info('ElectrumX server starting')
    try:
        controller = Controller(Env())
        controller.run()
    except Exception:
        traceback.print_exc()
        logging.critical('ElectrumX server terminated abnormally')
    else:
        logging.info('ElectrumX server terminated normally')
Exemple #2
0
async def query(args):
    env = Env()
    db = DB(env)
    coin = env.coin

    await db._open_dbs(False)

    if not args.scripts:
        await print_stats(db.hist_db, db.utxo_db)
        return
    limit = args.limit
    for arg in args.scripts:
        hashX = arg_to_hashX(coin, arg)
        if not hashX:
            continue
        n = None
        for n, (tx_hash, height) in enumerate(db.get_history(hashX, limit),
                                              start=1):
            print(f'History #{n:,d}: height {height:,d} '
                  f'tx_hash {hash_to_hex_str(tx_hash)}')
        if n is None:
            print('No history found')
        n = None
        for n, utxo in enumerate(db.get_utxos(hashX, limit), start=1):
            print(f'UTXO #{n:,d}: tx_hash {hash_to_hex_str(utxo.tx_hash)} '
                  f'tx_pos {utxo.tx_pos:,d} height {utxo.height:,d} '
                  f'value {utxo.value:,d}')
        if n is None:
            print('No UTXOs found')
        balance = db.get_balance(hashX)
        print(f'Balance: {coin.decimal_value(balance):,f} {coin.SHORTNAME}')
Exemple #3
0
async def query(args):
    env = Env()
    db = DB(env)
    coin = env.coin

    await db.open_for_serving()

    if not args.scripts:
        await print_stats(db.hist_db, db.utxo_db)
        return
    limit = args.limit
    for arg in args.scripts:
        hashX = arg_to_hashX(coin, arg)
        if not hashX:
            continue
        n = None
        history = await db.limited_history(hashX, limit=limit)
        for n, (tx_hash, height) in enumerate(history, start=1):
            print(f'History #{n:,d}: height {height:,d} '
                  f'tx_hash {hash_to_hex_str(tx_hash)}')
        if n is None:
            print('No history found')
        n = None
        utxos = await db.all_utxos(hashX)
        for n, utxo in enumerate(utxos, start=1):
            print(f'UTXO #{n:,d}: tx_hash {hash_to_hex_str(utxo.tx_hash)} '
                  f'tx_pos {utxo.tx_pos:,d} height {utxo.height:,d} '
                  f'value {utxo.value:,d}')
            if n == limit:
                break
        if n is None:
            print('No UTXOs found')
        balance = sum(utxo.value for utxo in utxos)
        print(f'Balance: {coin.decimal_value(balance):,f} {coin.SHORTNAME}')
Exemple #4
0
def main():
    env = Env()
    bp = DB(env)
    coin = env.coin
    if len(sys.argv) == 1:
        count_entries(bp.hist_db, bp.utxo_db)
        return
    argc = 1
    try:
        limit = int(sys.argv[argc])
        argc += 1
    except Exception:
        limit = 10
    for addr in sys.argv[argc:]:
        print('Address: ', addr)
        hashX = coin.address_to_hashX(addr)

        for n, (tx_hash, height) in enumerate(bp.get_history(hashX, limit)):
            print('History #{:d}: hash: {} height: {:d}'.format(
                n + 1, hash_to_hex_str(tx_hash), height))
        n = None
        for n, utxo in enumerate(bp.get_utxos(hashX, limit)):
            print('UTXOs #{:d}: hash: {} pos: {:d} height: {:d} value: {:d}'.
                  format(n + 1, hash_to_hex_str(utxo.tx_hash), utxo.tx_pos,
                         utxo.height, utxo.value))
        if n is None:
            print('No UTXOs')
        balance = bp.get_balance(hashX)
        print('Balance: {} {}'.format(coin.decimal_value(balance),
                                      coin.SHORTNAME))
def main():
    '''Set up logging and run the server.'''
    log_fmt = Env.default('LOG_FORMAT', '%(levelname)s:%(name)s:%(message)s')
    handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(CompactFormatter(log_fmt))
    logger = make_logger('electrumx', handler=handler, level='INFO')

    logger.info('ElectrumX server starting')
    try:
        env = Env()
        logger.info(f'logging level: {env.log_level}')
        logger.setLevel(env.log_level)
        controller = Controller(env)
        controller.run()
    except Exception:
        traceback.print_exc()
        logger.critical('ElectrumX server terminated abnormally')
    else:
        logger.info('ElectrumX server terminated normally')
Exemple #6
0
def compact_history():
    if sys.version_info < (3, 6):
        raise RuntimeError('Python >= 3.6 is required to run ElectrumX')

    environ['DAEMON_URL'] = ''   # Avoid Env erroring out
    env = Env()
    db = DB(env)

    assert not db.first_sync
    history = db.history
    # Continue where we left off, if interrupted
    if history.comp_cursor == -1:
        history.comp_cursor = 0

    history.comp_flush_count = max(history.comp_flush_count, 1)
    limit = 8 * 1000 * 1000

    while history.comp_cursor != -1:
        history._compact_history(limit)

    # When completed also update the UTXO flush count
    db.set_flush_count(history.flush_count)