コード例 #1
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        # monitoring
        self.avg_time = 0, 0, 0
        self.time_ref = time.time()

        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.history_cache = {}
        self.merkle_cache = {}
        self.max_cache_size = 100000
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''
        self.headers_path = config.get('leveldb', 'path')

        self.mempool_fees = {}
        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {}  # addr -> (txid, delta)
        self.mempool_unconfirmed = {}  # txid -> set of unconfirmed inputs
        self.mempool_hashes = set()
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean(
                'leveldb', 'test_reorgs')  # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.dashd_url = 'http://%s:%s@%s:%s/' % (config.get(
            'dashd', 'dashd_user'), config.get(
                'dashd', 'dashd_password'), config.get(
                    'dashd', 'dashd_host'), config.get('dashd', 'dashd_port'))

        self.sent_height = 0
        self.sent_header = None

        # catch_up headers
        self.init_headers(self.storage.height)
        # start catch_up thread
        if config.getboolean('leveldb', 'profiler'):
            filename = os.path.join(config.get('leveldb', 'path'), 'profile')
            print_log('profiled thread', filename)
            self.blockchain_thread = ProfiledThread(filename,
                                                    target=self.do_catch_up)
        else:
            self.blockchain_thread = threading.Thread(target=self.do_catch_up)
        self.blockchain_thread.start()
コード例 #2
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        # monitoring
        self.avg_time = 0,0,0
        self.time_ref = time.time()

        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.history_cache = {}
        self.merkle_cache = {}
        self.max_cache_size = 100000
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''
        self.headers_path = config.get('leveldb', 'path')

        self.mempool_fees = {}
        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {} # addr -> (txid, delta)
        self.mempool_unconfirmed = {} # txid -> set of unconfirmed inputs
        self.mempool_hashes = set()
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean('leveldb', 'test_reorgs')   # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.bitcoind_url = 'http://%s:%s@%s:%s/' % (
            config.get('bitcoind', 'bitcoind_user'),
            config.get('bitcoind', 'bitcoind_password'),
            config.get('bitcoind', 'bitcoind_host'),
            config.get('bitcoind', 'bitcoind_port'))

        self.sent_height = 0
        self.sent_header = None

        # catch_up headers
        self.init_headers(self.storage.height)
        # start catch_up thread
        if config.getboolean('leveldb', 'profiler'):
            filename = os.path.join(config.get('leveldb', 'path'), 'profile')
            print_log('profiled thread', filename)
            self.blockchain_thread = ProfiledThread(filename, target = self.do_catch_up)
        else:
            self.blockchain_thread = threading.Thread(target = self.do_catch_up)
        self.blockchain_thread.start()
コード例 #3
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.active_chain = chainparams.get_active_chain()

        self.mtimes = {}  # monitoring
        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.block_cache = OrderedDict()
        try:
            self.block_cache_size = config.getint('server', 'block_cache_size')
        except ConfigParser.NoOptionError:
            self.block_cache_size = default_block_cache_size

        self.history_cache = {}
        self.max_cache_size = 100000
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''
        self.headers_path = config.get('leveldb', 'path')

        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean(
                'leveldb', 'test_reorgs')  # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.dblock = threading.Lock()

        self.bitcoind_url = 'http://%s:%s@%s:%s/' % (
            config.get('bitcoind', 'bitcoind_user'),
            config.get('bitcoind', 'bitcoind_password'),
            config.get('bitcoind', 'bitcoind_host'),
            config.get('bitcoind', 'bitcoind_port'))

        self.sent_height = 0
        self.sent_header = None

        # catch_up headers
        self.init_headers(self.storage.height)

        self.blockchain_thread = threading.Thread(target=self.do_catch_up)
        self.blockchain_thread.start()
コード例 #4
0
 def __init__(self, config, shared):
     Processor.__init__(self)
     self.daemon = True
     self.config = config
     self.shared = shared
     self.irc_queue = Queue.Queue()
     self.peers = {}
     self.irc = None
コード例 #5
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.active_chain = chainparams.get_active_chain()

        self.mtimes = {} # monitoring
        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.block_cache = OrderedDict()
        try:
            self.block_cache_size = config.getint('server', 'block_cache_size')
        except ConfigParser.NoOptionError:
            self.block_cache_size = default_block_cache_size

        self.history_cache = {}
        self.max_cache_size = 100000
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''
        self.headers_path = config.get('leveldb', 'path')

        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean('leveldb', 'test_reorgs')   # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.dblock = threading.Lock()

        self.bitcoind_url = 'http://%s:%s@%s:%s/' % (
            config.get('bitcoind', 'bitcoind_user'),
            config.get('bitcoind', 'bitcoind_password'),
            config.get('bitcoind', 'bitcoind_host'),
            config.get('bitcoind', 'bitcoind_port'))

        self.sent_height = 0
        self.sent_header = None

        # catch_up headers
        self.init_headers(self.storage.height)

        self.blockchain_thread = threading.Thread(target = self.do_catch_up)
        self.blockchain_thread.start()
コード例 #6
0
 def __init__(self, config):
     Processor.__init__(self)
     cache = HistoryCache()
     self.backend = Backend()
     monitor = MonitorAddress(self, cache, self.backend)
     self.numblocks_subscribe = NumblocksSubscribe(self.backend, self)
     self.address_get_history = AddressGetHistory(self.backend, self)
     self.address_subscribe = \
         AddressSubscribe(self.backend, self, cache, monitor)
コード例 #7
0
 def __init__(self):
     Interface.__init__(self)
     Loader.__init__(self)
     Resizer.__init__(self)
     Processor.__init__(self)
     Colorizer.__init__(self)
     Displayer.__init__(self)
     
     getattr(self, self.args.command)()
コード例 #8
0
 def __init__(self, config):
     Processor.__init__(self)
     cache = HistoryCache()
     self.backend = Backend()
     monitor = MonitorAddress(self, cache, self.backend)
     self.numblocks_subscribe = NumblocksSubscribe(self.backend, self)
     self.address_get_history = AddressGetHistory(self.backend, self)
     self.address_subscribe = \
         AddressSubscribe(self.backend, self, cache, monitor)
コード例 #9
0
    def __init__(self, config):
        Processor.__init__(self)
        self.daemon = True
        self.banner = config.get('server', 'banner')

        if config.get('server', 'irc') == 'yes':
            self.irc = IrcThread(self, config)
        else:
            self.irc = None
コード例 #10
0
    def __init__(self, config):
        Processor.__init__(self)
        self.daemon = True
        self.banner = config.get('server', 'banner')

        if config.get('server', 'irc') == 'yes':
            self.irc = IrcThread(self, config)
        else:
            self.irc = None
コード例 #11
0
ファイル: __init__.py プロジェクト: 9cat/electrum-tpc-server
    def __init__(self, config):
        Processor.__init__(self)
        self.daemon = True
        self.banner = config.get("server", "banner")

        if config.get("server", "irc") == "yes":
            self.irc = IrcThread(self, config)
        else:
            self.irc = None
コード例 #12
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.mtimes = {} # monitoring
        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.history_cache = {}
        self.max_cache_size = 100000
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''
        self.headers_path = config.get('leveldb', 'path')

        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean('leveldb', 'test_reorgs')   # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.dblock = threading.Lock()
        
        self.bitcoind_rpc_ssl = False
        if config.has_option('bitcoind', 'bitcoind_rpc_ssl') and config.get('bitcoind', 'bitcoind_rpc_ssl') == '1':
            self.bitcoind_rpc_ssl = True
        
        self.bitcoind_url = '%s://%s:%s@%s:%s/' % (
            'https' if self.bitcoind_rpc_ssl else 'http',
            config.get('bitcoind', 'bitcoind_user'),
            config.get('bitcoind', 'bitcoind_password'),
            config.get('bitcoind', 'bitcoind_host'),
            config.get('bitcoind', 'bitcoind_port'))

        self.sent_height = 0
        self.sent_header = None

        # catch_up headers
        self.init_headers(self.storage.height)

        self.blockchain_thread = threading.Thread(target = self.do_catch_up)
        self.blockchain_thread.start()
コード例 #13
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.mtimes = {}  # monitoring
        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watch_proposals = []
        self.watched_addresses = {}
        self.watched_masternodes = {}

        self.history_cache = {}
        self.max_cache_size = 100000
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''
        self.headers_path = config.get('leveldb', 'path')

        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean(
                'leveldb', 'test_reorgs')  # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.dblock = threading.Lock()

        self.dashd_url = 'http://%s:%s@%s:%s/' % (config.get(
            'dashd', 'dashd_user'), config.get(
                'dashd', 'dashd_password'), config.get(
                    'dashd', 'dashd_host'), config.get('dashd', 'dashd_port'))

        self.sent_height = 0
        self.sent_header = None
        self.sent_masternodes_status = {}
        self.sent_proposals_status = None

        # catch_up headers
        self.init_headers(self.storage.height)

        self.blockchain_thread = threading.Thread(target=self.do_catch_up)
        self.blockchain_thread.start()
コード例 #14
0
ファイル: __init__.py プロジェクト: colindean/electrum-server
    def __init__(self, config):
        Processor.__init__(self)
        self.store = AbeStore(config)
        self.block_number = -1
        self.watched_addresses = []

        # catch_up first
        n = self.store.main_iteration()
        print "blockchain: %d blocks"%n

        threading.Timer(10, self.run_store_iteration).start()
コード例 #15
0
    def __init__(self, config, shared):
        Processor.__init__(self)
        self.store = AbeStore(config)
        self.watched_addresses = []
        self.shared = shared

        # catch_up first
        self.block_header, time_catch_up, time_mempool, n = self.store.main_iteration()
        self.block_number = self.block_header.get('block_height')
        print_log("blockchain: %d blocks" % self.block_number)

        threading.Timer(10, self.run_store_iteration).start()
コード例 #16
0
    def __init__(self, config, shared):
        Processor.__init__(self)
        self.store = AbeStore(config)
        self.watched_addresses = []
        self.shared = shared

        # catch_up first
        self.block_header, time_catch_up, time_mempool, n = self.store.main_iteration()
        self.block_number = self.block_header.get('block_height')
        print_log("blockchain: %d blocks" % self.block_number)

        threading.Timer(10, self.run_store_iteration).start()
コード例 #17
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.mtimes = {}  # monitoring
        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.history_cache = {}
        self.max_cache_size = 100000
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ""
        self.headers_path = config.get("leveldb", "path")

        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {}  # addr -> (txid, delta)
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean("leveldb", "test_reorgs")  # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.dblock = threading.Lock()

        self.bitcoind_url = "http://%s:%s@%s:%s/" % (
            config.get("bitcoind", "bitcoind_user"),
            config.get("bitcoind", "bitcoind_password"),
            config.get("bitcoind", "bitcoind_host"),
            config.get("bitcoind", "bitcoind_port"),
        )

        self.sent_height = 0
        self.sent_header = None

        # catch_up headers
        self.init_headers(self.storage.height)

        self.blockchain_thread = threading.Thread(target=self.do_catch_up)
        self.blockchain_thread.start()
コード例 #18
0
    def __init__(self, config, shared):
        Processor.__init__(self)
        self.daemon = True
        self.config = config
        self.shared = shared
        self.irc_queue = Queue.Queue()
        self.peers = {}

        if self.config.get('server', 'irc') == 'yes':
            self.irc = IrcThread(self, self.config)
            self.irc.start(self.irc_queue)
            t = threading.Thread(target=self.read_irc_results)
            t.daemon = True
            t.start()
        else:
            self.irc = None
コード例 #19
0
    def __init__(self, config, shared):
        Processor.__init__(self)
        self.daemon = True
        self.config = config
        self.shared = shared
        self.irc_queue = Queue.Queue()
        self.peers = {}

        if self.config.get('server', 'irc') == 'yes':
            self.irc = IrcThread(self, self.config)
            self.irc.start(self.irc_queue)
            t = threading.Thread(target=self.read_irc_results)
            t.daemon = True
            t.start()
        else:
            self.irc = None
コード例 #20
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        # monitoring
        self.avg_time = 0,0,0
        self.time_ref = time.time()

        self.shared = shared
        self.config = config

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}
        self.watched_addresses_flat = {}
        self.mempool_txs = {}
        self.mempool_lock = threading.Lock()
        self.tip = 0

        self.address_queue = Queue()

        self.blockchain_thread = threading.Thread(target = self.do_catch_up)
        self.blockchain_thread.start()
コード例 #21
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.mtimes = {}  # monitoring
        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.history_cache = {}
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ""
        self.headers_path = config.get("leveldb", "path_fulltree")

        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean("leveldb", "test_reorgs")  # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.dblock = threading.Lock()

        self.bitcoind_url = "http://%s:%s@%s:%s/" % (
            config.get("bitcoind", "user"),
            config.get("bitcoind", "password"),
            config.get("bitcoind", "host"),
            config.get("bitcoind", "port"),
        )

        while True:
            try:
                self.bitcoind("getinfo")
                break
            except:
                print_log("cannot contact darkcoind...")
                time.sleep(5)
                continue

        self.sent_height = 0
        self.sent_header = None

        # catch_up headers
        self.init_headers(self.storage.height)

        threading.Timer(0, lambda: self.catch_up(sync=False)).start()
        while not shared.stopped() and not self.up_to_date:
            try:
                time.sleep(1)
            except:
                print "keyboard interrupt: stopping threads"
                shared.stop()
                sys.exit(0)

        print_log("Blockchain is up to date.")
        self.memorypool_update()
        print_log("Memory pool initialized.")

        self.timer = threading.Timer(10, self.main_iteration)
        self.timer.start()
コード例 #22
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.history_cache = {}
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''

        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()
        self.dbpath = config.get('leveldb', 'path')
        self.pruning_limit = config.getint('leveldb', 'pruning_limit')
        self.db_version = 1 # increase this when database needs to be updated

        self.dblock = threading.Lock()
        try:
            self.db = leveldb.LevelDB(self.dbpath, paranoid_checks=True)
        except:
            traceback.print_exc(file=sys.stdout)
            self.shared.stop()

        self.bitcoind_url = 'http://%s:%s@%s:%s/' % (
            config.get('bitcoind', 'user'),
            config.get('bitcoind', 'password'),
            config.get('bitcoind', 'host'),
            config.get('bitcoind', 'port'))

        while True:
            try:
                self.bitcoind('getinfo')
                break
            except:
                print_log('cannot contact bitcoind...')
                time.sleep(5)
                continue

        self.height = 0
        self.is_test = False
        self.sent_height = 0
        self.sent_header = None

        try:
            hist = self.deserialize(self.db.Get('height'))
            self.last_hash, self.height, db_version = hist[0]
            print_log("Database version", self.db_version)
            print_log("Blockchain height", self.height)
        except:
            traceback.print_exc(file=sys.stdout)
            print_log('initializing database')
            self.height = 0
            self.last_hash = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
            db_version = self.db_version

        # check version
        if self.db_version != db_version:
            print_log("Your database '%s' is deprecated. Please create a new database"%self.dbpath)
            self.shared.stop()
            return

        # catch_up headers
        self.init_headers(self.height)

        threading.Timer(0, lambda: self.catch_up(sync=False)).start()
        while not shared.stopped() and not self.up_to_date:
            try:
                time.sleep(1)
            except:
                print "keyboard interrupt: stopping threads"
                shared.stop()
                sys.exit(0)

        print_log("Blockchain is up to date.")
        self.memorypool_update()
        print_log("Memory pool initialized.")

        threading.Timer(10, self.main_iteration).start()
コード例 #23
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.shared = shared
        self.config = config
        self.up_to_date = False
        self.watched_addresses = []
        self.history_cache = {}
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''

        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = []
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()
        self.dbpath = config.get('leveldb', 'path')

        self.dblock = threading.Lock()
        try:
            self.db = leveldb.LevelDB(self.dbpath)
        except:
            traceback.print_exc(file=sys.stdout)
            self.shared.stop()

        self.bitcoind_url = 'http://%s:%s@%s:%s/' % (
            config.get('bitcoind', 'user'),
            config.get('bitcoind', 'password'),
            config.get('bitcoind', 'host'),
            config.get('bitcoind', 'port'))

        self.height = 0
        self.is_test = False
        self.sent_height = 0
        self.sent_header = None

        try:
            hist = self.deserialize(self.db.Get('height'))
            self.last_hash, self.height, _ = hist[0]
            print_log("hist", hist)
        except:
            #traceback.print_exc(file=sys.stdout)
            print_log('initializing database')
            self.height = 0
            self.last_hash = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'

        # catch_up headers
        self.init_headers(self.height)

        threading.Timer(0, lambda: self.catch_up(sync=False)).start()
        while not shared.stopped() and not self.up_to_date:
            try:
                time.sleep(1)
            except:
                print "keyboard interrupt: stopping threads"
                shared.stop()
                sys.exit(0)

        print_log("blockchain is up to date.")

        threading.Timer(10, self.main_iteration).start()
コード例 #24
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.shared = shared
        self.up_to_date = False
        self.watched_addresses = []
        self.history_cache = {}
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''

        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = []
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()
        self.dbpath = config.get('leveldb', 'path')

        self.dblock = threading.Lock()
        try:
            self.db = leveldb.LevelDB(self.dbpath)
        except:
            traceback.print_exc(file=sys.stdout)
            self.shared.stop()

        self.bitcoind_url = 'http://%s:%s@%s:%s/' % (
            config.get('bitcoind','user'),
            config.get('bitcoind','password'),
            config.get('bitcoind','host'),
            config.get('bitcoind','port'))

        self.height = 0
        self.sent_height = 0
        self.sent_header = None


        try:
            hist = self.deserialize(self.db.Get('0'))
            hh, self.height, _ = hist[0] 
            self.block_hashes = [hh]
            print_log( "hist", hist )
        except:
            #traceback.print_exc(file=sys.stdout)
            print_log('initializing database')
            self.height = 0
            self.block_hashes = [ '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' ]

        # catch_up headers
        self.init_headers(self.height)

        threading.Timer(0, lambda: self.catch_up(sync=False)).start()
        while not shared.stopped() and not self.up_to_date:
            try:
                time.sleep(1)
            except:
                print "keyboard interrupt: stopping threads"
                shared.stop()
                sys.exit(0)

        print "blockchain is up to date."

        threading.Timer(10, self.main_iteration).start()
コード例 #25
0
ファイル: erp.py プロジェクト: estebanhurtado/pybet
 def __init__(self, dataset, **kwargs):
     Processor.__init__(dataset)
     self.set_params(Segmentation.params, kwargs)
コード例 #26
0
ファイル: propeller_p8x32.py プロジェクト: sladeware/bbapp
 def __init__(self):
   cores = list()
   cores = [PropellerCog(self, id_=_) for _ in range(8)]
   Processor.__init__(self, 8, cores)
コード例 #27
0
 def __init__(self, _reader, _writer):
     Processor.__init__(self, _reader, _writer)
