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

Function getFirstBlockFileId

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

Source from the content-addressed store, hash-verified

55# This gets the first block file ID that exists from the input block
56# file directory.
57def getFirstBlockFileId(block_dir_path):
58 # First, this sets up a pattern to search for block files, for
59 # example 'blkNNNNN.dat'.
60 blkFilePattern = os.path.join(block_dir_path, "blk[0-9][0-9][0-9][0-9][0-9].dat")
61
62 # This search is done with glob
63 blkFnList = glob.glob(blkFilePattern)
64
65 if len(blkFnList) == 0:
66 print("blocks not pruned - starting at 0")
67 return 0
68 # We then get the lexicographic minimum, which should be the first
69 # block file name.
70 firstBlkFilePath = min(blkFnList)
71 firstBlkFn = os.path.basename(firstBlkFilePath)
72
73 # now, the string should be ['b','l','k','N','N','N','N','N','.','d','a','t']
74 # So get the ID by choosing: 3 4 5 6 7
75 # The ID is not necessarily 0 if this is a pruned node.
76 blkId = int(firstBlkFn[3:8])
77 return blkId
78
79def read_xor_key(blocks_path):
80 NUM_XOR_BYTES = 8 # From InitBlocksdirXorKey::xor_key.size()

Callers 1

__init__Method · 0.85

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected