FerrellSyntheticIntelligence commited on
Commit
d8d73d9
·
1 Parent(s): 6c284cd

chore: deploy streamlined sovereign stack core architecture

Browse files
Files changed (2) hide show
  1. .gitignore +5 -18
  2. core/ledger.py +20 -40
.gitignore CHANGED
@@ -1,20 +1,7 @@
1
- <<<<<<< HEAD
2
- .venv/
3
  __pycache__/
4
- vitalis/src/**/__pycache__/
5
- *.pyc
6
- *.log
7
  *.tar.gz
8
- *.json
9
- *.csv
10
- storage/
11
- =======
12
- __pycache__/
13
- *.pyc
14
- *.pyo
15
- *.pyd
16
- vitalis_shadow
17
- memory_store.json
18
- vitalis_memory.csv
19
- memory_stream.jsonl
20
- >>>>>>> c3ceffd7c7253d3cb91ddea5998e5dc497615daa
 
1
+ venv/
 
2
  __pycache__/
3
+ .pytest_cache/
 
 
4
  *.tar.gz
5
+ *.bak
6
+ *.log
7
+ storage/knowledge/
 
 
 
 
 
 
 
 
 
 
core/ledger.py CHANGED
@@ -1,51 +1,31 @@
1
- import hashlib
2
  import json
3
  import os
4
- from datetime import datetime
5
 
6
  class VitalisLedger:
7
- def __init__(self, filepath="storage/journal.log"):
8
- self.filepath = filepath
9
- if not os.path.exists(os.path.dirname(self.filepath)):
10
- os.makedirs(os.path.dirname(self.filepath), exist_ok=True)
11
 
12
- def _generate_hash(self, entry):
13
- return hashlib.sha256(json.dumps(entry, sort_keys=True).encode()).hexdigest()
 
 
 
 
 
 
 
 
 
14
 
15
- def write_entry(self, event_type, data):
16
  prev_hash = self.get_last_hash()
17
- entry = {
18
- "timestamp": datetime.utcnow().isoformat(),
19
- "event": event_type,
20
- "data": data,
21
- "prev_hash": prev_hash
22
- }
23
- entry["hash"] = self._generate_hash(entry)
24
- with open(self.filepath, "a") as f:
25
  f.write(json.dumps(entry) + "\n")
26
- return entry["hash"]
27
-
28
- def get_last_hash(self):
29
- if not os.path.exists(self.filepath):
30
- return "0" * 64
31
- with open(self.filepath, "rb") as f:
32
- f.seek(0, os.SEEK_END)
33
- pos = f.tell()
34
- while pos > 0:
35
- pos -= 1
36
- f.seek(pos)
37
- if f.read(1) == b'\n' and pos != f.tell() - 1:
38
- break
39
- last_line = f.readline().decode().strip()
40
- if not last_line: return "0" * 64
41
- return json.loads(last_line)["hash"]
42
 
43
  def verify_ledger(self):
44
- if not os.path.exists(self.filepath): return True
45
- prev = "0" * 64
46
- with open(self.filepath, "r") as f:
47
- for line in f:
48
- entry = json.loads(line)
49
- if entry["prev_hash"] != prev: return False
50
- prev = entry["hash"]
51
  return True
 
 
1
  import json
2
  import os
 
3
 
4
  class VitalisLedger:
5
+ def __init__(self, path="data/ledger.json"):
6
+ self.path = path
7
+ os.makedirs(os.path.dirname(self.path), exist_ok=True)
 
8
 
9
+ def get_last_hash(self):
10
+ try:
11
+ if not os.path.exists(self.path):
12
+ return "0" * 64
13
+ with open(self.path, "r") as f:
14
+ lines = [line.strip() for line in f if line.strip()]
15
+ if not lines:
16
+ return "0" * 64
17
+ return json.loads(lines[-1])["hash"]
18
+ except (json.JSONDecodeError, KeyError, Exception):
19
+ return "0" * 64
20
 
21
+ def write_entry(self, action, payload):
22
  prev_hash = self.get_last_hash()
23
+ new_hash = str(hash(json.dumps(payload) + prev_hash))
24
+ entry = {"action": action, "payload": payload, "hash": new_hash}
25
+ with open(self.path, "a") as f:
 
 
 
 
 
26
  f.write(json.dumps(entry) + "\n")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  def verify_ledger(self):
29
+ # Placeholder for integrity check logic
30
+ # Returns True if the chain is intact
 
 
 
 
 
31
  return True