コード例 #28
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.history_cache = {}
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''

        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.use_plyvel = config.getboolean('leveldb', 'use_plyvel')
        except:
            self.use_plyvel = False
        print_log('use_plyvel:', self.use_plyvel)

        # don't use the same database for plyvel, because python-leveldb uses snappy compression
        self.dbpath = config.get('leveldb', 'path_plyvel' if self.use_plyvel else 'path')

        self.pruning_limit = config.getint('leveldb', 'pruning_limit')
        self.db_version = 1 # increase this when database needs to be updated

        self.dblock = threading.Lock()
        try:
            if self.use_plyvel:
                import plyvel
                self.db = plyvel.DB(self.dbpath, create_if_missing=True, paranoid_checks=None, compression=None)
            else:
                import leveldb
                self.db = leveldb.LevelDB(self.dbpath, paranoid_checks=False)
        except:
            traceback.print_exc(file=sys.stdout)
            self.shared.stop()

        self.bitcoind_url = 'http://%s:%s@%s:%s/' % (
            config.get('Protosharesd', 'user'),
            config.get('Protosharesd', 'password'),
            config.get('Protosharesd', 'host'),
            config.get('Protosharesd', 'port'))

        while True:
            try:
                self.bitcoind('getinfo')
                break
            except:
                print_log('cannot contact bitcoind...')
                time.sleep(5)
                continue

        self.height = 0
        self.is_test = False
        self.sent_height = 0
        self.sent_header = None

        try:
            hist = self.deserialize(self.db_get('height'))
            self.last_hash, self.height, db_version = hist[0]
            print_log("Database version", self.db_version)
            print_log("Blockchain height", self.height)
        except:
            traceback.print_exc(file=sys.stdout)
            print_log('initializing database')
            self.height = 0
            self.last_hash = '000fdcd47b7e75a46a2aded5f3335c90eb2224e01ab19ec64ffdd1b437d7b8c0'
            db_version = self.db_version

        # check version
        if self.db_version != db_version:
            print_log("Your database '%s' is deprecated. Please create a new database"%self.dbpath)
            self.shared.stop()
            return

        # catch_up headers
        self.init_headers(self.height)

        threading.Timer(0, lambda: self.catch_up(sync=False)).start()
        while not shared.stopped() and not self.up_to_date:
            try:
                time.sleep(1)
            except:
                print "keyboard interrupt: stopping threads"
                shared.stop()
                sys.exit(0)

        print_log("Blockchain is up to date.")
        self.memorypool_update()
        print_log("Memory pool initialized.")

        threading.Timer(10, self.main_iteration).start()
コード例 #29
0
    def __init__(self, config, shared):
        Processor.__init__(self)

        self.mtimes = {}  # monitoring
        self.shared = shared
        self.config = config
        self.up_to_date = False

        self.watch_lock = threading.Lock()
        self.watch_blocks = []
        self.watch_headers = []
        self.watched_addresses = {}

        self.history_cache = {}
        self.chunk_cache = {}
        self.cache_lock = threading.Lock()
        self.headers_data = ''
        self.headers_path = config.get('leveldb', 'path_fulltree')

        self.mempool_values = {}
        self.mempool_addresses = {}
        self.mempool_hist = {}
        self.mempool_hashes = set([])
        self.mempool_lock = threading.Lock()

        self.address_queue = Queue()

        try:
            self.test_reorgs = config.getboolean(
                'leveldb', 'test_reorgs')  # simulate random blockchain reorgs
        except:
            self.test_reorgs = False
        self.storage = Storage(config, shared, self.test_reorgs)

        self.dblock = threading.Lock()

        self.bitcoind_url = 'http://%s:%s@%s:%s/' % (
            config.get('bitcoind', 'user'), config.get('bitcoind', 'password'),
            config.get('bitcoind', 'host'), config.get('bitcoind', 'port'))

        while True:
            try:
                self.bitcoind('getinfo')
                break
            except:
                print_log('cannot contact bitcoind...')
                time.sleep(5)
                continue

        self.sent_height = 0
        self.sent_header = None

        # catch_up headers
        self.init_headers(self.storage.height)

        threading.Timer(0, lambda: self.catch_up(sync=False)).start()
        while not shared.stopped() and not self.up_to_date:
            try:
                time.sleep(1)
            except:
                print "keyboard interrupt: stopping threads"
                shared.stop()
                sys.exit(0)

        print_log("Blockchain is up to date.")
        self.memorypool_update()
        print_log("Memory pool initialized.")

        self.timer = threading.Timer(10, self.main_iteration)
        self.timer.start()