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

Function getFirstBlockFileId

contrib/linearize/linearize-data.py:97–117  ·  view source on GitHub ↗
(block_dir_path)

Source from the content-addressed store, hash-verified

95# This gets the first block file ID that exists from the input block
96# file directory.
97def 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
120BlockExtent = namedtuple('BlockExtent', ['fn', 'offset', 'inhdr', 'blkhdr', 'size'])

Callers 1

__init__Method · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected