Skip to content

Commit

Permalink
pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rilesdun committed Sep 17, 2023
1 parent e45d4ef commit 36a49c6
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 64 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/python-app.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ __pycache__/
# C extensions
*.so

#vscode
.vscode/

# npm packages
node_modules/

Expand Down
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from src.blocks import get_block_info

from src.get_latest_transactions import get_latest_transactions
from src.latestBlock import get_latest_block
from src.latest_block import get_latest_block

from src.supply.supply_details import get_supply_details
from src.supply.max_supply import max_supply
Expand All @@ -34,7 +34,7 @@

CORS(app, resources={r"/*": {"origins": "*"}})
cache.init_app(app)
logging.basicConfig(level=logging.INFO,
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - '
'%(levelname)s - %(message)s')
@app.route('/api/latest_block_num', methods=['GET'])
Expand Down
5 changes: 4 additions & 1 deletion cache_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Cache configuration for the application.
"""
from flask_caching import Cache

cache = Cache(config={'CACHE_TYPE': 'simple'})
cache = Cache(config={'CACHE_TYPE': 'simple'})
9 changes: 6 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# config.py
from dotenv import load_dotenv
"""
Function for loading .env files
"""

import os
from dotenv import load_dotenv

load_dotenv()
api_url = os.getenv("API_URL")
print(api_url) # Add this line
print(api_url)
10 changes: 7 additions & 3 deletions gunicorn_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
"""
Gunicorn config file
"""

import multiprocessing

bind = "0.0.0.0:5000"
worker_class = 'eventlet'
workers = multiprocessing.cpu_count() * 2 + 1
bind = "0.0.0.0:5000" # pylint: disable=invalid-name
worker_class = 'eventlet' # pylint: disable=invalid-name
workers = multiprocessing.cpu_count() * 2 + 1
7 changes: 4 additions & 3 deletions src/accounts/account_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

peerplays = PeerPlays(api_url)

"""
retrieve account history
"""

def get_account_history(account_name):
"""
retrieve account history
"""
account = Account(account_name, blockchain_instance=peerplays)

account_history = list(account.history())
Expand Down
6 changes: 6 additions & 0 deletions src/accounts/get_account.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"""
This module contains the function to get account information.
"""
from peerplays.account import Account
from peerplays import PeerPlays
from config import api_url

peerplays = PeerPlays(api_url)

def get_account_info(account_name):
"""
This function returns the account information for the given account name.
"""
account = Account(account_name, blockchain_instance=peerplays)
account_info = {
"id": account["id"],
Expand Down
2 changes: 1 addition & 1 deletion src/accounts/sons/active_sons.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_active_sons():
account_name = account_info["name"]
obj["son_account"] = account_name
results.append(obj)
son_count += 1
son_count += 1
object_id_number += 1
except Exception as error:
print(f"Error fetching object {object_id}: {error}", file=sys.stderr)
Expand Down
11 changes: 10 additions & 1 deletion src/get_latest_transactions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"""
This module is used to get the latest transactions from the Peerplays blockchain.
"""
from peerplays import PeerPlays
from peerplays.block import Block
from config import api_url

peerplays = PeerPlays(api_url)

def get_block_with_transactions(block_num):
"""
This function returns the block information for the given block number.
"""
block = Block(block_num, blockchain_instance=peerplays)
if block["transactions"]:
return {
Expand All @@ -14,6 +20,9 @@ def get_block_with_transactions(block_num):
return None

def get_latest_transactions(num_transactions=10):
"""
This function returns the latest transactions.
"""
latest_block_num = peerplays.info()["head_block_number"]
transactions = []

Expand All @@ -25,4 +34,4 @@ def get_latest_transactions(num_transactions=10):
if len(transactions) >= num_transactions:
return transactions[:num_transactions]

return transactions
return transactions
11 changes: 8 additions & 3 deletions src/latestBlock.py → src/latest_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
This file contains the function to get the latest block from the PeerPlays blockchain.
"""
from peerplays.blockchain import Blockchain
from peerplays import PeerPlays

Expand All @@ -6,12 +9,14 @@
peerplays = PeerPlays(api_url)

def get_latest_block():
"""
This function returns the latest block from the PeerPlays blockchain.
"""
chain = Blockchain(blockchain_instance=peerplays)

# Get the latest block
latest_block = None
for block in chain.blocks():
latest_block = block
break
break

return latest_block
return latest_block
11 changes: 9 additions & 2 deletions src/supply/circulating_supply.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from .common import get_supplies, peerplays, ASSET_IDS
"""
Circulating supply endpoint
"""
from peerplays.asset import Asset
from flask import Response
from src.supply.common import get_supplies, peerplays, ASSET_IDS


def circulating_supply(coin_name):
"""
This endpoint returns the circulating supply for the given coin name.
"""
asset_id = ASSET_IDS.get(coin_name)
if asset_id is None:
return Response("Invalid coin name", status=400)
A = Asset(asset_id, blockchain_instance=peerplays)
supply = get_supplies(A)["circulating"]
return Response(supply, content_type='text/plain')
return Response(supply, content_type='text/plain')
15 changes: 11 additions & 4 deletions src/supply/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Common functions for supply endpoints
"""
from peerplays.peerplays import PeerPlays
from peerplays.asset import Asset
from peerplays.amount import Amount
from config import api_url

peerplays = PeerPlays(api_url)
Expand All @@ -14,10 +15,16 @@
}

def sats_to_fixed(amount, P):
"""
Convert an amount in satoshis to a fixed point number
"""
V = int(amount) / 10**P
return "{:.{prec}f}".format(V, prec=P)
return f"{V:.{P}f}"

def get_supplies(asset):
"""
Get the supply details for an asset
"""
P = asset["precision"]
max_supply = sats_to_fixed(asset["options"]["max_supply"], P)
ddo = asset.blockchain.rpc.get_objects([asset["dynamic_asset_data_id"]])[0]
Expand All @@ -28,4 +35,4 @@ def get_supplies(asset):
"maximum": max_supply,
"total": max_supply,
"circulating": current_supply
}
}
9 changes: 8 additions & 1 deletion src/supply/max_supply.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from .common import get_supplies, peerplays, ASSET_IDS
"""
This module contains the max_supply function, which returns the maximum supply of a coin.
"""
from peerplays.asset import Asset
from flask import Response
from src.supply.common import get_supplies, peerplays, ASSET_IDS


ASSET_IDS = {
"ppy": "1.3.0",
Expand All @@ -12,6 +16,9 @@
}

def max_supply(coin_name):
"""
This endpoint returns the maximum supply for the given coin name.
"""
asset_id = ASSET_IDS.get(coin_name)
if asset_id is None:
return Response("Invalid coin name", status=400)
Expand Down
3 changes: 3 additions & 0 deletions src/supply/rich_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Rich list for a given coin
"""
from peerplays.asset import Asset
from flask import jsonify
from src.supply.common import sats_to_fixed, peerplays, ASSET_IDS
Expand Down
6 changes: 6 additions & 0 deletions src/supply/supply_details.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"""
This module is used to get the supply details of the asset.
"""
from peerplays.asset import Asset
from peerplays import PeerPlays
from src.supply.common import get_supplies


def get_supply_details(asset_id="1.3.0"):
"""
returns the supply details of the asset
"""
peerplays = PeerPlays("wss://ca.peerplays.info/api")
A = Asset(asset_id, blockchain_instance=peerplays)
supplies = get_supplies(A)
Expand Down
9 changes: 8 additions & 1 deletion src/supply/total_supply.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from .common import get_supplies, peerplays, ASSET_IDS
"""
This module contains the total supply endpoint.
"""
from peerplays.asset import Asset
from flask import Response
from src.supply.common import get_supplies, peerplays, ASSET_IDS


def total_supply(coin_name):
"""
This endpoint returns the total supply for the given coin name.
"""
asset_id = ASSET_IDS.get(coin_name)
if asset_id is None:
return Response("Invalid coin name", status=400)
Expand Down

0 comments on commit 36a49c6

Please sign in to comment.