Started implementing logic to push changes to the tangle
This commit is contained in:
parent
9f18e4a774
commit
c1a2d279ff
41
next.py
41
next.py
@ -5,7 +5,9 @@
|
||||
# TODO: ? Stop using tokens for files, use hashed name + short ?version-number + parent token instead
|
||||
# TODO: Store version-numbers for files in parent-dir
|
||||
# TODO: Chane Milestone-Format from [stone,stone,...] to [[dirStne,dirStone,...],[fileStone,,...]] and dont save type for the stones
|
||||
# TODO: Move iota-push-code from TangleBlob to chunk? and perform when sealing?
|
||||
# TODO: Decide how / when / from which class to push new blocks
|
||||
# TODO: Unload 'overwritten' blobs
|
||||
# TODO: Close blobs when they become unknown to the kernel or when we unmount (genesis only on unmount)
|
||||
# TODO: When unmounting walk throught tree and seal all blobs
|
||||
|
||||
from iota import Iota, ProposedTransaction, Address, TryteString, Tag
|
||||
@ -31,9 +33,20 @@ import gzip
|
||||
import secrets
|
||||
|
||||
CHUNKSIZE = 2187
|
||||
SYNCWRITES = True
|
||||
|
||||
def log(txt):
|
||||
print("[-] "+str(txt))
|
||||
|
||||
def sendEmOff(bundles, api):
|
||||
print("SENDING (")
|
||||
pprint(bundles)
|
||||
print(")")
|
||||
return
|
||||
api.send_trytes(
|
||||
trytes=bundles
|
||||
)
|
||||
|
||||
class Atom():
|
||||
def __init__(self, milestone: bool, cont, name: str = None) -> None:
|
||||
self.milestone = milestone
|
||||
@ -118,6 +131,21 @@ class TangleBlob():
|
||||
addr = self.adressGen.get_addresses(start=chunkNum + self.preChunks, count=1)[0]
|
||||
return self._genBundle(ct_bytes, addr)
|
||||
|
||||
def dumpAllSealed(self):
|
||||
bundles = []
|
||||
for i in range(len(self.chunks)-self.pushedNum):
|
||||
c = i + self.pushedNum
|
||||
chunk = self.chunks[c]
|
||||
if chunk.isSealed():
|
||||
bundles.append(self._dumpChunk(c))
|
||||
self.pushedNum+=1
|
||||
return bundles
|
||||
|
||||
def sealAndDump(self):
|
||||
# When unmounting / closing / ...
|
||||
self.chunks[-1].seal()
|
||||
return self.dumpAllSealed()
|
||||
|
||||
def append(self, data: bytes, newBlock: bool = False) -> None:
|
||||
self._requireFetched()
|
||||
if newBlock:
|
||||
@ -132,6 +160,10 @@ class TangleBlob():
|
||||
chunk = data[:CHUNKSIZE]
|
||||
self.chunks.append(BlobChunk(chunk))
|
||||
data = data[CHUNKSIZE:]
|
||||
if SYNCWRITES:
|
||||
bundles = self.dumpAllSealed()
|
||||
if bundles:
|
||||
sendEmOff(bundles, self.iotaApi)
|
||||
|
||||
def getChunkLen(self) -> int:
|
||||
return self.preChunks + len(self.chunks)
|
||||
@ -204,6 +236,11 @@ class TangleBlob():
|
||||
lines[-1]+=" {+}"
|
||||
return "\n".join(lines)
|
||||
|
||||
def close(self):
|
||||
bundles = self.sealAndDump()
|
||||
if bundles:
|
||||
sendEmOff(bundles, self.iotaApi)
|
||||
|
||||
class TangleFileTreeElement(TangleBlob):
|
||||
def __init__(self, name: str, lastMilestoneIndex: int, parent, iotaApi: Iota) -> None:
|
||||
if isinstance(parent, bytes):
|
||||
@ -350,7 +387,7 @@ class TangleFileTreeElement(TangleBlob):
|
||||
def _updateChildMilestone(self, name: str, milestoneIndex: int):
|
||||
if isinstance(self.parent, bytes):
|
||||
# We are the genesis-block
|
||||
self.append(milestoneIndex, True)
|
||||
self.append(milestoneIndex)
|
||||
else:
|
||||
atom = self.inodes[name].change(milestoneIndex = milestoneIndex)
|
||||
self._newAtom(atom)
|
||||
|
Loading…
Reference in New Issue
Block a user