Rename postgres_db to squeak_db variables everywhere (#437)

This commit is contained in:
Jonathan Zernik 2020-11-10 18:35:11 -05:00 committed by GitHub
parent 45dcfb1eb0
commit a536d18573
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 77 deletions

View file

@ -204,7 +204,7 @@ def run_server(config):
network = load_network(config)
SelectParams(network)
# load postgres db
# load the db
squeak_db = load_db(config, network)
squeak_db.init()

View file

@ -20,11 +20,11 @@ class NetworkSync:
def __init__(
self,
squeak_store,
postgres_db,
squeak_db,
lightning_client,
):
self.squeak_store = squeak_store
self.postgres_db = postgres_db
self.squeak_db = squeak_db
self.lightning_client = lightning_client
def sync_timeline(self, peer, block_height):
@ -34,7 +34,7 @@ class NetworkSync:
peer_sync_task = PeerSyncTask(
peer_connection,
self.squeak_store,
self.postgres_db,
self.squeak_db,
self.lightning_client,
)
if peer.uploading:
@ -49,7 +49,7 @@ class NetworkSync:
peer_sync_task = PeerSyncTask(
peer_connection,
self.squeak_store,
self.postgres_db,
self.squeak_db,
self.lightning_client,
)
if peer.uploading:

View file

@ -19,12 +19,12 @@ class PeerSyncTask:
self,
peer_connection,
squeak_store,
postgres_db,
squeak_db,
lightning_client,
):
self.peer_connection = peer_connection
self.squeak_store = squeak_store
self.postgres_db = postgres_db
self.squeak_db = squeak_db
self.lightning_client = lightning_client
@property
@ -210,7 +210,7 @@ class PeerSyncTask:
def _get_saved_offer(self, squeak_hash):
logger.info("Getting saved offer for hash: {}".format(squeak_hash))
offers = self.postgres_db.get_offers_with_peer(squeak_hash)
offers = self.squeak_db.get_offers_with_peer(squeak_hash)
for offer_with_peer in offers:
if offer_with_peer.offer.peer_id == self.peer.peer_id:
return offer_with_peer
@ -221,7 +221,7 @@ class PeerSyncTask:
self._save_squeak(squeak)
def _get_followed_addresses(self):
followed_profiles = self.postgres_db.get_following_profiles()
followed_profiles = self.squeak_db.get_following_profiles()
return [profile.address for profile in followed_profiles]
def _download_offer(self, squeak_hash):
@ -243,7 +243,7 @@ class PeerSyncTask:
self.peer_client.post_squeak(squeak)
def _get_sharing_addresses(self):
sharing_profiles = self.postgres_db.get_sharing_profiles()
sharing_profiles = self.squeak_db.get_sharing_profiles()
return [profile.address for profile in sharing_profiles]
def _generate_challenge_proof(self):
@ -262,7 +262,7 @@ class PeerSyncTask:
def _save_offer(self, offer):
logger.info("Saving offer: {}".format(offer))
self.postgres_db.insert_offer(offer)
self.squeak_db.insert_offer(offer)
def _offer_from_msg(self, offer_msg):
if not offer_msg:

View file

@ -5,8 +5,8 @@ logger = logging.getLogger(__name__)
class SqueakBlockVerifier:
def __init__(self, postgres_db, blockchain_client):
self.postgres_db = postgres_db
def __init__(self, squeak_db, blockchain_client):
self.squeak_db = squeak_db
self.blockchain_client = blockchain_client
self.unverified_queue = queue.Queue()
@ -31,7 +31,7 @@ class SqueakBlockVerifier:
def verify_all_unverified_squeaks(self):
logger.debug("Verifying all unverified squeaks.")
squeaks_to_verify = self.postgres_db.get_unverified_block_squeaks()
squeaks_to_verify = self.squeak_db.get_unverified_block_squeaks()
for squeak_hash in squeaks_to_verify:
self.verify_squeak_block(squeak_hash)
@ -47,15 +47,15 @@ class SqueakBlockVerifier:
logger.error("something bad happened", exc_info=True)
def _get_squeak(self, squeak_hash):
squeak_entry = self.postgres_db.get_squeak_entry(squeak_hash)
squeak_entry = self.squeak_db.get_squeak_entry(squeak_hash)
return squeak_entry.squeak
def _mark_squeak_verified(self, squeak_hash, block_info):
block_header_bytes = bytes.fromhex(block_info.block_header)
self.postgres_db.mark_squeak_block_valid(squeak_hash, block_header_bytes)
self.squeak_db.mark_squeak_block_valid(squeak_hash, block_header_bytes)
def _delete_squeak(self, squeak_hash):
self.postgres_db.delete_squeak(squeak_hash)
self.squeak_db.delete_squeak(squeak_hash)
def _get_block_info_for_height(self, block_height):
return self.blockchain_client.get_block_info_by_height(block_height)

View file

@ -4,11 +4,11 @@ logger = logging.getLogger(__name__)
class SqueakExpiredOfferCleaner:
def __init__(self, postgres_db):
self.postgres_db = postgres_db
def __init__(self, squeak_db):
self.squeak_db = squeak_db
def delete_all_expired_offers(self):
logger.debug("Deleting expired offers.")
num_expired_offers = self.postgres_db.delete_expired_offers()
num_expired_offers = self.squeak_db.delete_expired_offers()
if num_expired_offers > 0:
logger.info("Deleted number of offers: {}".format(num_expired_offers))

View file

@ -33,7 +33,7 @@ logger = logging.getLogger(__name__)
class SqueakNode:
def __init__(
self,
postgres_db,
squeak_db,
blockchain_client,
lightning_client,
lightning_host_port,
@ -41,13 +41,13 @@ class SqueakNode:
max_squeaks_per_address_per_hour,
sync_interval_s,
):
self.postgres_db = postgres_db
self.squeak_db = squeak_db
self.blockchain_client = blockchain_client
self.lightning_client = lightning_client
self.lightning_host_port = lightning_host_port
self.price_msat = price_msat
self.sync_interval_s = sync_interval_s
self.squeak_block_verifier = SqueakBlockVerifier(postgres_db, blockchain_client)
self.squeak_block_verifier = SqueakBlockVerifier(squeak_db, blockchain_client)
self.squeak_block_periodic_worker = SqueakBlockPeriodicWorker(
self.squeak_block_verifier
)
@ -55,16 +55,16 @@ class SqueakNode:
self.squeak_block_verifier
)
self.squeak_rate_limiter = SqueakRateLimiter(
postgres_db,
squeak_db,
blockchain_client,
lightning_client,
max_squeaks_per_address_per_hour,
)
self.squeak_whitelist = SqueakWhitelist(
postgres_db,
squeak_db,
)
self.squeak_store = SqueakStore(
postgres_db,
squeak_db,
self.squeak_block_verifier,
self.squeak_rate_limiter,
self.squeak_whitelist,
@ -72,7 +72,7 @@ class SqueakNode:
self.squeak_sync_controller = SqueakSyncController(
self.blockchain_client,
self.squeak_store,
self.postgres_db,
self.squeak_db,
self.lightning_client,
)
self.squeak_peer_sync_worker = SqueakPeerSyncWorker(
@ -80,7 +80,7 @@ class SqueakNode:
self.sync_interval_s,
)
self.squeak_expired_offer_cleaner = SqueakExpiredOfferCleaner(
self.postgres_db,
self.squeak_db,
)
self.squeak_offer_expiry_worker = SqueakOfferExpiryWorker(
self.squeak_expired_offer_cleaner,
@ -159,7 +159,7 @@ class SqueakNode:
sharing=False,
following=False,
)
return self.postgres_db.insert_profile(squeak_profile)
return self.squeak_db.insert_profile(squeak_profile)
def create_contact_profile(self, profile_name, squeak_address):
address_validator = SqueakAddressValidator()
@ -173,35 +173,35 @@ class SqueakNode:
sharing=False,
following=False,
)
return self.postgres_db.insert_profile(squeak_profile)
return self.squeak_db.insert_profile(squeak_profile)
def get_signing_profiles(self):
return self.postgres_db.get_signing_profiles()
return self.squeak_db.get_signing_profiles()
def get_contact_profiles(self):
return self.postgres_db.get_contact_profiles()
return self.squeak_db.get_contact_profiles()
def get_squeak_profile(self, profile_id):
return self.postgres_db.get_profile(profile_id)
return self.squeak_db.get_profile(profile_id)
def get_squeak_profile_by_address(self, address):
return self.postgres_db.get_profile_by_address(address)
return self.squeak_db.get_profile_by_address(address)
def get_squeak_profile_by_name(self, name):
return self.postgres_db.get_profile_by_name(name)
return self.squeak_db.get_profile_by_name(name)
def set_squeak_profile_following(self, profile_id, following):
self.postgres_db.set_profile_following(profile_id, following)
self.squeak_db.set_profile_following(profile_id, following)
self.squeak_whitelist.refresh()
def set_squeak_profile_sharing(self, profile_id, sharing):
self.postgres_db.set_profile_sharing(profile_id, sharing)
self.squeak_db.set_profile_sharing(profile_id, sharing)
def delete_squeak_profile(self, profile_id):
self.postgres_db.delete_profile(profile_id)
self.squeak_db.delete_profile(profile_id)
def make_squeak(self, profile_id, content_str, replyto_hash):
squeak_profile = self.postgres_db.get_profile(profile_id)
squeak_profile = self.squeak_db.get_profile(profile_id)
squeak_maker = SqueakMaker(self.blockchain_client)
squeak = squeak_maker.make_squeak(squeak_profile, content_str, replyto_hash)
return self.save_created_squeak(squeak)
@ -227,7 +227,7 @@ class SqueakNode:
)
def delete_squeak(self, squeak_hash):
num_deleted_offers = self.postgres_db.delete_offers_for_squeak(squeak_hash)
num_deleted_offers = self.squeak_db.delete_offers_for_squeak(squeak_hash)
logger.info("Deleted number of offers : {}".format(num_deleted_offers))
return self.squeak_store.delete_squeak(squeak_hash)
@ -240,32 +240,32 @@ class SqueakNode:
uploading=False,
downloading=False,
)
return self.postgres_db.insert_peer(squeak_peer)
return self.squeak_db.insert_peer(squeak_peer)
def get_peer(self, peer_id):
return self.postgres_db.get_peer(peer_id)
return self.squeak_db.get_peer(peer_id)
def get_peers(self):
return self.postgres_db.get_peers()
return self.squeak_db.get_peers()
def set_peer_downloading(self, peer_id, downloading):
self.postgres_db.set_peer_downloading(peer_id, downloading)
self.squeak_db.set_peer_downloading(peer_id, downloading)
def set_peer_uploading(self, peer_id, uploading):
self.postgres_db.set_peer_uploading(peer_id, uploading)
self.squeak_db.set_peer_uploading(peer_id, uploading)
def delete_peer(self, peer_id):
self.postgres_db.delete_peer(peer_id)
self.squeak_db.delete_peer(peer_id)
def get_buy_offers_with_peer(self, squeak_hash):
return self.postgres_db.get_offers_with_peer(squeak_hash)
return self.squeak_db.get_offers_with_peer(squeak_hash)
def get_buy_offer_with_peer(self, offer_id):
return self.postgres_db.get_offer_with_peer(offer_id)
return self.squeak_db.get_offer_with_peer(offer_id)
def pay_offer(self, offer_id):
# Get the offer from the database
offer_with_peer = self.postgres_db.get_offer_with_peer(offer_id)
offer_with_peer = self.squeak_db.get_offer_with_peer(offer_id)
offer = offer_with_peer.offer
# Pay the invoice
@ -292,7 +292,7 @@ class SqueakNode:
preimage_is_valid=is_valid_preimage,
time_ms=None,
)
sent_payment_id = self.postgres_db.insert_sent_payment(sent_payment)
sent_payment_id = self.squeak_db.insert_sent_payment(sent_payment)
if is_valid_preimage:
self.unlock_squeak(offer, preimage)
@ -300,7 +300,7 @@ class SqueakNode:
return sent_payment_id
def unlock_squeak(self, offer, preimage):
squeak_entry = self.postgres_db.get_squeak_entry(offer.squeak_hash)
squeak_entry = self.squeak_db.get_squeak_entry(offer.squeak_hash)
squeak = squeak_entry.squeak
# Verify with the payment preimage and decryption key ciphertext
@ -328,11 +328,11 @@ class SqueakNode:
return self.squeak_sync_controller.sync_timeline()
def sync_squeak(self, squeak_hash):
peers = self.postgres_db.get_peers()
peers = self.squeak_db.get_peers()
return self.squeak_sync_controller.sync_single_squeak(squeak_hash, peers)
def get_sent_payments(self):
return self.postgres_db.get_sent_payments()
return self.squeak_db.get_sent_payments()
def get_sent_payment(self, sent_payment_id):
return self.postgres_db.get_sent_payment(sent_payment_id)
return self.squeak_db.get_sent_payment(sent_payment_id)

View file

@ -11,12 +11,12 @@ HOUR_IN_SECONDS = 3600
class SqueakRateLimiter:
def __init__(
self,
postgres_db,
squeak_db,
blockchain_client,
lightning_client,
max_squeaks_per_address_per_hour,
):
self.postgres_db = postgres_db
self.squeak_db = squeak_db
self.blockchain_client = blockchain_client
self.lightning_client = lightning_client
self.max_squeaks_per_address_per_hour = max_squeaks_per_address_per_hour
@ -42,7 +42,7 @@ class SqueakRateLimiter:
squeak_address
)
)
hashes = self.postgres_db.lookup_squeaks_by_time(
hashes = self.squeak_db.lookup_squeaks_by_time(
[squeak_address],
HOUR_IN_SECONDS,
include_unverified=True,

View file

@ -7,9 +7,9 @@ logger = logging.getLogger(__name__)
class SqueakStore:
def __init__(
self, postgres_db, squeak_block_verifier, squeak_rate_limiter, squeak_whitelist
self, squeak_db, squeak_block_verifier, squeak_rate_limiter, squeak_whitelist
):
self.postgres_db = postgres_db
self.squeak_db = squeak_db
self.squeak_block_verifier = squeak_block_verifier
self.squeak_rate_limiter = squeak_rate_limiter
self.squeak_whitelist = squeak_whitelist
@ -22,7 +22,7 @@ class SqueakStore:
if not self.squeak_rate_limiter.should_rate_limit_allow(squeak):
raise Exception("Excedeed allowed number of squeaks per block.")
inserted_squeak_hash = self.postgres_db.insert_squeak(squeak)
inserted_squeak_hash = self.squeak_db.insert_squeak(squeak)
if verify:
self.squeak_block_verifier.verify_squeak_block(inserted_squeak_hash)
else:
@ -30,7 +30,7 @@ class SqueakStore:
return inserted_squeak_hash
def get_squeak(self, squeak_hash, clear_decryption_key=False):
squeak_entry = self.postgres_db.get_squeak_entry(squeak_hash)
squeak_entry = self.squeak_db.get_squeak_entry(squeak_hash)
if squeak_entry is None:
return None
squeak = squeak_entry.squeak
@ -39,37 +39,37 @@ class SqueakStore:
return squeak
def get_squeak_entry_with_profile(self, squeak_hash):
return self.postgres_db.get_squeak_entry_with_profile(squeak_hash)
return self.squeak_db.get_squeak_entry_with_profile(squeak_hash)
def get_followed_squeak_entries_with_profile(self):
return self.postgres_db.get_followed_squeak_entries_with_profile()
return self.squeak_db.get_followed_squeak_entries_with_profile()
def get_squeak_entries_with_profile_for_address(
self, address, min_block, max_block
):
return self.postgres_db.get_squeak_entries_with_profile_for_address(
return self.squeak_db.get_squeak_entries_with_profile_for_address(
address,
min_block,
max_block,
)
def get_ancestor_squeak_entries_with_profile(self, squeak_hash_str):
return self.postgres_db.get_thread_ancestor_squeak_entries_with_profile(
return self.squeak_db.get_thread_ancestor_squeak_entries_with_profile(
squeak_hash_str,
)
def delete_squeak(self, squeak_hash):
return self.postgres_db.delete_squeak(squeak_hash)
return self.squeak_db.delete_squeak(squeak_hash)
def lookup_squeaks(self, addresses, min_block, max_block):
return self.postgres_db.lookup_squeaks(
return self.squeak_db.lookup_squeaks(
addresses,
min_block,
max_block,
)
def lookup_squeaks_include_locked(self, addresses, min_block, max_block):
return self.postgres_db.lookup_squeaks(
return self.squeak_db.lookup_squeaks(
addresses,
min_block,
max_block,
@ -77,7 +77,7 @@ class SqueakStore:
)
def lookup_squeaks_needing_offer(self, addresses, min_block, max_block, peer_id):
return self.postgres_db.lookup_squeaks_needing_offer(
return self.squeak_db.lookup_squeaks_needing_offer(
addresses,
min_block,
max_block,
@ -85,7 +85,7 @@ class SqueakStore:
)
def unlock_squeak(self, squeak_hash, vch_decryption_key):
self.postgres_db.set_squeak_decryption_key(
self.squeak_db.set_squeak_decryption_key(
squeak_hash,
vch_decryption_key,
)

View file

@ -11,12 +11,12 @@ logger = logging.getLogger(__name__)
class SqueakSyncController:
def __init__(self, blockchain_client, squeak_store, postgres_db, lightning_client):
def __init__(self, blockchain_client, squeak_store, squeak_db, lightning_client):
self.blockchain_client = blockchain_client
self.squeak_store = squeak_store
self.postgres_db = postgres_db
self.squeak_db = squeak_db
self.lightning_client = lightning_client
self.network_sync = NetworkSync(squeak_store, postgres_db, lightning_client)
self.network_sync = NetworkSync(squeak_store, squeak_db, lightning_client)
def sync_timeline(self):
try:
@ -27,7 +27,7 @@ class SqueakSyncController:
"Failed to sync because unable to get blockchain info.", exc_info=False
)
return
peers = self.postgres_db.get_peers()
peers = self.squeak_db.get_peers()
dowload_timeline_task = TimelineNetworkSyncTask(
self.network_sync,
block_height,

View file

@ -6,8 +6,8 @@ logger = logging.getLogger(__name__)
class SqueakWhitelist:
def __init__(self, postgres_db):
self.postgres_db = postgres_db
def __init__(self, squeak_db):
self.squeak_db = squeak_db
self.allowed_addresses = []
self.refresh()
@ -30,7 +30,7 @@ class SqueakWhitelist:
self.allowed_addresses = whitelisted_addresses
def _get_whitelisted_addresses(self):
whitelisted_profiles = self.postgres_db.get_following_profiles()
whitelisted_profiles = self.squeak_db.get_following_profiles()
return [profile.address for profile in whitelisted_profiles]
def get_allowed_addresses(self, addresses):