def getblock(self, blkhash): block = self.blk_cache.get(blkhash) if block is not None: return block ser_hash = ser_uint256(blkhash) try: # Lookup the block index, seek in the file fpos = long(self.db.Get('blocks:' + ser_hash)) self.blk_read.seek(fpos) # read and decode "block" msg recvbuf = self.blk_read.read(4 + 4) if recvbuf[:4] == 'ZLIB': msg_len = int(recvbuf[4:8].encode('hex'), 16) recvbuf = self.blk_read.read(msg_len) f = cStringIO.StringIO(zlib.decompress(recvbuf)) msg = message_read(self.netmagic, f) else: self.blk_read.seek(fpos) msg = message_read(self.netmagic, self.blk_read) if msg is None: return None block = msg.block except KeyError: return None self.blk_cache.put(blkhash, block) return block
def getblock(self, blkhash): block = self.blk_cache.get(blkhash) if block is not None: return block ser_hash = ser_uint256(blkhash) try: # Lookup the block index, seek in the file fpos = long(self.db.Get('blocks:'+ser_hash)) self.blk_read.seek(fpos) # read and decode "block" msg recvbuf = self.blk_read.read(4+4) if recvbuf[:4] == 'ZLIB': msg_len = int(recvbuf[4:8].encode('hex'),16) recvbuf = self.blk_read.read(msg_len) f = cStringIO.StringIO(zlib.decompress(recvbuf)) msg = message_read(self.netmagic, f) else: self.blk_read.seek(fpos) msg = message_read(self.netmagic, self.blk_read) if msg is None: return None block = msg.block except KeyError: return None self.blk_cache.put(blkhash, block) return block
def getblock(self, blkhash): block = self.blk_cache.get(blkhash) if block is not None: return block ser_hash = ser_uint256(blkhash) try: # Lookup the block index, seek in the file fpos = long(self.db.Get('blocks:' + ser_hash)) self.blk_read.seek(fpos) # read and decode "block" msg if self.compression: msg = message_read(self.netmagic, self.block_decompress(self.blk_read)) else: msg = message_read(self.netmagic, self.blk_read) if msg is None: return None block = msg.block except KeyError: return None self.blk_cache.put(blkhash, block) return block
def getblock(self, blkhash): block = self.blk_cache.get(blkhash) if block is not None: return block ser_hash = ser_uint256(blkhash) try: # Lookup the block index, seek in the file fpos = long(self.db.Get('blocks:'+ser_hash)) self.blk_read.seek(fpos) # read and decode "block" msg if self.compression: msg = message_read(self.netmagic, self.block_decompress(self.blk_read)) else: msg = message_read(self.netmagic, self.blk_read) if msg is None: return None block = msg.block except KeyError: return None self.blk_cache.put(blkhash, block) return block