diff --git a/schema/comments_ddl.sql b/schema/comments_ddl.sql index 5960824..af06eb8 100644 --- a/schema/comments_ddl.sql +++ b/schema/comments_ddl.sql @@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS COMMENT ( ParentId TEXT DEFAULT NULL, Signature TEXT DEFAULT NULL, Timestamp INTEGER NOT NULL, + SigningTs TEXT DEFAULT NULL, CONSTRAINT COMMENT_PRIMARY_KEY PRIMARY KEY (CommentId) ON CONFLICT IGNORE, CONSTRAINT COMMENT_SIGNATURE_SK UNIQUE (Signature) ON CONFLICT ABORT, CONSTRAINT COMMENT_CHANNEL_FK FOREIGN KEY (ChannelId) REFERENCES CHANNEL(ClaimId) @@ -22,7 +23,7 @@ CREATE TABLE IF NOT EXISTS COMMENT ( ON UPDATE CASCADE ON DELETE NO ACTION -- setting null implies comment is top level ); -ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL; +-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL; -- DROP TABLE IF EXISTS CHANNEL; CREATE TABLE IF NOT EXISTS CHANNEL( diff --git a/src/database.py b/src/database.py index 5ee10d9..c71bdff 100644 --- a/src/database.py +++ b/src/database.py @@ -94,9 +94,8 @@ def insert_comment(conn: sqlite3.Connection, claim_id: str = None, comment: str channel_id: str = None, signature: str = None, signing_ts: str = None, parent_id: str = None) -> str: timestamp = int(time.time()) - prehash = ':'.join((claim_id, comment, str(timestamp),)) - prehash = bytes(prehash.encode('utf-8')) - comment_id = nacl.hash.sha256(prehash).decode('utf-8') + prehash = b':'.join((claim_id.encode(), comment.encode(), str(timestamp).encode(),)) + comment_id = nacl.hash.sha256(prehash).decode() with conn: conn.execute( """ diff --git a/src/writes.py b/src/writes.py index 981ad1d..8030cca 100644 --- a/src/writes.py +++ b/src/writes.py @@ -2,8 +2,10 @@ import logging import sqlite3 from src.database import get_comment_or_none -from src.database import insert_comment, insert_channel -from src.misc import validate_channel, validate_signature +from src.database import insert_comment +from src.database import insert_channel +from src.misc import validate_channel +from src.misc import validate_signature logger = logging.getLogger(__name__) @@ -16,7 +18,7 @@ def create_comment(conn: sqlite3.Connection, comment: str, claim_id: str, channe try: comment_id = insert_comment( conn=conn, comment=comment, claim_id=claim_id, channel_id=channel_id, - signature=signature, parent_id=parent_id + signature=signature, parent_id=parent_id, signing_ts=signing_ts ) return get_comment_or_none(conn, comment_id) except sqlite3.IntegrityError as ie: diff --git a/tests/database_test.py b/tests/database_test.py index 39371e6..427b6a5 100644 --- a/tests/database_test.py +++ b/tests/database_test.py @@ -75,6 +75,7 @@ class TestCommentCreation(DatabaseTestCase): signing_ts='asdasd' ) self.assertIsNotNone(comment) + self.assertIn('signing_ts', comment) previous_id = comment['comment_id'] reply = create_comment( conn=self.conn, @@ -88,6 +89,7 @@ class TestCommentCreation(DatabaseTestCase): ) self.assertIsNotNone(reply) self.assertEqual(reply['parent_id'], comment['comment_id']) + self.assertIn('signing_ts', reply) def test04UsernameVariations(self): self.assertRaises(