mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-13 12:33:25 +02:00
Add precommit hooks (#526)
This commit is contained in:
parent
089db023c8
commit
22f6b4fc3c
45 changed files with 472 additions and 350 deletions
14
.flake8
Normal file
14
.flake8
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[flake8]
|
||||
ignore = E203, E266, E501, W503, F403, F401, C901
|
||||
exclude =
|
||||
.git,
|
||||
__pycache__,
|
||||
docs/source/conf.py,
|
||||
old,
|
||||
build,
|
||||
dist,
|
||||
tox,
|
||||
proto
|
||||
max-line-length = 79
|
||||
max-complexity = 18
|
||||
select = B,C,E,F,W,T4,B9
|
||||
26
.pre-commit-config.yaml
Normal file
26
.pre-commit-config.yaml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v3.4.0
|
||||
hooks:
|
||||
# - id: trailing-whitespace
|
||||
# exclude: static/*
|
||||
# - id: end-of-file-fixer
|
||||
# exclude: static/*
|
||||
- id: check-yaml
|
||||
- id: debug-statements
|
||||
# - id: name-tests-test
|
||||
- id: requirements-txt-fixer
|
||||
- id: check-byte-order-marker
|
||||
- id: check-merge-conflict
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.7.9
|
||||
hooks:
|
||||
- id: flake8
|
||||
- repo: https://github.com/pre-commit/mirrors-autopep8
|
||||
rev: v1.5.4
|
||||
hooks:
|
||||
- id: autopep8
|
||||
- repo: https://github.com/asottile/reorder_python_imports
|
||||
rev: v2.3.6
|
||||
hooks:
|
||||
- id: reorder-python-imports
|
||||
2
Makefile
2
Makefile
|
|
@ -12,8 +12,6 @@ clean:
|
|||
|
||||
test: gen-protos
|
||||
tox
|
||||
tox -e codechecks
|
||||
tox -e mypy
|
||||
|
||||
codeformat: gen-protos
|
||||
tox -e autoflake
|
||||
|
|
|
|||
|
|
@ -4,8 +4,12 @@ import grpc
|
|||
import pytest
|
||||
from squeak.params import SelectParams
|
||||
|
||||
from proto import squeak_admin_pb2, squeak_admin_pb2_grpc, squeak_server_pb2_grpc
|
||||
from tests.util import generate_signing_key, get_address, load_lightning_client
|
||||
from proto import squeak_admin_pb2
|
||||
from proto import squeak_admin_pb2_grpc
|
||||
from proto import squeak_server_pb2_grpc
|
||||
from tests.util import generate_signing_key
|
||||
from tests.util import get_address
|
||||
from tests.util import load_lightning_client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
|
|
|||
|
|
@ -5,22 +5,22 @@ import time
|
|||
from hashlib import sha256
|
||||
|
||||
import pytest
|
||||
from squeak.core import CheckSqueak, CSqueak
|
||||
from squeak.core import CheckSqueak
|
||||
from squeak.core import CSqueak
|
||||
|
||||
from proto import lnd_pb2 as ln
|
||||
from proto import squeak_admin_pb2, squeak_server_pb2
|
||||
from tests.util import (
|
||||
build_squeak_msg,
|
||||
connect_peer,
|
||||
generate_signing_key,
|
||||
get_address,
|
||||
get_hash,
|
||||
get_latest_block_info,
|
||||
make_squeak,
|
||||
open_channel,
|
||||
squeak_from_msg,
|
||||
subtract_tweak,
|
||||
)
|
||||
from proto import squeak_admin_pb2
|
||||
from proto import squeak_server_pb2
|
||||
from tests.util import build_squeak_msg
|
||||
from tests.util import connect_peer
|
||||
from tests.util import generate_signing_key
|
||||
from tests.util import get_address
|
||||
from tests.util import get_hash
|
||||
from tests.util import get_latest_block_info
|
||||
from tests.util import make_squeak
|
||||
from tests.util import open_channel
|
||||
from tests.util import squeak_from_msg
|
||||
from tests.util import subtract_tweak
|
||||
|
||||
|
||||
def test_get_profile(server_stub, admin_stub, signing_profile_id):
|
||||
|
|
@ -89,7 +89,8 @@ def test_post_squeak_not_following(
|
|||
|
||||
squeak_msg = build_squeak_msg(squeak)
|
||||
with pytest.raises(Exception):
|
||||
server_stub.PostSqueak(squeak_server_pb2.PostSqueakRequest(squeak=squeak_msg))
|
||||
server_stub.PostSqueak(
|
||||
squeak_server_pb2.PostSqueakRequest(squeak=squeak_msg))
|
||||
|
||||
|
||||
def test_lookup_squeaks(server_stub, admin_stub, signing_profile_id, saved_squeak_hash):
|
||||
|
|
@ -155,7 +156,8 @@ def test_lookup_squeaks_empty_result_block_ranges(
|
|||
|
||||
def test_sell_squeak(server_stub, admin_stub, lightning_client, saved_squeak_hash):
|
||||
# Check the server balance
|
||||
get_balance_response = admin_stub.LndWalletBalance(ln.WalletBalanceRequest())
|
||||
get_balance_response = admin_stub.LndWalletBalance(
|
||||
ln.WalletBalanceRequest())
|
||||
initial_server_balance = get_balance_response.total_balance
|
||||
|
||||
# Get the squeak from the server
|
||||
|
|
@ -189,7 +191,8 @@ def test_sell_squeak(server_stub, admin_stub, lightning_client, saved_squeak_has
|
|||
# list_channels_response = lightning_client.list_channels()
|
||||
|
||||
# Pay the invoice
|
||||
payment = lightning_client.pay_invoice_sync(buy_response.offer.payment_request)
|
||||
payment = lightning_client.pay_invoice_sync(
|
||||
buy_response.offer.payment_request)
|
||||
preimage = payment.payment_preimage
|
||||
|
||||
# Verify with the payment preimage and decryption key ciphertext (TODO: switch to using payment point)
|
||||
|
|
@ -205,7 +208,8 @@ def test_sell_squeak(server_stub, admin_stub, lightning_client, saved_squeak_has
|
|||
CheckSqueak(get_response_squeak)
|
||||
|
||||
# Check the server balance
|
||||
get_balance_response = admin_stub.LndWalletBalance(ln.WalletBalanceRequest())
|
||||
get_balance_response = admin_stub.LndWalletBalance(
|
||||
ln.WalletBalanceRequest())
|
||||
final_server_balance = get_balance_response.total_balance
|
||||
assert final_server_balance - initial_server_balance == 1000
|
||||
|
||||
|
|
@ -251,7 +255,8 @@ def test_make_squeak(server_stub, admin_stub, signing_profile_id):
|
|||
|
||||
# Get all squeak displays for the known address
|
||||
get_address_squeak_display_response = admin_stub.GetAddressSqueakDisplays(
|
||||
squeak_admin_pb2.GetAddressSqueakDisplaysRequest(address=squeak_profile_address)
|
||||
squeak_admin_pb2.GetAddressSqueakDisplaysRequest(
|
||||
address=squeak_profile_address)
|
||||
)
|
||||
assert len(get_address_squeak_display_response.squeak_display_entries) == 1
|
||||
for (
|
||||
|
|
@ -521,8 +526,10 @@ def test_create_peer(server_stub, admin_stub):
|
|||
assert get_peer_response.squeak_peer.port == 1234
|
||||
|
||||
# Get all peers
|
||||
get_peers_response = admin_stub.GetPeers(squeak_admin_pb2.GetPeersRequest())
|
||||
peer_hosts = [squeak_peer.host for squeak_peer in get_peers_response.squeak_peers]
|
||||
get_peers_response = admin_stub.GetPeers(
|
||||
squeak_admin_pb2.GetPeersRequest())
|
||||
peer_hosts = [
|
||||
squeak_peer.host for squeak_peer in get_peers_response.squeak_peers]
|
||||
assert "fake_host" in peer_hosts
|
||||
|
||||
|
||||
|
|
@ -623,7 +630,8 @@ def test_list_channels(server_stub, admin_stub, lightning_client, saved_squeak_h
|
|||
), open_channel(lightning_client, destination, 1000000):
|
||||
# List channels
|
||||
get_info_response = lightning_client.get_info()
|
||||
list_channels_response = admin_stub.LndListChannels(ln.ListChannelsRequest())
|
||||
list_channels_response = admin_stub.LndListChannels(
|
||||
ln.ListChannelsRequest())
|
||||
|
||||
assert len(list_channels_response.channels) > 0
|
||||
assert any(
|
||||
|
|
@ -633,7 +641,8 @@ def test_list_channels(server_stub, admin_stub, lightning_client, saved_squeak_h
|
|||
]
|
||||
)
|
||||
|
||||
list_channels_response = admin_stub.LndListChannels(ln.ListChannelsRequest())
|
||||
list_channels_response = admin_stub.LndListChannels(
|
||||
ln.ListChannelsRequest())
|
||||
assert len(list_channels_response.channels) == 0
|
||||
|
||||
|
||||
|
|
@ -758,7 +767,8 @@ def test_open_channel(server_stub, admin_stub, lightning_client, saved_squeak_ha
|
|||
print("Channel now open: " + str(channel_point))
|
||||
break
|
||||
|
||||
list_channels_response = admin_stub.LndListChannels(ln.ListChannelsRequest())
|
||||
list_channels_response = admin_stub.LndListChannels(
|
||||
ln.ListChannelsRequest())
|
||||
assert len(list_channels_response.channels) == 1
|
||||
|
||||
# Close the channel
|
||||
|
|
@ -772,7 +782,8 @@ def test_open_channel(server_stub, admin_stub, lightning_client, saved_squeak_ha
|
|||
print("Channel now closed.")
|
||||
break
|
||||
|
||||
list_channels_response = admin_stub.LndListChannels(ln.ListChannelsRequest())
|
||||
list_channels_response = admin_stub.LndListChannels(
|
||||
ln.ListChannelsRequest())
|
||||
assert len(list_channels_response.channels) == 0
|
||||
|
||||
|
||||
|
|
@ -927,7 +938,8 @@ def test_connect_other_node(
|
|||
squeak_admin_pb2.GetReceivedPaymentsRequest(),
|
||||
)
|
||||
print(
|
||||
"get_received_payments_response: {}".format(get_received_payments_response)
|
||||
"get_received_payments_response: {}".format(
|
||||
get_received_payments_response)
|
||||
)
|
||||
payment_hashes = [
|
||||
received_payment.payment_hash
|
||||
|
|
@ -936,7 +948,8 @@ def test_connect_other_node(
|
|||
assert sent_payment.payment_hash in payment_hashes
|
||||
for received_payment in get_received_payments_response.received_payments:
|
||||
received_payment_time_ms = received_payment.payment_time_ms
|
||||
print("received_payment_time_ms: {}".format(received_payment_time_ms))
|
||||
print("received_payment_time_ms: {}".format(
|
||||
received_payment_time_ms))
|
||||
received_payment_time = datetime.datetime.fromtimestamp(
|
||||
received_payment_time_ms / 1000.0
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,9 +4,14 @@ import time
|
|||
from contextlib import contextmanager
|
||||
|
||||
from lnd_lightning_client import LNDLightningClient
|
||||
from squeak.core import HASH_LENGTH, CSqueak, MakeSqueakFromStr
|
||||
from squeak.core.elliptic import scalar_difference, scalar_from_bytes, scalar_to_bytes
|
||||
from squeak.core.signing import CSigningKey, CSqueakAddress
|
||||
from squeak.core import CSqueak
|
||||
from squeak.core import HASH_LENGTH
|
||||
from squeak.core import MakeSqueakFromStr
|
||||
from squeak.core.elliptic import scalar_difference
|
||||
from squeak.core.elliptic import scalar_from_bytes
|
||||
from squeak.core.elliptic import scalar_to_bytes
|
||||
from squeak.core.signing import CSigningKey
|
||||
from squeak.core.signing import CSqueakAddress
|
||||
|
||||
from proto import squeak_server_pb2
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import time
|
||||
|
||||
from bitcoin.core import lx
|
||||
from squeak.core import HASH_LENGTH, MakeSqueakFromStr
|
||||
from squeak.core import HASH_LENGTH
|
||||
from squeak.core import MakeSqueakFromStr
|
||||
from squeak.core.signing import CSigningKey
|
||||
|
||||
|
||||
|
|
@ -13,7 +14,8 @@ def make_squeak(
|
|||
signing_key: CSigningKey, content: str, reply_to: bytes = b"\x00" * HASH_LENGTH
|
||||
):
|
||||
block_height = 0
|
||||
block_hash = lx("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")
|
||||
block_hash = lx(
|
||||
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")
|
||||
timestamp = int(time.time())
|
||||
return MakeSqueakFromStr(
|
||||
signing_key,
|
||||
|
|
|
|||
6
requirements-dev.txt
Normal file
6
requirements-dev.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
coverage==4.5.4
|
||||
flake8==3.7.9
|
||||
mock
|
||||
pre-commit
|
||||
pytest
|
||||
requirements-tools==1.2.4
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
importlib_resources==1.4.0
|
||||
squeaklib==0.5.1
|
||||
argparse
|
||||
googleapis-common-protos
|
||||
grpcio
|
||||
grpcio-tools
|
||||
importlib_resources==1.4.0
|
||||
pytest
|
||||
squeaklib==0.5.1
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
importlib_resources==1.4.0
|
||||
squeaklib==0.5.1
|
||||
alembic
|
||||
argparse
|
||||
Flask
|
||||
flask-cors
|
||||
flask-login
|
||||
Flask-WTF
|
||||
googleapis-common-protos
|
||||
grpcio
|
||||
grpcio-tools
|
||||
importlib_resources==1.4.0
|
||||
mypy-protobuf
|
||||
protobuf
|
||||
psycopg2
|
||||
requests
|
||||
SQLAlchemy
|
||||
Flask
|
||||
protobuf
|
||||
flask-login
|
||||
Flask-WTF
|
||||
flask-cors
|
||||
alembic
|
||||
squeaklib==0.5.1
|
||||
|
|
|
|||
4
setup.py
4
setup.py
|
|
@ -5,7 +5,9 @@ import pkg_resources
|
|||
import setuptools.command.build_py
|
||||
import setuptools.command.test
|
||||
from grpc_tools import protoc
|
||||
from setuptools import Command, find_packages, setup
|
||||
from setuptools import Command
|
||||
from setuptools import find_packages
|
||||
from setuptools import setup
|
||||
|
||||
from squeaknode import __version__
|
||||
|
||||
|
|
|
|||
|
|
@ -2,17 +2,15 @@ import logging
|
|||
import sys
|
||||
|
||||
from proto import squeak_admin_pb2
|
||||
from squeaknode.admin.util import (
|
||||
offer_entry_to_message,
|
||||
received_payments_to_message,
|
||||
sent_offer_to_message,
|
||||
sent_payment_with_peer_to_message,
|
||||
squeak_entry_to_detail_message,
|
||||
squeak_entry_to_message,
|
||||
squeak_peer_to_message,
|
||||
squeak_profile_to_message,
|
||||
sync_result_to_message,
|
||||
)
|
||||
from squeaknode.admin.util import offer_entry_to_message
|
||||
from squeaknode.admin.util import received_payments_to_message
|
||||
from squeaknode.admin.util import sent_offer_to_message
|
||||
from squeaknode.admin.util import sent_payment_with_peer_to_message
|
||||
from squeaknode.admin.util import squeak_entry_to_detail_message
|
||||
from squeaknode.admin.util import squeak_entry_to_message
|
||||
from squeaknode.admin.util import squeak_peer_to_message
|
||||
from squeaknode.admin.util import squeak_profile_to_message
|
||||
from squeaknode.admin.util import sync_result_to_message
|
||||
from squeaknode.lightning.lnd_lightning_client import LNDLightningClient
|
||||
from squeaknode.node.squeak_controller import SqueakController
|
||||
|
||||
|
|
@ -80,8 +78,10 @@ class SqueakAdminServerHandler(object):
|
|||
|
||||
def handle_create_signing_profile(self, request):
|
||||
profile_name = request.profile_name
|
||||
logger.info("Handle create signing profile with name: {}".format(profile_name))
|
||||
profile_id = self.squeak_controller.create_signing_profile(profile_name)
|
||||
logger.info(
|
||||
"Handle create signing profile with name: {}".format(profile_name))
|
||||
profile_id = self.squeak_controller.create_signing_profile(
|
||||
profile_name)
|
||||
logger.info("New profile_id: {}".format(profile_id))
|
||||
return squeak_admin_pb2.CreateSigningProfileReply(
|
||||
profile_id=profile_id,
|
||||
|
|
@ -108,14 +108,16 @@ class SqueakAdminServerHandler(object):
|
|||
logger.info("Handle get signing profiles.")
|
||||
profiles = self.squeak_controller.get_signing_profiles()
|
||||
logger.info("Got number of signing profiles: {}".format(len(profiles)))
|
||||
profile_msgs = [squeak_profile_to_message(profile) for profile in profiles]
|
||||
profile_msgs = [squeak_profile_to_message(
|
||||
profile) for profile in profiles]
|
||||
return squeak_admin_pb2.GetSigningProfilesReply(squeak_profiles=profile_msgs)
|
||||
|
||||
def handle_get_contact_profiles(self, request):
|
||||
logger.info("Handle get contact profiles.")
|
||||
profiles = self.squeak_controller.get_contact_profiles()
|
||||
logger.info("Got number of contact profiles: {}".format(len(profiles)))
|
||||
profile_msgs = [squeak_profile_to_message(profile) for profile in profiles]
|
||||
profile_msgs = [squeak_profile_to_message(
|
||||
profile) for profile in profiles]
|
||||
return squeak_admin_pb2.GetContactProfilesReply(squeak_profiles=profile_msgs)
|
||||
|
||||
def handle_get_squeak_profile(self, request):
|
||||
|
|
@ -131,8 +133,10 @@ class SqueakAdminServerHandler(object):
|
|||
|
||||
def handle_get_squeak_profile_by_address(self, request):
|
||||
address = request.address
|
||||
logger.info("Handle get squeak profile with address: {}".format(address))
|
||||
squeak_profile = self.squeak_controller.get_squeak_profile_by_address(address)
|
||||
logger.info(
|
||||
"Handle get squeak profile with address: {}".format(address))
|
||||
squeak_profile = self.squeak_controller.get_squeak_profile_by_address(
|
||||
address)
|
||||
squeak_profile_msg = squeak_profile_to_message(squeak_profile)
|
||||
return squeak_admin_pb2.GetSqueakProfileByAddressReply(
|
||||
squeak_profile=squeak_profile_msg
|
||||
|
|
@ -141,7 +145,8 @@ class SqueakAdminServerHandler(object):
|
|||
def handle_get_squeak_profile_by_name(self, request):
|
||||
name = request.name
|
||||
logger.info("Handle get squeak profile with name: {}".format(name))
|
||||
squeak_profile = self.squeak_controller.get_squeak_profile_by_name(name)
|
||||
squeak_profile = self.squeak_controller.get_squeak_profile_by_name(
|
||||
name)
|
||||
squeak_profile_msg = squeak_profile_to_message(squeak_profile)
|
||||
return squeak_admin_pb2.GetSqueakProfileByNameReply(
|
||||
squeak_profile=squeak_profile_msg
|
||||
|
|
@ -156,7 +161,8 @@ class SqueakAdminServerHandler(object):
|
|||
following,
|
||||
)
|
||||
)
|
||||
self.squeak_controller.set_squeak_profile_following(profile_id, following)
|
||||
self.squeak_controller.set_squeak_profile_following(
|
||||
profile_id, following)
|
||||
return squeak_admin_pb2.SetSqueakProfileFollowingReply()
|
||||
|
||||
def handle_set_squeak_profile_sharing(self, request):
|
||||
|
|
@ -173,7 +179,8 @@ class SqueakAdminServerHandler(object):
|
|||
|
||||
def handle_delete_squeak_profile(self, request):
|
||||
profile_id = request.profile_id
|
||||
logger.info("Handle delete squeak profile with id: {}".format(profile_id))
|
||||
logger.info(
|
||||
"Handle delete squeak profile with id: {}".format(profile_id))
|
||||
self.squeak_controller.delete_squeak_profile(profile_id)
|
||||
return squeak_admin_pb2.DeleteSqueakProfileReply()
|
||||
|
||||
|
|
@ -181,7 +188,8 @@ class SqueakAdminServerHandler(object):
|
|||
profile_id = request.profile_id
|
||||
content_str = request.content
|
||||
replyto_hash_str = request.replyto
|
||||
replyto_hash = bytes.fromhex(replyto_hash_str) if replyto_hash_str else None
|
||||
replyto_hash = bytes.fromhex(
|
||||
replyto_hash_str) if replyto_hash_str else None
|
||||
logger.info("Handle make squeak profile with id: {}".format(profile_id))
|
||||
inserted_squeak_hash = self.squeak_controller.make_squeak(
|
||||
profile_id, content_str, replyto_hash
|
||||
|
|
@ -192,14 +200,17 @@ class SqueakAdminServerHandler(object):
|
|||
|
||||
def handle_get_squeak_display_entry(self, request):
|
||||
squeak_hash = request.squeak_hash
|
||||
logger.info("Handle get squeak display entry for hash: {}".format(squeak_hash))
|
||||
logger.info(
|
||||
"Handle get squeak display entry for hash: {}".format(squeak_hash))
|
||||
squeak_entry_with_profile = (
|
||||
self.squeak_controller.get_squeak_entry_with_profile(squeak_hash)
|
||||
)
|
||||
logger.info("Squeak display entry: {}".format(squeak_entry_with_profile))
|
||||
logger.info("Squeak display entry: {}".format(
|
||||
squeak_entry_with_profile))
|
||||
display_message = squeak_entry_to_message(squeak_entry_with_profile)
|
||||
logger.info(
|
||||
"Returning squeak display entry message: {}".format(display_message)
|
||||
"Returning squeak display entry message: {}".format(
|
||||
display_message)
|
||||
)
|
||||
return squeak_admin_pb2.GetSqueakDisplayReply(
|
||||
squeak_display_entry=display_message
|
||||
|
|
@ -226,7 +237,8 @@ class SqueakAdminServerHandler(object):
|
|||
address = request.address
|
||||
min_block = 0
|
||||
max_block = sys.maxsize
|
||||
logger.info("Handle get squeak display entries for address: {}".format(address))
|
||||
logger.info(
|
||||
"Handle get squeak display entries for address: {}".format(address))
|
||||
squeak_entries_with_profile = (
|
||||
self.squeak_controller.get_squeak_entries_with_profile_for_address(
|
||||
address,
|
||||
|
|
@ -404,7 +416,8 @@ class SqueakAdminServerHandler(object):
|
|||
|
||||
def handle_get_sent_payment(self, request):
|
||||
sent_payment_id = request.sent_payment_id
|
||||
logger.info("Handle get sent payment with id: {}".format(sent_payment_id))
|
||||
logger.info(
|
||||
"Handle get sent payment with id: {}".format(sent_payment_id))
|
||||
sent_payment = self.squeak_controller.get_sent_payment(sent_payment_id)
|
||||
sent_payment_msg = sent_payment_with_peer_to_message(sent_payment)
|
||||
return squeak_admin_pb2.GetSentPaymentReply(
|
||||
|
|
@ -413,11 +426,13 @@ class SqueakAdminServerHandler(object):
|
|||
|
||||
def handle_get_squeak_details(self, request):
|
||||
squeak_hash = request.squeak_hash
|
||||
logger.info("Handle get squeak details for hash: {}".format(squeak_hash))
|
||||
logger.info(
|
||||
"Handle get squeak details for hash: {}".format(squeak_hash))
|
||||
squeak_entry_with_profile = (
|
||||
self.squeak_controller.get_squeak_entry_with_profile(squeak_hash)
|
||||
)
|
||||
detail_message = squeak_entry_to_detail_message(squeak_entry_with_profile)
|
||||
detail_message = squeak_entry_to_detail_message(
|
||||
squeak_entry_with_profile)
|
||||
return squeak_admin_pb2.GetSqueakDetailsReply(
|
||||
squeak_detail_entry=detail_message
|
||||
)
|
||||
|
|
@ -446,11 +461,13 @@ class SqueakAdminServerHandler(object):
|
|||
def handle_subscribe_received_payments(self, request):
|
||||
payment_index = request.payment_index
|
||||
logger.info(
|
||||
"Handle subscribe received payments with index: {}".format(payment_index)
|
||||
"Handle subscribe received payments with index: {}".format(
|
||||
payment_index)
|
||||
)
|
||||
received_payments_stream = self.squeak_controller.subscribe_received_payments(
|
||||
payment_index
|
||||
)
|
||||
for received_payment in received_payments_stream:
|
||||
received_payment_msg = received_payments_to_message(received_payment)
|
||||
received_payment_msg = received_payments_to_message(
|
||||
received_payment)
|
||||
yield received_payment_msg
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ from concurrent import futures
|
|||
|
||||
import grpc
|
||||
|
||||
from proto import squeak_admin_pb2, squeak_admin_pb2_grpc
|
||||
from proto import squeak_admin_pb2
|
||||
from proto import squeak_admin_pb2_grpc
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import logging
|
||||
|
||||
from proto import squeak_admin_pb2
|
||||
from squeaknode.core.util import get_hash, get_replyto
|
||||
from squeaknode.core.util import get_hash
|
||||
from squeaknode.core.util import get_replyto
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
from flask import Flask, flash, redirect, render_template, request, url_for
|
||||
from flask import flash
|
||||
from flask import Flask
|
||||
from flask import redirect
|
||||
from flask import render_template
|
||||
from flask import request
|
||||
from flask import url_for
|
||||
from flask_cors import CORS
|
||||
from flask_login import (
|
||||
LoginManager,
|
||||
current_user,
|
||||
login_required,
|
||||
login_user,
|
||||
logout_user,
|
||||
)
|
||||
from flask_login import current_user
|
||||
from flask_login import login_required
|
||||
from flask_login import login_user
|
||||
from flask_login import LoginManager
|
||||
from flask_login import logout_user
|
||||
|
||||
from proto import lnd_pb2, squeak_admin_pb2
|
||||
from proto import lnd_pb2
|
||||
from proto import squeak_admin_pb2
|
||||
from squeaknode.admin.webapp.forms import LoginForm
|
||||
from squeaknode.admin.webapp.squeak_admin_web_user import User
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
from flask_wtf import FlaskForm
|
||||
from wtforms import BooleanField, PasswordField, StringField, SubmitField
|
||||
from wtforms import BooleanField
|
||||
from wtforms import PasswordField
|
||||
from wtforms import StringField
|
||||
from wtforms import SubmitField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import logging
|
||||
|
||||
from flask_login import UserMixin
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
from werkzeug.security import check_password_hash
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from abc import ABC
|
||||
from abc import abstractmethod
|
||||
|
||||
from squeaknode.bitcoin.block_info import BlockInfo
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ class Config:
|
|||
|
||||
def _get_bitcoin_rpc_port(self):
|
||||
network = self._get_squeaknode_network()
|
||||
default_rpc_port = BITCOIN_RPC_PORT.get(network, DEFAULT_BITCOIN_RPC_PORT)
|
||||
default_rpc_port = BITCOIN_RPC_PORT.get(
|
||||
network, DEFAULT_BITCOIN_RPC_PORT)
|
||||
return self.parser.getint("bitcoin", "rpc_port", fallback=default_rpc_port)
|
||||
|
||||
def _get_bitcoin_rpc_user(self):
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import os
|
||||
|
||||
from squeak.core.elliptic import (
|
||||
generate_random_scalar,
|
||||
scalar_difference,
|
||||
scalar_from_bytes,
|
||||
scalar_sum,
|
||||
scalar_to_bytes,
|
||||
)
|
||||
from squeak.core.elliptic import generate_random_scalar
|
||||
from squeak.core.elliptic import scalar_difference
|
||||
from squeak.core.elliptic import scalar_from_bytes
|
||||
from squeak.core.elliptic import scalar_sum
|
||||
from squeak.core.elliptic import scalar_to_bytes
|
||||
|
||||
DATA_KEY_LENGTH = 32
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
|
||||
from squeaknode.db.models import Models
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
"""Initialize all
|
||||
|
||||
Revision ID: 82c409b96c66
|
||||
Revises:
|
||||
Revises:
|
||||
Create Date: 2020-12-28 15:35:10.195043
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
|
|
@ -19,97 +19,127 @@ depends_on = None
|
|||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('offer',
|
||||
sa.Column('offer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('payment_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('nonce', sa.String(length=64), nullable=False),
|
||||
sa.Column('payment_point', sa.String(length=66), nullable=False),
|
||||
sa.Column('invoice_timestamp', sa.Integer(), nullable=False),
|
||||
sa.Column('invoice_expiry', sa.Integer(), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('payment_request', sa.String(), nullable=False),
|
||||
sa.Column('destination', sa.String(length=66), nullable=False),
|
||||
sa.Column('node_host', sa.String(), nullable=False),
|
||||
sa.Column('node_port', sa.Integer(), nullable=False),
|
||||
sa.Column('peer_id', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('offer_id')
|
||||
)
|
||||
sa.Column('offer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text(
|
||||
'(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('payment_hash', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('nonce', sa.String(length=64), nullable=False),
|
||||
sa.Column('payment_point', sa.String(
|
||||
length=66), nullable=False),
|
||||
sa.Column('invoice_timestamp',
|
||||
sa.Integer(), nullable=False),
|
||||
sa.Column('invoice_expiry', sa.Integer(), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('payment_request', sa.String(), nullable=False),
|
||||
sa.Column('destination', sa.String(
|
||||
length=66), nullable=False),
|
||||
sa.Column('node_host', sa.String(), nullable=False),
|
||||
sa.Column('node_port', sa.Integer(), nullable=False),
|
||||
sa.Column('peer_id', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('offer_id')
|
||||
)
|
||||
op.create_table('peer',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('peer_name', sa.String(), nullable=True),
|
||||
sa.Column('server_host', sa.String(), nullable=False),
|
||||
sa.Column('server_port', sa.Integer(), nullable=False),
|
||||
sa.Column('uploading', sa.Boolean(), nullable=False),
|
||||
sa.Column('downloading', sa.Boolean(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text(
|
||||
'(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('peer_name', sa.String(), nullable=True),
|
||||
sa.Column('server_host', sa.String(), nullable=False),
|
||||
sa.Column('server_port', sa.Integer(), nullable=False),
|
||||
sa.Column('uploading', sa.Boolean(), nullable=False),
|
||||
sa.Column('downloading', sa.Boolean(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('profile',
|
||||
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('profile_name', sa.String(), nullable=False),
|
||||
sa.Column('private_key', sa.Binary(), nullable=True),
|
||||
sa.Column('address', sa.String(length=35), nullable=False),
|
||||
sa.Column('sharing', sa.Boolean(), nullable=False),
|
||||
sa.Column('following', sa.Boolean(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('profile_id'),
|
||||
sa.UniqueConstraint('address'),
|
||||
sa.UniqueConstraint('profile_name')
|
||||
)
|
||||
sa.Column('profile_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text(
|
||||
'(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('profile_name', sa.String(), nullable=False),
|
||||
sa.Column('private_key', sa.Binary(), nullable=True),
|
||||
sa.Column('address', sa.String(length=35), nullable=False),
|
||||
sa.Column('sharing', sa.Boolean(), nullable=False),
|
||||
sa.Column('following', sa.Boolean(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('profile_id'),
|
||||
sa.UniqueConstraint('address'),
|
||||
sa.UniqueConstraint('profile_name')
|
||||
)
|
||||
op.create_table('received_payment',
|
||||
sa.Column('received_payment_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('payment_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('settle_index', sa.Integer(), nullable=False),
|
||||
sa.Column('client_addr', sa.String(length=64), nullable=False),
|
||||
sa.PrimaryKeyConstraint('received_payment_id'),
|
||||
sa.UniqueConstraint('payment_hash')
|
||||
)
|
||||
sa.Column('received_payment_id',
|
||||
sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text(
|
||||
'(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('payment_hash', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('settle_index', sa.Integer(), nullable=False),
|
||||
sa.Column('client_addr', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.PrimaryKeyConstraint('received_payment_id'),
|
||||
sa.UniqueConstraint('payment_hash')
|
||||
)
|
||||
op.create_table('sent_offer',
|
||||
sa.Column('sent_offer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('payment_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('secret_key', sa.String(length=64), nullable=False),
|
||||
sa.Column('nonce', sa.String(length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('payment_request', sa.String(), nullable=False),
|
||||
sa.Column('invoice_timestamp', sa.Integer(), nullable=False),
|
||||
sa.Column('invoice_expiry', sa.Integer(), nullable=False),
|
||||
sa.Column('client_addr', sa.String(length=64), nullable=False),
|
||||
sa.PrimaryKeyConstraint('sent_offer_id'),
|
||||
sa.UniqueConstraint('payment_hash')
|
||||
)
|
||||
sa.Column('sent_offer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text(
|
||||
'(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('payment_hash', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('secret_key', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('nonce', sa.String(length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('payment_request', sa.String(), nullable=False),
|
||||
sa.Column('invoice_timestamp',
|
||||
sa.Integer(), nullable=False),
|
||||
sa.Column('invoice_expiry', sa.Integer(), nullable=False),
|
||||
sa.Column('client_addr', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.PrimaryKeyConstraint('sent_offer_id'),
|
||||
sa.UniqueConstraint('payment_hash')
|
||||
)
|
||||
op.create_table('sent_payment',
|
||||
sa.Column('sent_payment_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('offer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('peer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('payment_hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('secret_key', sa.String(length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('node_pubkey', sa.String(length=66), nullable=False),
|
||||
sa.PrimaryKeyConstraint('sent_payment_id')
|
||||
)
|
||||
sa.Column('sent_payment_id', sa.Integer(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text(
|
||||
'(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('offer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('peer_id', sa.Integer(), nullable=False),
|
||||
sa.Column('squeak_hash', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('payment_hash', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('secret_key', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('price_msat', sa.Integer(), nullable=False),
|
||||
sa.Column('node_pubkey', sa.String(
|
||||
length=66), nullable=False),
|
||||
sa.PrimaryKeyConstraint('sent_payment_id')
|
||||
)
|
||||
op.create_table('squeak',
|
||||
sa.Column('hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak', sa.Binary(), nullable=False),
|
||||
sa.Column('hash_reply_sqk', sa.String(length=64), nullable=False),
|
||||
sa.Column('hash_block', sa.String(length=64), nullable=False),
|
||||
sa.Column('n_block_height', sa.Integer(), nullable=False),
|
||||
sa.Column('n_time', sa.Integer(), nullable=False),
|
||||
sa.Column('author_address', sa.String(length=35), nullable=False),
|
||||
sa.Column('secret_key', sa.String(length=64), nullable=True),
|
||||
sa.Column('block_header', sa.Binary(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('hash')
|
||||
)
|
||||
sa.Column('hash', sa.String(length=64), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text(
|
||||
'(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('squeak', sa.Binary(), nullable=False),
|
||||
sa.Column('hash_reply_sqk', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('hash_block', sa.String(
|
||||
length=64), nullable=False),
|
||||
sa.Column('n_block_height', sa.Integer(), nullable=False),
|
||||
sa.Column('n_time', sa.Integer(), nullable=False),
|
||||
sa.Column('author_address', sa.String(
|
||||
length=35), nullable=False),
|
||||
sa.Column('secret_key', sa.String(
|
||||
length=64), nullable=True),
|
||||
sa.Column('block_header', sa.Binary(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('hash')
|
||||
)
|
||||
with op.batch_alter_table('squeak', schema=None) as batch_op:
|
||||
batch_op.create_index(batch_op.f('ix_squeak_author_address'), ['author_address'], unique=False)
|
||||
batch_op.create_index(batch_op.f('ix_squeak_author_address'), [
|
||||
'author_address'], unique=False)
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import logging
|
||||
|
||||
from pkg_resources import resource_filename
|
||||
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
from pkg_resources import resource_filename
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
|||
|
|
@ -1,23 +1,20 @@
|
|||
import datetime
|
||||
import logging
|
||||
|
||||
from sqlalchemy import Binary
|
||||
from sqlalchemy import Boolean
|
||||
from sqlalchemy import Column
|
||||
from sqlalchemy import DateTime
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy import Integer
|
||||
from sqlalchemy import MetaData
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy import Table
|
||||
from sqlalchemy.types import TypeDecorator
|
||||
from sqlalchemy import (
|
||||
Binary,
|
||||
Boolean,
|
||||
Column,
|
||||
DateTime,
|
||||
Integer,
|
||||
MetaData,
|
||||
String,
|
||||
Table,
|
||||
func,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
import datetime
|
||||
|
||||
class TZDateTime(TypeDecorator):
|
||||
impl = DateTime
|
||||
|
||||
|
|
@ -45,7 +42,8 @@ class Models:
|
|||
"squeak",
|
||||
self.metadata,
|
||||
Column("hash", String(64), primary_key=True),
|
||||
Column("created", TZDateTime, server_default=func.now(), nullable=False),
|
||||
Column("created", TZDateTime,
|
||||
server_default=func.now(), nullable=False),
|
||||
Column("squeak", Binary, nullable=False),
|
||||
Column("hash_reply_sqk", String(64), nullable=False),
|
||||
Column("hash_block", String(64), nullable=False),
|
||||
|
|
@ -60,7 +58,8 @@ class Models:
|
|||
"profile",
|
||||
self.metadata,
|
||||
Column("profile_id", Integer, primary_key=True),
|
||||
Column("created", TZDateTime, server_default=func.now(), nullable=False),
|
||||
Column("created", TZDateTime,
|
||||
server_default=func.now(), nullable=False),
|
||||
Column("profile_name", String, unique=True, nullable=False),
|
||||
Column("private_key", Binary),
|
||||
Column("address", String(35), unique=True, nullable=False),
|
||||
|
|
@ -72,7 +71,8 @@ class Models:
|
|||
"peer",
|
||||
self.metadata,
|
||||
Column("id", Integer, primary_key=True),
|
||||
Column("created", TZDateTime, server_default=func.now(), nullable=False),
|
||||
Column("created", TZDateTime,
|
||||
server_default=func.now(), nullable=False),
|
||||
Column("peer_name", String),
|
||||
Column("server_host", String, nullable=False),
|
||||
Column("server_port", Integer, nullable=False),
|
||||
|
|
@ -84,7 +84,8 @@ class Models:
|
|||
"offer",
|
||||
self.metadata,
|
||||
Column("offer_id", Integer, primary_key=True),
|
||||
Column("created", TZDateTime, server_default=func.now(), nullable=False),
|
||||
Column("created", TZDateTime,
|
||||
server_default=func.now(), nullable=False),
|
||||
Column("squeak_hash", String(64), nullable=False),
|
||||
Column("payment_hash", String(64), nullable=False),
|
||||
Column("nonce", String(64), nullable=False),
|
||||
|
|
@ -103,7 +104,8 @@ class Models:
|
|||
"sent_payment",
|
||||
self.metadata,
|
||||
Column("sent_payment_id", Integer, primary_key=True),
|
||||
Column("created", TZDateTime, server_default=func.now(), nullable=False),
|
||||
Column("created", TZDateTime,
|
||||
server_default=func.now(), nullable=False),
|
||||
Column("offer_id", Integer, nullable=False),
|
||||
Column("peer_id", Integer, nullable=False),
|
||||
Column("squeak_hash", String(64), nullable=False),
|
||||
|
|
@ -117,7 +119,8 @@ class Models:
|
|||
"sent_offer",
|
||||
self.metadata,
|
||||
Column("sent_offer_id", Integer, primary_key=True),
|
||||
Column("created", TZDateTime, server_default=func.now(), nullable=False),
|
||||
Column("created", TZDateTime,
|
||||
server_default=func.now(), nullable=False),
|
||||
Column("squeak_hash", String(64), nullable=False),
|
||||
Column("payment_hash", String(64), unique=True, nullable=False),
|
||||
Column("secret_key", String(64), nullable=False),
|
||||
|
|
@ -133,7 +136,8 @@ class Models:
|
|||
"received_payment",
|
||||
self.metadata,
|
||||
Column("received_payment_id", Integer, primary_key=True),
|
||||
Column("created", TZDateTime, server_default=func.now(), nullable=False),
|
||||
Column("created", TZDateTime,
|
||||
server_default=func.now(), nullable=False),
|
||||
Column("squeak_hash", String(64), nullable=False),
|
||||
Column("payment_hash", String(64), unique=True, nullable=False),
|
||||
Column("price_msat", Integer, nullable=False),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
import logging
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from datetime import timezone
|
||||
|
||||
import sqlalchemy
|
||||
from sqlalchemy import func, literal
|
||||
from sqlalchemy.sql import and_, or_, select
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy import literal
|
||||
from sqlalchemy.sql import and_
|
||||
from sqlalchemy.sql import or_
|
||||
from sqlalchemy.sql import select
|
||||
from squeak.core import CSqueak
|
||||
|
||||
from squeaknode.bitcoin.util import parse_block_header
|
||||
|
|
@ -307,7 +312,8 @@ class SqueakDb:
|
|||
select([self.squeaks.c.hash])
|
||||
.where(self.squeaks.c.author_address.in_(addresses))
|
||||
.where(
|
||||
self.squeaks.c.created > datetime.now(timezone.utc) - timedelta(seconds=interval_seconds)
|
||||
self.squeaks.c.created > datetime.now(
|
||||
timezone.utc) - timedelta(seconds=interval_seconds)
|
||||
)
|
||||
.where(
|
||||
or_(
|
||||
|
|
@ -503,7 +509,8 @@ class SqueakDb:
|
|||
|
||||
def get_profile(self, profile_id):
|
||||
""" Get a profile. """
|
||||
s = select([self.profiles]).where(self.profiles.c.profile_id == profile_id)
|
||||
s = select([self.profiles]).where(
|
||||
self.profiles.c.profile_id == profile_id)
|
||||
with self.get_connection() as connection:
|
||||
result = connection.execute(s)
|
||||
row = result.fetchone()
|
||||
|
|
@ -765,7 +772,8 @@ class SqueakDb:
|
|||
|
||||
def get_offers(self, squeak_hash):
|
||||
""" Get offers for a squeak hash. """
|
||||
s = select([self.offers]).where(self.offers.c.squeak_hash == squeak_hash)
|
||||
s = select([self.offers]).where(
|
||||
self.offers.c.squeak_hash == squeak_hash)
|
||||
with self.get_connection() as connection:
|
||||
result = connection.execute(s)
|
||||
rows = result.fetchall()
|
||||
|
|
@ -797,7 +805,8 @@ class SqueakDb:
|
|||
with self.get_connection() as connection:
|
||||
result = connection.execute(s)
|
||||
rows = result.fetchall()
|
||||
offers_with_peer = [self._parse_offer_with_peer(row) for row in rows]
|
||||
offers_with_peer = [
|
||||
self._parse_offer_with_peer(row) for row in rows]
|
||||
return offers_with_peer
|
||||
|
||||
# sql = """
|
||||
|
|
@ -833,7 +842,8 @@ class SqueakDb:
|
|||
def delete_expired_offers(self):
|
||||
""" Delete all expired offers. """
|
||||
s = self.offers.delete().where(
|
||||
datetime.now(timezone.utc).timestamp() > self.offers.c.invoice_timestamp + self.offers.c.invoice_expiry
|
||||
datetime.now(timezone.utc).timestamp(
|
||||
) > self.offers.c.invoice_timestamp + self.offers.c.invoice_expiry
|
||||
)
|
||||
with self.get_connection() as connection:
|
||||
res = connection.execute(s)
|
||||
|
|
@ -891,7 +901,8 @@ class SqueakDb:
|
|||
with self.get_connection() as connection:
|
||||
result = connection.execute(s)
|
||||
rows = result.fetchall()
|
||||
sent_payments = [self._parse_sent_payment_with_peer(row) for row in rows]
|
||||
sent_payments = [
|
||||
self._parse_sent_payment_with_peer(row) for row in rows]
|
||||
return sent_payments
|
||||
|
||||
def get_sent_payment(self, sent_payment_id):
|
||||
|
|
@ -967,7 +978,8 @@ class SqueakDb:
|
|||
def delete_expired_sent_offers(self):
|
||||
""" Delete all expired sent offers. """
|
||||
s = self.sent_offers.delete().where(
|
||||
datetime.now(timezone.utc).timestamp() > self.sent_offers.c.invoice_timestamp + self.sent_offers.c.invoice_expiry
|
||||
datetime.now(timezone.utc).timestamp(
|
||||
) > self.sent_offers.c.invoice_timestamp + self.sent_offers.c.invoice_expiry
|
||||
)
|
||||
with self.get_connection() as connection:
|
||||
res = connection.execute(s)
|
||||
|
|
@ -1008,7 +1020,8 @@ class SqueakDb:
|
|||
with self.get_connection() as connection:
|
||||
result = connection.execute(s)
|
||||
rows = result.fetchall()
|
||||
received_payments = [self._parse_received_payment(row) for row in rows]
|
||||
received_payments = [
|
||||
self._parse_received_payment(row) for row in rows]
|
||||
return received_payments
|
||||
|
||||
def yield_received_payments_from_index(self, start_index=0):
|
||||
|
|
@ -1031,14 +1044,17 @@ class SqueakDb:
|
|||
if row is None:
|
||||
return None
|
||||
secret_key_column = row["secret_key"]
|
||||
secret_key = bytes.fromhex(secret_key_column) if secret_key_column else b""
|
||||
secret_key = bytes.fromhex(
|
||||
secret_key_column) if secret_key_column else b""
|
||||
squeak = CSqueak.deserialize(row["squeak"])
|
||||
if secret_key:
|
||||
squeak.SetDecryptionKey(secret_key)
|
||||
block_header_column = row["block_header"]
|
||||
block_header_bytes = bytes(block_header_column) if block_header_column else None
|
||||
block_header_bytes = bytes(
|
||||
block_header_column) if block_header_column else None
|
||||
block_header = (
|
||||
parse_block_header(block_header_bytes) if block_header_bytes else None
|
||||
parse_block_header(
|
||||
block_header_bytes) if block_header_bytes else None
|
||||
)
|
||||
logger.info("Returning squeak entry with squeak: {}".format(squeak))
|
||||
return SqueakEntry(squeak=squeak, block_header=block_header)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import os
|
|||
|
||||
import grpc
|
||||
|
||||
from proto import lnd_pb2, lnd_pb2_grpc
|
||||
from proto import lnd_pb2
|
||||
from proto import lnd_pb2_grpc
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -49,7 +50,8 @@ class LNDLightningClient:
|
|||
|
||||
# combine the cert credentials and the macaroon auth credentials
|
||||
# such that every call is properly encrypted and authenticated
|
||||
combined_creds = grpc.composite_channel_credentials(cert_creds, auth_creds)
|
||||
combined_creds = grpc.composite_channel_credentials(
|
||||
cert_creds, auth_creds)
|
||||
|
||||
# finally pass in the combined credentials when creating a channel
|
||||
channel = grpc.secure_channel(url, combined_creds)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ from squeaknode.admin.webapp.app import SqueakAdminWebServer
|
|||
from squeaknode.bitcoin.bitcoin_blockchain_client import BitcoinBlockchainClient
|
||||
from squeaknode.config.config import Config
|
||||
from squeaknode.core.lightning_address import LightningAddressHostPort
|
||||
from squeaknode.db.db_engine import get_engine, get_sqlite_connection_string
|
||||
from squeaknode.db.db_engine import get_engine
|
||||
from squeaknode.db.db_engine import get_sqlite_connection_string
|
||||
from squeaknode.db.squeak_db import SqueakDb
|
||||
from squeaknode.lightning.lnd_lightning_client import LNDLightningClient
|
||||
from squeaknode.node.squeak_controller import SqueakController
|
||||
|
|
@ -169,7 +170,8 @@ def parse_args():
|
|||
subparsers = parser.add_subparsers(help="sub-command help")
|
||||
|
||||
# create the parser for the "run-server" command
|
||||
parser_run_server = subparsers.add_parser("run-server", help="run-server help")
|
||||
parser_run_server = subparsers.add_parser(
|
||||
"run-server", help="run-server help")
|
||||
parser_run_server.set_defaults(func=run_server)
|
||||
|
||||
return parser.parse_args()
|
||||
|
|
@ -207,7 +209,8 @@ def run_server(config):
|
|||
price_msat = load_price_msat(config)
|
||||
|
||||
# load the max squeaks per block per address
|
||||
max_squeaks_per_address_per_hour = load_max_squeaks_per_address_per_hour(config)
|
||||
max_squeaks_per_address_per_hour = load_max_squeaks_per_address_per_hour(
|
||||
config)
|
||||
|
||||
# load the lightning client
|
||||
lightning_client = load_lightning_client(config)
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ import logging
|
|||
from contextlib import contextmanager
|
||||
|
||||
import grpc
|
||||
from squeak.core import CheckSqueak, CSqueak
|
||||
from squeak.core import CheckSqueak
|
||||
from squeak.core import CSqueak
|
||||
|
||||
from proto import squeak_server_pb2, squeak_server_pb2_grpc
|
||||
from proto import squeak_server_pb2
|
||||
from proto import squeak_server_pb2_grpc
|
||||
from squeaknode.core.util import get_hash
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import logging
|
|||
import queue
|
||||
import threading
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, List
|
||||
from typing import Any
|
||||
from typing import List
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ class PeerSyncTask:
|
|||
logger.debug("Followed addresses: {}".format(addresses))
|
||||
|
||||
# Get remote hashes
|
||||
lookup_result = self._get_remote_hashes(addresses, min_block, max_block)
|
||||
lookup_result = self._get_remote_hashes(
|
||||
addresses, min_block, max_block)
|
||||
remote_hashes = lookup_result.hashes
|
||||
logger.debug("Got remote hashes: {}".format(len(remote_hashes)))
|
||||
for hash in remote_hashes:
|
||||
|
|
@ -63,14 +64,16 @@ class PeerSyncTask:
|
|||
self._download_squeak(hash)
|
||||
|
||||
# Get local hashes of locked squeaks that don't have an offer from this peer.
|
||||
locked_hashes = self._get_locked_hashes(addresses, min_block, max_block)
|
||||
locked_hashes = self._get_locked_hashes(
|
||||
addresses, min_block, max_block)
|
||||
logger.debug("Got locked hashes: {}".format(len(locked_hashes)))
|
||||
for hash in locked_hashes:
|
||||
logger.debug("locked hash: {}".format(hash))
|
||||
|
||||
# Get hashes to get offer
|
||||
hashes_to_get_offer = set(remote_hashes) & set(locked_hashes)
|
||||
logger.debug("Hashes to get offer: {}".format(len(hashes_to_get_offer)))
|
||||
logger.debug("Hashes to get offer: {}".format(
|
||||
len(hashes_to_get_offer)))
|
||||
for hash in hashes_to_get_offer:
|
||||
logger.debug("hash to get offer: {}".format(hash))
|
||||
|
||||
|
|
@ -91,7 +94,8 @@ class PeerSyncTask:
|
|||
logger.debug("Sharing addresses: {}".format(addresses))
|
||||
|
||||
# Get remote hashes
|
||||
lookup_result = self._get_remote_hashes(addresses, min_block, max_block)
|
||||
lookup_result = self._get_remote_hashes(
|
||||
addresses, min_block, max_block)
|
||||
remote_hashes = lookup_result.hashes
|
||||
allowed_addresses = lookup_result.allowed_addresses
|
||||
logger.debug("Got remote hashes: {}".format(len(remote_hashes)))
|
||||
|
|
@ -99,7 +103,8 @@ class PeerSyncTask:
|
|||
logger.debug("remote hash: {}".format(hash))
|
||||
|
||||
# Get local hashes
|
||||
local_hashes = self._get_local_unlocked_hashes(addresses, min_block, max_block)
|
||||
local_hashes = self._get_local_unlocked_hashes(
|
||||
addresses, min_block, max_block)
|
||||
logger.debug("Got local hashes: {}".format(len(local_hashes)))
|
||||
for hash in local_hashes:
|
||||
logger.debug("local hash: {}".format(hash))
|
||||
|
|
@ -122,13 +127,15 @@ class PeerSyncTask:
|
|||
|
||||
# Download squeak if not already present.
|
||||
saved_squeak = self._get_local_squeak(squeak_hash)
|
||||
logger.info("download_single_squeak with saved_squeak: {}".format(saved_squeak))
|
||||
logger.info(
|
||||
"download_single_squeak with saved_squeak: {}".format(saved_squeak))
|
||||
if not saved_squeak:
|
||||
self._download_squeak(squeak_hash)
|
||||
|
||||
# Download offer from peer if not already present.
|
||||
saved_offer = self._get_saved_offer(squeak_hash)
|
||||
logger.info("download_single_squeak with saved_offer: {}".format(saved_offer))
|
||||
logger.info(
|
||||
"download_single_squeak with saved_offer: {}".format(saved_offer))
|
||||
if not saved_offer:
|
||||
self._download_offer(squeak_hash)
|
||||
|
||||
|
|
@ -268,7 +275,8 @@ class PeerSyncTask:
|
|||
return [profile.address for profile in sharing_profiles]
|
||||
|
||||
def _download_offer_msg(self, squeak_hash):
|
||||
logger.info("Downloading buy offer for squeak hash: {}".format(squeak_hash))
|
||||
logger.info(
|
||||
"Downloading buy offer for squeak hash: {}".format(squeak_hash))
|
||||
return self.peer_client.buy_squeak(squeak_hash)
|
||||
|
||||
def _save_offer(self, offer):
|
||||
|
|
|
|||
|
|
@ -73,7 +73,8 @@ class ReceivedPaymentsSubscriptionClient:
|
|||
self._queue.put(payment)
|
||||
payment_index = payment.received_payment_id
|
||||
logger.info(
|
||||
"Added payment to queue. Size: {}".format(self._queue.qsize())
|
||||
"Added payment to queue. Size: {}".format(
|
||||
self._queue.qsize())
|
||||
)
|
||||
time.sleep(self.update_interval_s)
|
||||
|
||||
|
|
@ -86,5 +87,6 @@ class ReceivedPaymentsSubscriptionClient:
|
|||
yield payment
|
||||
self._queue.task_done()
|
||||
logger.info(
|
||||
"Removed payment from queue. Size: {}".format(self._queue.qsize())
|
||||
"Removed payment from queue. Size: {}".format(
|
||||
self._queue.qsize())
|
||||
)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ class SentOffersVerifier:
|
|||
settle_index,
|
||||
)
|
||||
)
|
||||
sent_offer = self.squeak_db.get_sent_offer_by_payment_hash(payment_hash)
|
||||
sent_offer = self.squeak_db.get_sent_offer_by_payment_hash(
|
||||
payment_hash)
|
||||
received_payment = ReceivedPayment(
|
||||
received_payment_id=None,
|
||||
created=None,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ class SentOffersWorker:
|
|||
self.squeak_controller = squeak_controller
|
||||
|
||||
def start_running(self):
|
||||
threading.Thread(target=self.process_subscribed_invoices, daemon=True).start()
|
||||
threading.Thread(
|
||||
target=self.process_subscribed_invoices, daemon=True).start()
|
||||
|
||||
def process_subscribed_invoices(self):
|
||||
self.squeak_controller.process_subscribed_invoices()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ class SqueakBlockVerifier:
|
|||
try:
|
||||
block_info = self._get_block_info_for_height(squeak.nBlockHeight)
|
||||
except Exception:
|
||||
logger.error("Failed to get block info for squeak.", exc_info=False)
|
||||
logger.error("Failed to get block info for squeak.",
|
||||
exc_info=False)
|
||||
return None
|
||||
if squeak.hashBlock != block_info.block_hash:
|
||||
logger.info("block hash incorrect: {}".format(block_info))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import logging
|
||||
|
||||
from squeak.core import CheckSqueak
|
||||
from squeak.core.signing import CSigningKey, CSqueakAddress
|
||||
from squeak.core.signing import CSigningKey
|
||||
from squeak.core.signing import CSqueakAddress
|
||||
|
||||
from squeaknode.core.buy_offer import BuyOffer
|
||||
from squeaknode.core.sent_offer import SentOffer
|
||||
|
|
@ -9,7 +10,9 @@ from squeaknode.core.sent_payment import SentPayment
|
|||
from squeaknode.core.squeak_address_validator import SqueakAddressValidator
|
||||
from squeaknode.core.squeak_peer import SqueakPeer
|
||||
from squeaknode.core.squeak_profile import SqueakProfile
|
||||
from squeaknode.core.util import add_tweak, generate_tweak, subtract_tweak
|
||||
from squeaknode.core.util import add_tweak
|
||||
from squeaknode.core.util import generate_tweak
|
||||
from squeaknode.core.util import subtract_tweak
|
||||
from squeaknode.node.received_payments_subscription_client import (
|
||||
OpenReceivedPaymentsSubscriptionClient,
|
||||
)
|
||||
|
|
@ -180,7 +183,8 @@ class SqueakController:
|
|||
def create_contact_profile(self, profile_name, squeak_address):
|
||||
address_validator = SqueakAddressValidator()
|
||||
if not address_validator.validate(squeak_address):
|
||||
raise Exception("Invalid squeak address: {}".format(squeak_address))
|
||||
raise Exception(
|
||||
"Invalid squeak address: {}".format(squeak_address))
|
||||
squeak_profile = SqueakProfile(
|
||||
profile_id=None,
|
||||
profile_name=profile_name,
|
||||
|
|
@ -219,7 +223,8 @@ class SqueakController:
|
|||
def make_squeak(self, profile_id, content_str, replyto_hash):
|
||||
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)
|
||||
squeak = squeak_maker.make_squeak(
|
||||
squeak_profile, content_str, replyto_hash)
|
||||
return self.save_created_squeak(squeak)
|
||||
|
||||
def get_squeak_entry_with_profile(self, squeak_hash):
|
||||
|
|
@ -243,7 +248,8 @@ class SqueakController:
|
|||
)
|
||||
|
||||
def delete_squeak(self, squeak_hash):
|
||||
num_deleted_offers = self.squeak_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)
|
||||
|
||||
|
|
@ -358,14 +364,16 @@ class SqueakController:
|
|||
logger.debug("Deleting 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))
|
||||
logger.info("Deleted number of offers: {}".format(
|
||||
num_expired_offers))
|
||||
|
||||
def delete_all_expired_sent_offers(self):
|
||||
logger.debug("Deleting expired sent offers.")
|
||||
num_expired_sent_offers = self.squeak_db.delete_expired_offers()
|
||||
if num_expired_sent_offers > 0:
|
||||
logger.info(
|
||||
"Deleted number of sent offers: {}".format(num_expired_sent_offers)
|
||||
"Deleted number of sent offers: {}".format(
|
||||
num_expired_sent_offers)
|
||||
)
|
||||
|
||||
def process_subscribed_invoices(self):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
# import logging
|
||||
|
||||
# logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# class SqueakExpiredOfferCleaner:
|
||||
# def __init__(self, squeak_controller):
|
||||
# self.squeak_controller = squeak_controller
|
||||
|
||||
# def delete_all_expired_offers(self):
|
||||
# self.squeak_controller.delete_all_expired_offers()
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ class SqueakMaker:
|
|||
signing_key_str = signing_profile.private_key.decode()
|
||||
signing_key = CSigningKey(signing_key_str)
|
||||
logger.info("Creating squeak with signing key: {}".format(signing_key))
|
||||
logger.info("Creating squeak with replyto_hash: {}".format(replyto_hash))
|
||||
logger.info(
|
||||
"Creating squeak with replyto_hash: {}".format(replyto_hash))
|
||||
block_info = self._get_latest_block_info()
|
||||
logger.info("Creating squeak with block_info: {}".format(block_info))
|
||||
block_height = block_info.block_height
|
||||
|
|
|
|||
|
|
@ -18,9 +18,12 @@ class SqueakStore:
|
|||
raise Exception("Squeak upload not allowed by whitelist.")
|
||||
|
||||
if not self.squeak_rate_limiter.should_rate_limit_allow(squeak):
|
||||
raise Exception("Excedeed allowed number of squeaks per block.")
|
||||
block_header_bytes = self.squeak_block_verifier.get_block_header(squeak)
|
||||
inserted_squeak_hash = self.squeak_db.insert_squeak(squeak, block_header_bytes)
|
||||
raise Exception(
|
||||
"Excedeed allowed number of squeaks per block.")
|
||||
block_header_bytes = self.squeak_block_verifier.get_block_header(
|
||||
squeak)
|
||||
inserted_squeak_hash = self.squeak_db.insert_squeak(
|
||||
squeak, block_header_bytes)
|
||||
return inserted_squeak_hash
|
||||
|
||||
def get_squeak(self, squeak_hash, clear_decryption_key=False):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
import logging
|
||||
|
||||
from squeaknode.node.network_sync import NetworkSync
|
||||
from squeaknode.node.network_task import (
|
||||
SingleSqueakNetworkSyncTask,
|
||||
TimelineNetworkSyncTask,
|
||||
)
|
||||
from squeaknode.node.network_task import SingleSqueakNetworkSyncTask
|
||||
from squeaknode.node.network_task import TimelineNetworkSyncTask
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -18,7 +16,8 @@ class SqueakSyncController:
|
|||
self.squeak_store = squeak_store
|
||||
self.squeak_db = squeak_db
|
||||
self.lightning_client = lightning_client
|
||||
self.network_sync = NetworkSync(squeak_store, squeak_db, lightning_client)
|
||||
self.network_sync = NetworkSync(
|
||||
squeak_store, squeak_db, lightning_client)
|
||||
|
||||
def sync_timeline(self):
|
||||
try:
|
||||
|
|
@ -38,7 +37,8 @@ class SqueakSyncController:
|
|||
max_block,
|
||||
)
|
||||
network_sync_result = dowload_timeline_task.sync(peers)
|
||||
logger.info("Upload network_sync_result: {}".format(network_sync_result))
|
||||
logger.info("Upload network_sync_result: {}".format(
|
||||
network_sync_result))
|
||||
return network_sync_result
|
||||
|
||||
def sync_single_squeak(self, squeak_hash, peers):
|
||||
|
|
@ -48,6 +48,7 @@ class SqueakSyncController:
|
|||
)
|
||||
network_sync_result = timeline_sync_task.sync(peers)
|
||||
logger.info(
|
||||
"Download single squeak network_sync_result: {}".format(network_sync_result)
|
||||
"Download single squeak network_sync_result: {}".format(
|
||||
network_sync_result)
|
||||
)
|
||||
return network_sync_result
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ class SqueakServerHandler(object):
|
|||
self.squeak_controller = squeak_controller
|
||||
|
||||
def handle_posted_squeak(self, squeak):
|
||||
logger.info("Handle posted squeak with hash: {}".format(get_hash(squeak)))
|
||||
logger.info(
|
||||
"Handle posted squeak with hash: {}".format(get_hash(squeak)))
|
||||
# Save the squeak
|
||||
self.squeak_controller.save_uploaded_squeak(squeak)
|
||||
|
||||
|
|
@ -31,11 +32,14 @@ class SqueakServerHandler(object):
|
|||
str(addresses), min_block, max_block
|
||||
)
|
||||
)
|
||||
hashes = self.squeak_controller.lookup_squeaks(addresses, min_block, max_block)
|
||||
hashes = self.squeak_controller.lookup_squeaks(
|
||||
addresses, min_block, max_block)
|
||||
logger.info("Got number of hashes from db: {}".format(len(hashes)))
|
||||
allowed_addresses = self.squeak_controller.lookup_allowed_addresses(addresses)
|
||||
allowed_addresses = self.squeak_controller.lookup_allowed_addresses(
|
||||
addresses)
|
||||
logger.info(
|
||||
"Got number of allowed addresses from db: {}".format(len(allowed_addresses))
|
||||
"Got number of allowed addresses from db: {}".format(
|
||||
len(allowed_addresses))
|
||||
)
|
||||
return squeak_server_pb2.LookupSqueaksReply(
|
||||
hashes=hashes,
|
||||
|
|
@ -48,5 +52,6 @@ class SqueakServerHandler(object):
|
|||
squeak_hash, client_addr
|
||||
)
|
||||
)
|
||||
buy_offer = self.squeak_controller.get_buy_offer(squeak_hash, client_addr)
|
||||
buy_offer = self.squeak_controller.get_buy_offer(
|
||||
squeak_hash, client_addr)
|
||||
return buy_offer
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ from concurrent import futures
|
|||
import grpc
|
||||
from squeak.core import CSqueak
|
||||
|
||||
from proto import squeak_server_pb2, squeak_server_pb2_grpc
|
||||
from proto import squeak_server_pb2
|
||||
from proto import squeak_server_pb2_grpc
|
||||
from squeaknode.core.util import get_hash
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import logging
|
||||
|
||||
from squeak.core import CheckSqueak, CheckSqueakError, CSqueak
|
||||
from squeak.core import CheckSqueak
|
||||
from squeak.core import CheckSqueakError
|
||||
from squeak.core import CSqueak
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import pytest
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from squeaknode.bitcoin.blockchain_client import BlockchainClient
|
||||
from squeaknode.core.lightning_address import LightningAddressHostPort
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import time
|
|||
|
||||
import pytest
|
||||
from bitcoin.core import lx
|
||||
from squeak.core import HASH_LENGTH, MakeSqueakFromStr
|
||||
from squeak.core import HASH_LENGTH
|
||||
from squeak.core import MakeSqueakFromStr
|
||||
from squeak.core.signing import CSigningKey
|
||||
|
||||
from squeaknode.server.squeak_validator import SqueakValidator
|
||||
|
|
@ -16,7 +17,8 @@ def make_squeak(
|
|||
signing_key: CSigningKey, content: str, reply_to: bytes = b"\x00" * HASH_LENGTH
|
||||
):
|
||||
block_height = 0
|
||||
block_hash = lx("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")
|
||||
block_hash = lx(
|
||||
"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")
|
||||
timestamp = int(time.time())
|
||||
return MakeSqueakFromStr(
|
||||
signing_key,
|
||||
|
|
|
|||
83
tox.ini
83
tox.ini
|
|
@ -5,83 +5,18 @@ skip_missing_interpreters =
|
|||
|
||||
[testenv]
|
||||
deps =
|
||||
pytest
|
||||
mock
|
||||
-rrequirements.txt
|
||||
passenv = MY_APP_CONFIG_FILE
|
||||
-rrequirements-dev.txt
|
||||
-rrequirements.txt
|
||||
commands =
|
||||
py.test {posargs:tests}
|
||||
|
||||
[testenv:coverage]
|
||||
deps =
|
||||
{[testenv]deps}
|
||||
coverage
|
||||
pytest
|
||||
commands = coverage run -m pytest {posargs:tests}
|
||||
|
||||
[testenv:mypy]
|
||||
deps =
|
||||
{[testenv]deps}
|
||||
mypy
|
||||
mypy_paths =
|
||||
squeaknode
|
||||
tests
|
||||
itests
|
||||
commands =
|
||||
mypy --ignore-missing-imports {posargs:{[testenv:mypy]mypy_paths}}
|
||||
|
||||
[testenv:codechecks]
|
||||
basepython = python3.8
|
||||
deps =
|
||||
flake8
|
||||
-rrequirements.txt
|
||||
codechecks_paths =
|
||||
squeaknode
|
||||
tests
|
||||
itests
|
||||
commands =
|
||||
flake8 {posargs:{[testenv:codechecks]codechecks_paths}}
|
||||
|
||||
[testenv:black]
|
||||
basepython = python3.8
|
||||
deps =
|
||||
black
|
||||
-rrequirements.txt
|
||||
black_paths =
|
||||
squeaknode
|
||||
tests
|
||||
itests
|
||||
commands =
|
||||
black {posargs:{[testenv:black]black_paths}}
|
||||
|
||||
[testenv:autopep8]
|
||||
basepython = python3.8
|
||||
deps =
|
||||
autopep8
|
||||
-rrequirements.txt
|
||||
commands =
|
||||
autopep8 --in-place --recursive --max-line-length=100 .
|
||||
|
||||
[testenv:autoflake]
|
||||
basepython = python3.8
|
||||
deps =
|
||||
autoflake
|
||||
-rrequirements.txt
|
||||
commands =
|
||||
autoflake --in-place --recursive --remove-all-unused-imports .
|
||||
|
||||
[testenv:isort]
|
||||
basepython = python3.8
|
||||
deps =
|
||||
isort
|
||||
-rrequirements.txt
|
||||
commands =
|
||||
isort .
|
||||
coverage erase
|
||||
coverage run -m pytest {posargs:tests}
|
||||
coverage report --show-missing
|
||||
coverage html
|
||||
pre-commit install -f --install-hooks
|
||||
pre-commit run --all-files
|
||||
# check-requirements
|
||||
|
||||
[testenv:setup]
|
||||
basepython = python3.8
|
||||
commands =
|
||||
{envbindir}/python setup.py build_proto_modules
|
||||
|
||||
[flake8]
|
||||
ignore = E501
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue