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

Method writeBlock

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

Source from the content-addressed store, hash-verified

154 self.outOfOrderSize = 0 # running total size for items in outOfOrderData
155
156 def writeBlock(self, inhdr, blk_hdr, rawblock):
157 blockSizeOnDisk = len(inhdr) + len(blk_hdr) + len(rawblock)
158 if not self.fileOutput and ((self.outsz + blockSizeOnDisk) > self.maxOutSz):
159 self.outF.close()
160 if self.setFileTime:
161 os.utime(self.outFname, (int(time.time()), self.highTS))
162 self.outF = None
163 self.outFname = None
164 self.outFn = self.outFn + 1
165 self.outsz = 0
166
167 (blkDate, blkTS) = get_blk_dt(blk_hdr)
168 if self.timestampSplit and (blkDate > self.lastDate):
169 print("New month " + blkDate.strftime("%Y-%m") + " @ " + self.hash_str)
170 self.lastDate = blkDate
171 if self.outF:
172 self.outF.close()
173 if self.setFileTime:
174 os.utime(self.outFname, (int(time.time()), self.highTS))
175 self.outF = None
176 self.outFname = None
177 self.outFn = self.outFn + 1
178 self.outsz = 0
179
180 if not self.outF:
181 if self.fileOutput:
182 self.outFname = self.settings['output_file']
183 else:
184 self.outFname = os.path.join(self.settings['output'], "blk%05d.dat" % self.outFn)
185 print("Output file " + self.outFname)
186 self.outF = open(self.outFname, "wb")
187
188 self.outF.write(inhdr)
189 self.outF.write(blk_hdr)
190 self.outF.write(rawblock)
191 self.outsz = self.outsz + len(inhdr) + len(blk_hdr) + len(rawblock)
192
193 self.blkCountOut = self.blkCountOut + 1
194 if blkTS > self.highTS:
195 self.highTS = blkTS
196
197 if (self.blkCountOut % 1000) == 0:
198 print('%i blocks scanned, %i blocks written (of %i, %.1f%% complete)' %
199 (self.blkCountIn, self.blkCountOut, len(self.blkindex), 100.0 * self.blkCountOut / len(self.blkindex)))
200
201 def inFileName(self, fn):
202 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
closeMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected