Ejemplo n.º 1
0
def run_blockmirrord():
    """ run blockmirrord
    """
    global blockmirrord
    global bitcoind
    global namecoind
    global cached_namespace
    
    signal.signal(signal.SIGINT, signal_handler)
    
    bitcoin_opts, parser = blockdaemon.parse_bitcoind_args( return_parser=True )
    namecoin_opts, parser = parse_namecoind_args( return_parser=True, parser=parser )
    
    parser.add_argument(
        "--namespace",
        help="path to the cached namespace JSON file")
    
    subparsers = parser.add_subparsers(
        dest='action', help='the action to be taken')
    parser_server = subparsers.add_parser(
        'start',
        help='start the blockmirrord server')
    parser_server.add_argument(
        '--foreground', action='store_true',
        help='start the blockmirrord server in foreground')
    parser_server = subparsers.add_parser(
        'stop',
        help='stop the blockmirrord server')
    
    args, _ = parser.parse_known_args()
    
    # did we get a namespace JSON file?
    if hasattr( args, "namespace" ) and getattr( args, "namespace" ) is not None:
       
       namespace_path = args.namespace
       namespace_json = None 
       
       log.info("Loading JSON from '%s'" % namespace_path)
          
       with open(namespace_path, "r") as namespace_fd:
          namespace_json = namespace_fd.read()
       
       log.info("Parsing JSON")
       
       try:
          cached_namespace = json.loads( namespace_json )
       except Exception, e:
          log.exception(e)
          exit(1)
Ejemplo n.º 2
0
def run_blockmirrord():
    """ run blockmirrord
    """
    global blockmirrord
    global bitcoind
    global namecoind
    global cached_namespace
    
    signal.signal(signal.SIGINT, signal_handler)
    
    bitcoin_opts, parser = blockdaemon.parse_bitcoind_args( return_parser=True )
    namecoin_opts, parser = parse_namecoind_args( return_parser=True, parser=parser )
    
    parser.add_argument(
        "--namespace",
        help="path to the cached namespace JSON file")
    
    subparsers = parser.add_subparsers(
        dest='action', help='the action to be taken')
    parser_server = subparsers.add_parser(
        'start',
        help='start the blockmirrord server')
    parser_server.add_argument(
        '--foreground', action='store_true',
        help='start the blockmirrord server in foreground')
    parser_server = subparsers.add_parser(
        'stop',
        help='stop the blockmirrord server')
    
    args, _ = parser.parse_known_args()
    
    # did we get a namespace JSON file?
    if hasattr( args, "namespace" ) and getattr( args, "namespace" ) is not None:
       
       namespace_path = args.namespace
       namespace_json = None 
       
       log.info("Loading JSON from '%s'" % namespace_path)
          
       with open(namespace_path, "r") as namespace_fd:
          namespace_json = namespace_fd.read()
       
       log.info("Parsing JSON")
       
       try:
          cached_namespace = json.loads( namespace_json )
       except Exception, e:
          log.exception(e)
          exit(1)
Ejemplo n.º 3
0
def do_upgrade(inplace, incode):
    global engine, upgrade_enabled, upgrade_functions

    if StrictVersion(inplace['db_version']) > StrictVersion(
            incode['db_version']):
        raise Exception("DB downgrade not supported")

    if inplace['db_version'] != incode['db_version']:
        print("upgrading DB: from=" + str(inplace['db_version']) + " to=" +
              str(incode['db_version']))

        if upgrade_enabled:
            db_current = inplace['db_version']
            db_target = incode['db_version']

            for version_tuple, functions_to_run in upgrade_functions:
                db_from = version_tuple[0]
                db_to = version_tuple[1]

                # finish if we've reached the target version
                if StrictVersion(db_current) >= StrictVersion(db_target):
                    # done
                    break
                elif StrictVersion(db_to) <= StrictVersion(db_current):
                    # Upgrade code is for older version, skip it.
                    continue
                else:
                    print("Executing upgrade functions for version {} to {}".
                          format(db_from, db_to))
                    for fn in functions_to_run:
                        try:
                            print("Executing upgrade function: {}".format(
                                fn.__name__))
                            fn()
                        except Exception as e:
                            log.exception(
                                'Upgrade function {} raised an error. Failing upgrade.'
                                .format(fn.__name__))
                            raise e

                    db_current = db_to

    if inplace['service_version'] != incode['service_version']:
        print("upgrading service: from=" + str(inplace['service_version']) +
              " to=" + str(incode['service_version']))

    ret = True
    return (ret)
Ejemplo n.º 4
0
def get_index_range(start_block=0):
    """
    """

    from lib.config import FIRST_BLOCK_MAINNET

    if start_block == 0:
        start_block = FIRST_BLOCK_MAINNET

    try:
        current_block = int(bitcoind.getblockcount())
    except Exception, e:
        log.exception(e)
        log.info("ERROR: Cannot connect to bitcoind")
        user_input = raw_input("Do you want to re-enter bitcoind server configs? (yes/no): ")
        if user_input.lower() == "yes" or user_input.lower() == "y":
            prompt_user_for_bitcoind_details()
            log.info("Exiting. Restart blockstored to try the new configs.")
            exit(1)
        else:
            exit(1)
Ejemplo n.º 5
0
def get_index_range(start_block=0):
    """
    """

    from lib.config import FIRST_BLOCK_MAINNET

    if start_block == 0:
        start_block = FIRST_BLOCK_MAINNET

    try:
        current_block = int(bitcoind.getblockcount())
    except Exception, e:
        log.exception(e)
        log.info("ERROR: Cannot connect to bitcoind")
        user_input = raw_input(
            "Do you want to re-enter bitcoind server configs? (yes/no): ")
        if user_input.lower() == "yes" or user_input.lower() == "y":
            prompt_user_for_bitcoind_details()
            log.info("Exiting. Restart blockstored to try the new configs.")
            exit(1)
        else:
            exit(1)
Ejemplo n.º 6
0
        log.info('Blockstored successfully started')

    except IndexError, ie:
        # indicates that we don't have the latest block
        log.error("\n\nFailed to find the first blockstore record (got block %s).\n" % current_block + \
                   "Please verify that your bitcoin provider has " + \
                   "processed up to block %s.\n" % (START_BLOCK) + \
                   "    Example:  bitcoin-cli getblockcount" )
        try:
            os.killpg(blockstored.pid, signal.SIGTERM)
        except:
            pass
        exit(1)

    except Exception as e:
        log.exception(e)
        log.info('Exiting blockstored server')
        try:
            os.killpg(blockstored.pid, signal.SIGTERM)
        except:
            pass
        exit(1)


def run_blockstored():
    """ run blockstored
    """
    global bitcoin_opts

    parser = argparse.ArgumentParser(
        description='Blockstore Core Daemon version {}'.format(config.VERSION))
Ejemplo n.º 7
0
        # begin serving
        blockmirrord = subprocess.Popen( command, shell=True, preexec_fn=os.setsid)
        log.info('Blockmirrord successfully started')

    except IndexError, ie:
        
        traceback.print_exc()
        
        try:
            os.killpg(blockmirrord.pid, signal.SIGTERM)
        except:
            pass
        exit(1)
    
    except Exception, e:
        log.exception(e)
        log.info('Exiting blockmirrord server')
        try:
            os.killpg(blockmirrord.pid, signal.SIGTERM)
        except:
            pass
        exit(1)



def parse_namecoind_args( return_parser=False, parser=None ):
    """
    Get namecoind command-line arguments.
    Optionally return the parser as well.
    """