| 95 | # This gets the first block file ID that exists from the input block |
| 96 | # file directory. |
| 97 | def getFirstBlockFileId(block_dir_path): |
| 98 | # First, this sets up a pattern to search for block files, for |
| 99 | # example 'blkNNNNN.dat'. |
| 100 | blkFilePattern = os.path.join(block_dir_path, "blk[0-9][0-9][0-9][0-9][0-9].dat") |
| 101 | |
| 102 | # This search is done with glob |
| 103 | blkFnList = glob.glob(blkFilePattern) |
| 104 | |
| 105 | if len(blkFnList) == 0: |
| 106 | print("blocks not pruned - starting at 0") |
| 107 | return 0 |
| 108 | # We then get the lexicographic minimum, which should be the first |
| 109 | # block file name. |
| 110 | firstBlkFilePath = min(blkFnList) |
| 111 | firstBlkFn = os.path.basename(firstBlkFilePath) |
| 112 | |
| 113 | # now, the string should be ['b','l','k','N','N','N','N','N','.','d','a','t'] |
| 114 | # So get the ID by choosing: 3 4 5 6 7 |
| 115 | # The ID is not necessarily 0 if this is a pruned node. |
| 116 | blkId = int(firstBlkFn[3:8]) |
| 117 | return blkId |
| 118 | |
| 119 | # Block header and extent on disk |
| 120 | BlockExtent = namedtuple('BlockExtent', ['fn', 'offset', 'inhdr', 'blkhdr', 'size']) |