Ejemplo n.º 1
0
 def fork(self, height):
     import shutil
     filename = "blockchain_fork_%d"%height
     new_path = os.path.join(util.get_headers_dir(self.config), filename)
     shutil.copy(self.path(), new_path)
     with open(new_path, 'rb+') as f:
         f.seek((height) * 80)
         f.truncate()
         f.close()
     return filename
Ejemplo n.º 2
0
def read_blockchains(config):
    blockchains[0] = Blockchain(config, 0, None)
    fdir = os.path.join(util.get_headers_dir(config), 'forks')
    if not os.path.exists(fdir):
        os.mkdir(fdir)
    l = filter(lambda x: x.startswith('fork_'), os.listdir(fdir))
    l = sorted(l, key=lambda x: int(x.split('_')[1]))
    for filename in l:
        checkpoint = int(filename.split('_')[2])
        parent_id = int(filename.split('_')[1])
        b = Blockchain(config, checkpoint, parent_id)
        blockchains[b.checkpoint] = b
    return blockchains
Ejemplo n.º 3
0
def read_blockchains(config):
    blockchains[0] = Blockchain(config, 0, None)
    fdir = os.path.join(util.get_headers_dir(config), 'forks')
    if not os.path.exists(fdir):
        os.mkdir(fdir)
    l = filter(lambda x: x.startswith('fork_'), os.listdir(fdir))
    l = sorted(l, key = lambda x: int(x.split('_')[1]))
    for filename in l:
        checkpoint = int(filename.split('_')[2])
        parent_id = int(filename.split('_')[1])
        b = Blockchain(config, checkpoint, parent_id)
        blockchains[b.checkpoint] = b
    return blockchains
Ejemplo n.º 4
0
 def fork_and_save(self):
     import shutil
     self.print_error("save fork")
     height = self.checkpoint
     filename = "blockchain_fork_%d" % height
     new_path = os.path.join(util.get_headers_dir(self.config), filename)
     shutil.copy(self.path(), new_path)
     with open(new_path, 'rb+') as f:
         f.seek((height) * 80)
         f.truncate()
     self.filename = filename
     self.is_saved = True
     for h in self.headers:
         self.write_header(h)
     self.headers = []
Ejemplo n.º 5
0
 def path(self):
     d = util.get_headers_dir(self.config)
     filename = 'blockchain_headers' if self.parent_id is None else os.path.join(
         'forks', 'fork_%d_%d' % (self.parent_id, self.checkpoint))
     return os.path.join(d, filename)
Ejemplo n.º 6
0
 def path(self):
     d = util.get_headers_dir(self.config)
     return os.path.join(d, self.filename)
Ejemplo n.º 7
0
 def path(self):
     d = util.get_headers_dir(self.config)
     filename = 'blockchain_headers' if self.parent_id is None else os.path.join('forks', 'fork_%d_%d'%(self.parent_id, self.checkpoint))
     return os.path.join(d, filename)