chore: format source using the pre_commit command

This commit is contained in:
fusion44 2022-03-20 17:20:56 +01:00
parent 20f60abaf3
commit 516550bd9f
No known key found for this signature in database
GPG key ID: 645FA807E935D9D5
33 changed files with 78 additions and 69 deletions

View file

@ -12,14 +12,14 @@ login_password=12345678
# enable_local_cookie_auth = false
# Platform tells the backend on what kind of system it is running on.
# Different platforms might use different data sources and might yield
# Different platforms might use different data sources and might yield
# different kinds of data. E.g.: If set to "raspiblitz",then hardware
# information will be fetched from Redis instead of the native python implementation.
# In case of native_python set other optional config vars np_* further below.
# supported values: [raspiblitz, native_python]
# platform=raspiblitz
# Amount of seconds the app will wait until it'll
# Amount of seconds the app will wait until it'll
# send another hardware update
# only applies when platform=native_python
gather_hw_info_interval = 2
@ -27,7 +27,7 @@ gather_hw_info_interval = 2
# Amount of seconds the app will gather CPU usage data for each update
# The resulting CPU usage is averaged over this period of time.
# To get realistic results at least 0.1 seconds is recommended
# must be less than and not equal to gather_hw_info_interval
# must be less than and not equal to gather_hw_info_interval
# only applies when platform=native_python
cpu_usage_averaging_period = 0.5
@ -43,7 +43,7 @@ shell_script_path = /home/admin
# default: false
# sse_notify_forward_successes=false
# If set to 0 all forward event will be sent instantly, otherwise they'll
# If set to 0 all forward event will be sent instantly, otherwise they'll
# be gathered and sent as an array of notifications.
# This also affects how often the wallet balance is updated (even if sse_notify_forward_successes is false)
# default: 2.0 seconds
@ -107,4 +107,4 @@ lnd_rest_port=8080
# np_ssh_address="username@192.168.1.50"
# Version of the platform. Ignored on platform Raspiblitz
# np_version="v0.5.0beta"
# np_version="v0.5.0beta"

3
.vscode/launch.json vendored
View file

