diff --git a/squeaknode/bitcoin/blockchain_client.py b/squeaknode/bitcoin/bitcoin_client.py similarity index 94% rename from squeaknode/bitcoin/blockchain_client.py rename to squeaknode/bitcoin/bitcoin_client.py index b2fe0506..ee33c039 100644 --- a/squeaknode/bitcoin/blockchain_client.py +++ b/squeaknode/bitcoin/bitcoin_client.py @@ -7,7 +7,8 @@ from squeaknode.bitcoin.block_info import BlockInfo logger = logging.getLogger(__name__) -class BlockchainClient(ABC): +class BitcoinClient(ABC): + @abstractmethod def get_best_block_info(self) -> BlockInfo: pass diff --git a/squeaknode/bitcoin/bitcoin_blockchain_client.py b/squeaknode/bitcoin/bitcoin_core_bitcoin_client.py similarity index 94% rename from squeaknode/bitcoin/bitcoin_blockchain_client.py rename to squeaknode/bitcoin/bitcoin_core_bitcoin_client.py index 12b78836..0e058d6e 100644 --- a/squeaknode/bitcoin/bitcoin_blockchain_client.py +++ b/squeaknode/bitcoin/bitcoin_core_bitcoin_client.py @@ -4,13 +4,13 @@ import os import requests +from squeaknode.bitcoin.bitcoin_client import BitcoinClient from squeaknode.bitcoin.block_info import BlockInfo -from squeaknode.bitcoin.blockchain_client import BlockchainClient logger = logging.getLogger(__name__) -class BitcoinBlockchainClient(BlockchainClient): +class BitcoinCoreBitcoinClient(BitcoinClient): """Access a bitcoin daemon using RPC.""" def __init__( @@ -33,7 +33,7 @@ class BitcoinBlockchainClient(BlockchainClient): def get_best_block_info(self) -> BlockInfo: block_height = self.get_block_count() - logger.info("Best block height: {}".format(block_height)) + logger.debug("Best block height: {}".format(block_height)) return self.get_block_info_by_height(block_height) def get_block_info_by_height(self, block_height: int) -> BlockInfo: diff --git a/squeaknode/core/squeak_core.py b/squeaknode/core/squeak_core.py index f23a14d5..4d568ab7 100644 --- a/squeaknode/core/squeak_core.py +++ b/squeaknode/core/squeak_core.py @@ -8,7 +8,7 @@ from squeak.core import MakeSqueakFromStr from squeak.core.elliptic import payment_point_bytes_from_scalar_bytes from squeak.core.signing import CSigningKey -from squeaknode.bitcoin.blockchain_client import BlockchainClient +from squeaknode.bitcoin.bitcoin_client import BitcoinClient from squeaknode.bitcoin.util import parse_block_header from squeaknode.core.offer import Offer from squeaknode.core.received_offer import ReceivedOffer @@ -34,10 +34,10 @@ logger = logging.getLogger(__name__) class SqueakCore: def __init__( self, - blockchain_client: BlockchainClient, + bitcoin_client: BitcoinClient, lightning_client: LNDLightningClient, ): - self.blockchain_client = blockchain_client + 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) -> SqueakEntry: @@ -58,7 +58,7 @@ class SqueakCore: raise Exception("Can't make squeak with a contact profile.") signing_key_str = signing_profile.private_key.decode() signing_key = CSigningKey(signing_key_str) - block_info = self.blockchain_client.get_best_block_info() + block_info = self.bitcoin_client.get_best_block_info() block_height = block_info.block_height block_hash = block_info.block_hash timestamp = int(time.time()) @@ -89,7 +89,7 @@ class SqueakCore: Raises: Exception: If the block hash is not valid. """ - block_info = self.blockchain_client.get_block_info_by_height( + block_info = self.bitcoin_client.get_block_info_by_height( squeak.nBlockHeight) if squeak.hashBlock != block_info.block_hash: raise Exception("Block hash incorrect.") @@ -105,7 +105,7 @@ class SqueakCore: Returns: int: the current latest block height. """ - block_info = self.blockchain_client.get_best_block_info() + block_info = self.bitcoin_client.get_best_block_info() return block_info.block_height def create_offer(self, squeak: CSqueak, client_addr: str, price_msat: int) -> SentOffer: diff --git a/squeaknode/node/squeak_node.py b/squeaknode/node/squeak_node.py index e45a3fea..520756f6 100644 --- a/squeaknode/node/squeak_node.py +++ b/squeaknode/node/squeak_node.py @@ -7,7 +7,7 @@ from squeak.params import SelectParams from squeaknode.admin.squeak_admin_server_handler import SqueakAdminServerHandler from squeaknode.admin.squeak_admin_server_servicer import SqueakAdminServerServicer from squeaknode.admin.webapp.app import SqueakAdminWebServer -from squeaknode.bitcoin.bitcoin_blockchain_client import BitcoinBlockchainClient +from squeaknode.bitcoin.bitcoin_core_bitcoin_client import BitcoinCoreBitcoinClient from squeaknode.config.config import SqueaknodeConfig from squeaknode.core.squeak_controller import SqueakController from squeaknode.core.squeak_core import SqueakCore @@ -48,11 +48,11 @@ class SqueakNode: # load the lightning client lightning_client = load_lightning_client(self.config) - # load the blockchain client - blockchain_client = load_blockchain_client(self.config) + # load the bitcoin client + bitcoin_client = load_bitcoin_client(self.config) squeak_core = SqueakCore( - blockchain_client, + bitcoin_client, lightning_client, ) squeak_rate_limiter = SqueakRateLimiter( @@ -200,8 +200,8 @@ def load_db(config, network): return SqueakDb(engine) -def load_blockchain_client(config): - return BitcoinBlockchainClient( +def load_bitcoin_client(config): + return BitcoinCoreBitcoinClient( config.bitcoin.rpc_host, config.bitcoin.rpc_port, config.bitcoin.rpc_user, diff --git a/tests/core/test_squeak_core.py b/tests/core/test_squeak_core.py index ed2a6ee6..87cdd1a8 100644 --- a/tests/core/test_squeak_core.py +++ b/tests/core/test_squeak_core.py @@ -4,8 +4,8 @@ from bitcoin.core import CoreMainParams from squeak.core.signing import CSigningKey from squeak.core.signing import CSqueakAddress +from squeaknode.bitcoin.bitcoin_client import BitcoinClient from squeaknode.bitcoin.block_info import BlockInfo -from squeaknode.bitcoin.blockchain_client import BlockchainClient from squeaknode.core.lightning_address import LightningAddressHostPort from squeaknode.core.squeak_core import SqueakCore from squeaknode.core.squeak_profile import SqueakProfile @@ -31,7 +31,7 @@ def max_squeaks_per_address_per_hour(): return 5000 -class MockBitcoinClient(BlockchainClient): +class MockBitcoinClient(BitcoinClient): genesis_block_info = BlockInfo( block_height=0, block_hash=CoreMainParams.GENESIS_BLOCK.GetHash(),