MCPcopy Create free account
hub / github.com/ElementsProject/elements / run

Method run

contrib/linearize/linearize-data.py:222–285  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

220 self.writeBlock(extent.inhdr, extent.blkhdr, rawblock)
221
222 def run(self):
223 while self.blkCountOut < len(self.blkindex):
224 if not self.inF:
225 fname = self.inFileName(self.inFn)
226 print("Input file " + fname)
227 try:
228 self.inF = open(fname, "rb")
229 except IOError:
230 print("Premature end of block data")
231 return
232
233 inhdr = self.inF.read(8)
234 if (not inhdr or (inhdr[0] == "\0")):
235 self.inF.close()
236 self.inF = None
237 self.inFn = self.inFn + 1
238 continue
239
240 inMagic = inhdr[:4]
241 if (inMagic != self.settings['netmagic']):
242 # Seek backwards 7 bytes (skipping the first byte in the previous search)
243 # and continue searching from the new position if the magic bytes are not
244 # found.
245 self.inF.seek(-7, os.SEEK_CUR)
246 continue
247 inLenLE = inhdr[4:]
248 su = struct.unpack("<I", inLenLE)
249 inLen = su[0] - 80 # length without header
250 blk_hdr = self.inF.read(80)
251 inExtent = BlockExtent(self.inFn, self.inF.tell(), inhdr, blk_hdr, inLen)
252
253 self.hash_str = calc_hash_str(blk_hdr)
254 if not self.hash_str in blkmap:
255 # Because blocks can be written to files out-of-order as of 0.10, the script
256 # may encounter blocks it doesn't know about. Treat as debug output.
257 if settings['debug_output'] == 'true':
258 print("Skipping unknown block " + self.hash_str)
259 self.inF.seek(inLen, os.SEEK_CUR)
260 continue
261
262 blkHeight = self.blkmap[self.hash_str]
263 self.blkCountIn += 1
264
265 if self.blkCountOut == blkHeight:
266 # If in-order block, just copy
267 rawblock = self.inF.read(inLen)
268 self.writeBlock(inhdr, blk_hdr, rawblock)
269
270 # See if we can catch up to prior out-of-order blocks
271 while self.blkCountOut in self.blockExtents:
272 self.copyOneBlock()
273
274 else: # If out-of-order, skip over block data for now
275 self.blockExtents[blkHeight] = inExtent
276 if self.outOfOrderSize < self.settings['out_of_order_cache_sz']:
277 # If there is space in the cache, read the data
278 # Reading the data in file sequence instead of seeking and fetching it later is preferred,
279 # but we don't want to fill up memory

Callers 15

shellFunction · 0.45
linearize-data.pyFile · 0.45
call_symbol_checkFunction · 0.45
get_machineFunction · 0.45
gen-manpages.pyFile · 0.45
call_security_checkFunction · 0.45
get_archFunction · 0.45
getcoins.pyFile · 0.45
download_with_wgetFunction · 0.45
verify_with_gpgFunction · 0.45
ComplexMemPoolFunction · 0.45
MempoolCheckFunction · 0.45

Calls 7

inFileNameMethod · 0.95
writeBlockMethod · 0.95
copyOneBlockMethod · 0.95
calc_hash_strFunction · 0.85
readMethod · 0.45
closeMethod · 0.45
seekMethod · 0.45

Tested by 4

call_symbol_checkFunction · 0.36
get_machineFunction · 0.36
call_security_checkFunction · 0.36
get_archFunction · 0.36