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

Method writeBlock

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

Source from the content-addressed store, hash-verified

132 return bytes(data)
133
134 def writeBlock(self, inhdr, blk_hdr, rawblock):
135 blockSizeOnDisk = len(inhdr) + len(blk_hdr) + len(rawblock)
136 if not self.fileOutput and ((self.outsz + blockSizeOnDisk) > self.maxOutSz):
137 self.outF.close()
138 if self.setFileTime:
139 os.utime(self.outFname, (int(time.time()), self.highTS))
140 self.outF = None
141 self.outFname = None
142 self.outFn = self.outFn + 1
143 self.outsz = 0
144
145 (blkDate, blkTS) = get_blk_dt(blk_hdr)
146 if self.timestampSplit and (blkDate > self.lastDate):
147 print("New month " + blkDate.strftime("%Y-%m") + " @ " + self.hash_str)
148 self.lastDate = blkDate
149 if self.outF:
150 self.outF.close()
151 if self.setFileTime:
152 os.utime(self.outFname, (int(time.time()), self.highTS))
153 self.outF = None
154 self.outFname = None
155 self.outFn = self.outFn + 1
156 self.outsz = 0
157
158 if not self.outF:
159 if self.fileOutput:
160 self.outFname = self.settings['output_file']
161 else:
162 self.outFname = os.path.join(self.settings['output'], "blk%05d.dat" % self.outFn)
163 print("Output file " + self.outFname)
164 self.outF = open(self.outFname, "wb")
165
166 self.outF.write(inhdr)
167 self.outF.write(blk_hdr)
168 self.outF.write(rawblock)
169 self.outsz = self.outsz + len(inhdr) + len(blk_hdr) + len(rawblock)
170
171 self.blkCountOut = self.blkCountOut + 1
172 if blkTS > self.highTS:
173 self.highTS = blkTS
174
175 if (self.blkCountOut % 1000) == 0:
176 print('%i blocks scanned, %i blocks written (of %i, %.1f%% complete)' %
177 (self.blkCountIn, self.blkCountOut, len(self.blkindex), 100.0 * self.blkCountOut / len(self.blkindex)))
178
179 def inFileName(self, fn):
180 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