/
chain_map.py
49 lines (34 loc) · 1014 Bytes
/
chain_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
# %% Imports
from pybit.py2.chain import Chain, Dat
# %% Higher level classes
class ChainMap(Chain):
def readDat(self, datn):
f = "{0}blk{1:05d}.dat".format(self.datPath, datn)
if self.verb >= 1:
print f
dat = DatMap(f,
verb=self.verb)
self.datni += 1
return dat
class DatMap(Dat):
def read_next_block(self):
"""
Read and return the next block
Track cursor position
"""
b = BlockMap(self.mmap, self.cursor,
verb=self.verb,
f=self.f)
self.cursor = b.end
self.nBlock += 1
# Save block dat object - unordered at this point
self.blocks[self.nBlock] = b
if self.verb == 2:
print "{0}Read block {1}".format(self.verb*" "*2, self.nBlock)
if __name__ == "__main__":
""
# %% Read chain - 1 step
c = Chain(verb=2,
datStart=2)
c.read_next_Dat()