MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / writeBlock

Method writeBlock

contrib/linearize/linearize-data.py:168–211  ·  view source on GitHub ↗
(self, inhdr, blk_hdr, rawblock)

Source from the content-addressed store, hash-verified

166 self.outOfOrderSize = 0 # running total size for items in outOfOrderData
167
168 def writeBlock(self, inhdr, blk_hdr, rawblock):
169 blockSizeOnDisk = len(inhdr) + len(blk_hdr) + len(rawblock)
170 if not self.fileOutput and ((self.outsz + blockSizeOnDisk) > self.maxOutSz):
171 self.outF.close()
172 if self.setFileTime:
173 os.utime(self.outFname, (int(time.time()), self.highTS))
174 self.outF = None
175 self.outFname = None
176 self.outFn = self.outFn + 1
177 self.outsz = 0
178
179 (blkDate, blkTS) = get_blk_dt(blk_hdr)
180 if self.timestampSplit and (blkDate > self.lastDate):
181 print("New month " + blkDate.strftime("%Y-%m") + " @ " + self.hash_str)
182 self.lastDate = blkDate
183 if self.outF:
184 self.outF.close()
185 if self.setFileTime:
186 os.utime(self.outFname, (int(time.time()), self.highTS))
187 self.outF = None
188 self.outFname = None
189 self.outFn = self.outFn + 1
190 self.outsz = 0
191
192 if not self.outF:
193 if self.fileOutput:
194 self.outFname = self.settings['output_file']
195 else:
196 self.outFname = os.path.join(self.settings['output'], "blk%05d.dat" % self.outFn)
197 print("Output file " + self.outFname)
198 self.outF = open(self.outFname, "wb")
199
200 self.outF.write(inhdr)
201 self.outF.write(blk_hdr)
202 self.outF.write(rawblock)
203 self.outsz = self.outsz + len(inhdr) + len(blk_hdr) + len(rawblock)
204
205 self.blkCountOut = self.blkCountOut + 1
206 if blkTS > self.highTS:
207 self.highTS = blkTS
208
209 if (self.blkCountOut % 1000) == 0:
210 print('%i blocks scanned, %i blocks written (of %i, %.1f%% complete)' %
211 (self.blkCountIn, self.blkCountOut, len(self.blkindex), 100.0 * self.blkCountOut / len(self.blkindex)))
212
213 def inFileName(self, fn):
214 return os.path.join(self.settings['input'], "blk%05d.dat" % fn)

Callers 2

copyOneBlockMethod · 0.95
runMethod · 0.95

Calls 4

get_blk_dtFunction · 0.85
joinMethod · 0.80
closeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected