Include block header in make squeak method (#1900)

* Update make squeak method to include block header in return value

* Remove type hint from make squeak in twitter forwarder
This commit is contained in:
Jonathan Zernik 2021-12-27 14:17:12 -08:00 committed by GitHub
parent cf64664a44
commit e6e59bb3fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 16 deletions

View file

@ -62,7 +62,12 @@ class SqueakCore:
self.bitcoin_client = bitcoin_client
self.lightning_client = lightning_client
def make_squeak(self, signing_profile: SqueakProfile, content_str: str, replyto_hash: Optional[bytes] = None) -> Tuple[CSqueak, bytes]:
def make_squeak(
self,
signing_profile: SqueakProfile,
content_str: str,
replyto_hash: Optional[bytes] = None,
) -> Tuple[CSqueak, bytes, CBlockHeader]:
"""Create a new squeak.
TODO: Include the block header in the result tuple.
@ -73,8 +78,8 @@ class SqueakCore:
replyto_hash: The hash of the squeak to which this one is replying.
Returns:
Tuple[CSqueak, bytes]: the squeak that was created together
with its decryption key.
Tuple[CSqueak, bytes, CBlockheader]: the squeak that was created together
with its decryption key and block header.
Raises:
Exception: If the profile does not have a signing key.
@ -84,13 +89,14 @@ class SqueakCore:
block_info = self.bitcoin_client.get_best_block_info()
block_height = block_info.block_height
block_hash = block_info.block_hash
return make_squeak_with_block(
squeak, secret_key = make_squeak_with_block(
signing_profile.private_key,
content_str,
block_height,
block_hash,
replyto_hash,
)
return squeak, secret_key, block_info.block_header
def check_squeak(self, squeak: CSqueak) -> None:
"""Checks if the squeak is valid and has a valid signature.

View file

@ -84,12 +84,11 @@ class SqueakController:
raise Exception("Profile with id {} not found.".format(
profile_id,
))
squeak, secret_key = self.squeak_core.make_squeak(
squeak, secret_key, block_header = self.squeak_core.make_squeak(
squeak_profile,
content_str,
replyto_hash,
)
block_header = self.squeak_core.get_block_header(squeak)
inserted_squeak_hash = self.squeak_store.save_squeak(
squeak,
block_header,

View file

@ -22,7 +22,6 @@
import logging
import threading
from typing import Dict
from typing import Optional
from squeaknode.core.squeak_core import SqueakCore
from squeaknode.core.twitter_account_entry import TwitterAccountEntry
@ -166,21 +165,16 @@ class TwitterForwarderTask:
if self.is_tweet_a_match(tweet):
self.forward_tweet(tweet)
def make_squeak(
self,
profile_id: int,
content_str: str,
) -> Optional[bytes]:
def make_squeak(self, profile_id: int, content_str: str):
squeak_profile = self.squeak_store.get_squeak_profile(profile_id)
if squeak_profile is None:
raise Exception("Profile with id {} not found.".format(
profile_id,
))
squeak, secret_key = self.squeak_core.make_squeak(
squeak, secret_key, block_header = self.squeak_core.make_squeak(
squeak_profile,
content_str,
)
block_header = self.squeak_core.get_block_header(squeak)
inserted_squeak_hash = self.squeak_store.save_squeak(
squeak,
block_header,
@ -192,4 +186,3 @@ class TwitterForwarderTask:
secret_key,
content_str,
)
return inserted_squeak_hash

View file

@ -289,8 +289,9 @@ def test_make_squeak(
squeak_core,
signing_profile,
squeak_content,
block_header
):
created_squeak, created_secret_key = squeak_core.make_squeak(
created_squeak, created_secret_key, attached_block_header = squeak_core.make_squeak(
signing_profile,
squeak_content,
)
@ -300,6 +301,7 @@ def test_make_squeak(
)
assert decrypted_created_content == squeak_content
assert attached_block_header == block_header
def test_make_squeak_with_contact_profile(