@ -1,7 +1,4 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{

View file

@ -1,5 +1,5 @@
from fastapi import HTTPException, Request, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from .auth_handler import decodeJWT

View file

@ -1,9 +1,9 @@
# FastAPI Versioning
* Original: https://github.com/DeanWay/fastapi-versioning
* Original: https://github.com/DeanWay/fastapi-versioning
* Fork: https://github.com/fusion44/fastapi-versioning
TODO: Replace with original, once [this PR](https://github.com/DeanWay/fastapi-versioning/pull/59) is approved and released.
Background:
https://github.com/fusion44/blitz_api/issues/40
https://github.com/fusion44/blitz_api/issues/40

View file

@ -24,4 +24,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -22,7 +22,7 @@ from starlette.types import Receive, Scope, Send
class AppStatus:
""" helper for monkeypatching the signal-handler of uvicorn """
"""helper for monkeypatching the signal-handler of uvicorn"""
should_exit = False

View file

@ -1,5 +1,6 @@
from enum import Enum
from typing import List, Optional
from fastapi import Query
from pydantic.main import BaseModel

View file

@ -1,12 +1,13 @@
from enum import Enum
from typing import List, Optional, Union
import app.models.lightning_docs as docs
from deepdiff import DeepDiff
from fastapi.param_functions import Query
from pydantic import BaseModel
from pydantic.types import conint
import app.models.lightning_docs as docs
class OnchainAddressType(str, Enum):
P2WKH = "p2wkh"

View file

@ -1,5 +1,5 @@
tx_id_desc = """
Unique identifier for this transaction.
Unique identifier for this transaction.
Depending on the type of the transaction it will be different:
#### On-chain

View file

@ -1,14 +1,14 @@
from enum import Enum
from typing import List, Optional
from app.models.lightning import LnInfo
from app.routers.system_docs import get_debug_data_sample_str
from decouple import config
from fastapi import Query
from fastapi.param_functions import Query
from pydantic import BaseModel
from pydantic.types import constr
from app.routers.system_docs import get_debug_data_sample_str
class LoginInput(BaseModel):
password: constr(min_length=8)
@ -29,7 +29,7 @@ class HealthMessage(BaseModel):
id: int = Query(
None,
description="""ID of the message.
Idea behind the ID is that messages can be replacable on the client.
Idea behind the ID is that messages can be replacable on the client.
To prevent spamming the user with multiple messages, message with ID 25 will be replaced with never data of ID 25
""",
example="""
@ -44,7 +44,7 @@ To prevent spamming the user with multiple messages, message with ID 25 will be
level: HealthMessagePriority = Query(
HealthMessagePriority.INFO,
description="""Priority level of the message. For more info see `message`.
`INFO`: FYI, can normally be ignored.\n
`WARNING`: Potential problem might occur, user interaction possibly required.\n
`ERROR`: Something bad happened. User interaction definitely required.

View file

@ -5,12 +5,13 @@ import logging
import zmq
import zmq.asyncio
from app.models.bitcoind import BlockchainInfo, BtcInfo, FeeEstimationMode, NetworkInfo
from app.utils import SSE, bitcoin_config, bitcoin_rpc_async, send_sse_message
from fastapi import Request
from fastapi.exceptions import HTTPException
from starlette import status
from app.models.bitcoind import BlockchainInfo, BtcInfo, FeeEstimationMode, NetworkInfo
from app.utils import SSE, bitcoin_config, bitcoin_rpc_async, send_sse_message
async def get_blockchain_info() -> BlockchainInfo:
result = await bitcoin_rpc_async("getblockchaininfo")

View file

@ -1,7 +1,6 @@
import psutil
from decouple import config
SLEEP_TIME = config("gather_hw_info_interval", default=2, cast=float)
CPU_AVG_PERIOD = config("cpu_usage_averaging_period", default=0.5, cast=float)
HW_INFO_YIELD_TIME = SLEEP_TIME + CPU_AVG_PERIOD

View file

@ -1,6 +1,10 @@
import asyncio
from typing import List, Optional
import logging
from typing import List, Optional
from decouple import config
from fastapi import status
from fastapi.exceptions import HTTPException
from app.models.lightning import (
FeeRevenue,
@ -16,9 +20,6 @@ from app.models.lightning import (
SendCoinsResponse,
)
from app.utils import SSE, lightning_config, send_sse_message
from decouple import config
from fastapi import status
from fastapi.exceptions import HTTPException
if lightning_config.ln_node == "lnd":
from app.repositories.ln_impl.lnd import (
@ -181,7 +182,7 @@ Unable to connect to LND. Possible reasons:
* Node is not reachable (ports, network down, ...)
* Maccaroon is not correct
* IP is not included in LND tls certificate
Add tlsextraip=192.168.1.xxx to lnd.conf and restart LND.
Add tlsextraip=192.168.1.xxx to lnd.conf and restart LND.
This will recreate the TLS certificate. The .env must be adpted accordingly.
* TLS certificate is wrong. (settings changed, ...)

View file

@ -1,10 +1,13 @@
import asyncio
from typing import List, Optional
import grpc
from fastapi.exceptions import HTTPException
from starlette import status
import app.repositories.ln_impl.protos.lightning_pb2 as ln
import app.repositories.ln_impl.protos.router_pb2 as router
import app.repositories.ln_impl.protos.walletunlocker_pb2 as unlocker
import grpc
from app.models.lightning import (
FeeRevenue,
ForwardSuccessEvent,
@ -24,8 +27,6 @@ from app.models.lightning import (
from app.utils import SSE
from app.utils import lightning_config as lncfg
from app.utils import send_sse_message
from fastapi.exceptions import HTTPException
from starlette import status
def get_implementation_name() -> str:

View file

@ -2,11 +2,11 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: lightning.proto
"""Generated protocol buffer code."""
from google.protobuf.internal import enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import enum_type_wrapper
# @@protoc_insertion_point(imports)

View file

@ -2,13 +2,13 @@
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: router.proto
"""Generated protocol buffer code."""
import app.repositories.ln_impl.protos.lightning_pb2 as lightning__pb2
from google.protobuf.internal import enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
from google.protobuf.internal import enum_type_wrapper
import app.repositories.ln_impl.protos.lightning_pb2 as lightning__pb2
# @@protoc_insertion_point(imports)

View file

@ -1,7 +1,6 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import signer_pb2 as signer__pb2

View file

@ -14,7 +14,6 @@ _sym_db = _symbol_database.Default()
import app.repositories.ln_impl.protos.lightning_pb2 as lightning__pb2
DESCRIPTOR = _descriptor.FileDescriptor(
name="walletunlocker.proto",
package="lnrpc",

View file

@ -2,7 +2,6 @@
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import app.repositories.ln_impl.protos.walletunlocker_pb2 as walletunlocker__pb2

View file

@ -1,11 +1,12 @@
import asyncio
from os import path
from app.models.system import APIPlatform, RawDebugLogData, SystemInfo
from app.utils import SSE, send_sse_message
from decouple import config
from fastapi import HTTPException, Request, status
from app.models.system import APIPlatform, RawDebugLogData, SystemInfo
from app.utils import SSE, send_sse_message
PLATFORM = config("platform", default=APIPlatform.RASPIBLITZ)
if PLATFORM == APIPlatform.RASPIBLITZ:
from app.repositories.hardware_impl.raspiblitz import (

View file

@ -1,3 +1,5 @@
from decouple import config
from app.constants import API_VERSION
from app.models.system import (
APIPlatform,
@ -7,7 +9,6 @@ from app.models.system import (
SystemInfo,
)
from app.repositories.lightning import get_ln_info
from decouple import config
async def get_system_info_impl() -> SystemInfo:

View file

@ -1,9 +1,10 @@
from fastapi import APIRouter, HTTPException, status
from fastapi.params import Depends
import app.repositories.apps as repo
import app.routers.apps_docs as docs
from app.auth.auth_bearer import JWTBearer
from app.external.sse_startlette import EventSourceResponse
from fastapi import APIRouter, HTTPException, status
from fastapi.params import Depends
_PREFIX = "apps"

View file

@ -1,3 +1,6 @@
from fastapi import APIRouter, HTTPException, Request, status
from fastapi.params import Depends, Query
from app.auth.auth_bearer import JWTBearer
from app.external.sse_startlette import EventSourceResponse
from app.models.bitcoind import BlockchainInfo, BtcInfo, FeeEstimationMode, NetworkInfo
@ -10,8 +13,6 @@ from app.repositories.bitcoin import (
)
from app.routers.bitcoin_docs import blocks_sub_doc, estimate_fee_mode_desc
from app.utils import bitcoin_rpc
from fastapi import APIRouter, HTTPException, Request, status
from fastapi.params import Depends, Query
_PREFIX = "bitcoin"

View file

@ -1,5 +1,8 @@
from typing import List, Optional
from fastapi import APIRouter, HTTPException, Query, status
from fastapi.params import Depends
from app.auth.auth_bearer import JWTBearer
from app.models.lightning import (
FeeRevenue,
@ -38,8 +41,6 @@ from app.routers.lightning_docs import (
send_coins_desc,
send_payment_desc,
)
from fastapi import APIRouter, HTTPException, Query, status
from fastapi.params import Depends
_PREFIX = "lightning"
@ -93,8 +94,8 @@ async def getwalletbalance():
name=f"{_PREFIX}.get-fee-revenue",
summary="Returns the daily, weekly and monthly fee revenue earned.",
description="""
Currently, year and total fees are always null. Backends don't return these values by default.
Implementation in BlitzAPI is a [to-do](https://github.com/fusion44/blitz_api/issues/64).
Currently, year and total fees are always null. Backends don't return these values by default.
Implementation in BlitzAPI is a [to-do](https://github.com/fusion44/blitz_api/issues/64).
""",
dependencies=[Depends(JWTBearer())],
response_model=FeeRevenue,
@ -113,7 +114,7 @@ async def get_fee_revenue_path() -> FeeRevenue:
"/list-all-tx",
name=f"{_PREFIX}.list-all-tx",
summary="Lists all on-chain transactions, payments and invoices in the wallet",
description="""Returns a list with all on-chain transaction, payments and invoices combined into one list.
description="""Returns a list with all on-chain transaction, payments and invoices combined into one list.
The index of each tx is only valid for each identical set of parameters.
""",
dependencies=[Depends(JWTBearer())],

View file

@ -1,6 +1,6 @@
get_balance_response_desc = """
A JSON String with on chain wallet balances with on-chain balances in
**sat** and channel balances in **msat**. Detailed description is in
A JSON String with on chain wallet balances with on-chain balances in
**sat** and channel balances in **msat**. Detailed description is in
the schema"""
new_address_desc = """
@ -10,16 +10,16 @@ Generate a wallet new address. Address-types has to be one of:
"""
send_coins_desc = """
__send-coins__ executes a request to send coins to a particular address.
__send-coins__ executes a request to send coins to a particular address.
### LND:
### LND:
If neither __target_conf__, or __sat_per_vbyte__ are set, then the internal wallet will consult its fee model to determine a fee for the default confirmation target.
> 👉 See [https://api.lightning.community/?shell#sendcoins](https://api.lightning.community/?shell#sendcoins)
### c-lightning:
### c-lightning:
* Set __target_conf__ ==1: interpreted as urgent (aim for next block)
* Set __target_conf__ >=2: interpreted as normal (next 4 blocks or so, **default**)
* Set __target_conf__ >=2: interpreted as normal (next 4 blocks or so, **default**)
* Set __target_cont__ >=10: interpreted as slow (next 100 blocks or so)
* If __sat_per_vbyte__ is set then __target_conf__ is ignored and vbytes (sipabytes) will be used.

View file

@ -2,13 +2,14 @@ import asyncio
import logging
from aioredis import Redis
from app.auth.auth_bearer import JWTBearer
from app.auth.auth_handler import signJWT
from app.utils import redis_get
from fastapi import APIRouter, HTTPException, status
from fastapi.params import Depends
from fastapi_plugins import depends_redis
from app.auth.auth_bearer import JWTBearer
from app.auth.auth_handler import signJWT
from app.utils import redis_get
router = APIRouter(prefix="/setup", tags=["Setup"])
# can always be called without credentials to check if

View file

@ -1,5 +1,9 @@
import secrets
from decouple import config
from fastapi import APIRouter, HTTPException, Request, status
from fastapi.params import Depends
from app.auth.auth_bearer import JWTBearer
from app.auth.auth_handler import signJWT
from app.external.sse_startlette import EventSourceResponse
@ -17,9 +21,6 @@ from app.routers.system_docs import (
get_debug_logs_raw_summary,
get_hw_info_json,
)
from decouple import config
from fastapi import APIRouter, HTTPException, Request, status
from fastapi.params import Depends
_PREFIX = "system"

View file

@ -81,7 +81,7 @@ get_hw_info_json = """
get_debug_data_sample_str = """
***************************************************************
* RASPIBLITZ DEBUG LOGS
* RASPIBLITZ DEBUG LOGS
***************************************************************
blitzversion: 1.7.0
chainnetwork: bitcoin / main
@ -371,8 +371,8 @@ use the following command and share the resulting link:
get_debug_logs_raw_summary = "Get raw system logs as a text string."
get_debug_logs_raw_desc = """
This endpoint will gather latest system logs and return it in a
raw string. This endpoint will **not** return immediately because
This endpoint will gather latest system logs and return it in a
raw string. This endpoint will **not** return immediately because
it gathers all data on time of the request.
"""

View file

@ -17,7 +17,7 @@ if [ ${sshpassInstalled} -eq 0 ]; then
echo "FAIL: please make sure that sshpass is installed on your system"
echo "macOS: brew install hudochenkov/sshpass/sshpass"
echo "Linux(Debian): apt install sshpass"
exit
exit
fi
# check if ping is installed
@ -25,7 +25,7 @@ pingInstalled=$(ping -V | grep -c "ping")
if [ ${pingInstalled} -eq 0 ]; then
echo "FAIL: please make sure that ping is installed on your system"
echo "Linux(Debian): apt install inetutils-ping OR apt install iputils-ping"
exit
exit
fi
# check if localIP is available&responding

View file

@ -1,6 +1,7 @@
from starlette.testclient import TestClient
from app.models.lightning import LightningInfoLite
from app.routers import lightning
from starlette.testclient import TestClient
from tests.routers.utils import call_route
from tests.utils import monkeypatch_auth

View file

@ -1,4 +1,5 @@
from starlette.testclient import TestClient
from tests.routers.utils import call_route

View file

@ -1,7 +1,8 @@
import pytest
from app.main import app
from starlette.testclient import TestClient
from app.main import app
@pytest.fixture(scope="module")
def test_client():

View file

@ -1,6 +1,7 @@
from app.auth.auth_bearer import JWTBearer
from fastapi.security import HTTPAuthorizationCredentials
from app.auth.auth_bearer import JWTBearer
def monkeypatch_auth(monkeypatch):
async def fake__call__(self, request):