Skip to content

Commit 22d1a4b

Browse files
Refactor route handlers for improved readability
Update function signatures in block, mining, transaction, and wallet routes to enhance code clarity. This includes formatting changes for better alignment and consistency across the API route definitions.
1 parent 7191a5a commit 22d1a4b

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

api/routes/block_routes.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ async def get_latest_block(request: Request, blockchain: Blockchain = Depends(ge
3636

3737
@blockRouter.get("/blocks/{block_hash}")
3838
@limiter.limit("10/minute")
39-
async def get_block(request: Request, block_hash: str, blockchain: Blockchain = Depends(get_blockchain)):
39+
async def get_block(
40+
request: Request, block_hash: str, blockchain: Blockchain = Depends(get_blockchain)
41+
):
4042
"""Get a specific block by its hash"""
4143
try:
4244
for block in blockchain.chain:

api/routes/mining_routes.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ class MiningRequest(BaseModel):
1313

1414
@miningRouter.post("/mine")
1515
@limiter.limit("5/minute") # Strict limit for mining operations
16-
async def mine_block(request: Request, mining_request: MiningRequest, blockchain: Blockchain = Depends(get_blockchain)):
16+
async def mine_block(
17+
request: Request,
18+
mining_request: MiningRequest,
19+
blockchain: Blockchain = Depends(get_blockchain),
20+
):
1721
try:
1822
blockchain.mine_pending_transactions(mining_request.miner_address)
1923
return {"message": "Block mined successfully"}

api/routes/transaction_routes.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ async def get_all_transactions(request: Request, blockchain: Blockchain = Depend
3434
async def create_transaction(
3535
request: Request,
3636
tx_request: CreateTransactionRequest,
37-
blockchain: Blockchain = Depends(get_blockchain)
37+
blockchain: Blockchain = Depends(get_blockchain),
3838
):
3939
try:
4040
transaction = Transaction(
41-
tx_request.sender_address,
42-
tx_request.recipient_address,
43-
tx_request.amount
41+
tx_request.sender_address, tx_request.recipient_address, tx_request.amount
4442
)
4543
transaction.sign_transaction(tx_request.sender_private_key)
4644
blockchain.add_pending_transaction(transaction)

api/routes/wallet_routes.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ def get_wallet_manager():
2222
@walletRouter.post("/wallets")
2323
@limiter.limit("20/minute")
2424
async def create_wallet(
25-
request: Request, wallet_data: WalletCreate, wallet_manager: Wallet = Depends(get_wallet_manager)
25+
request: Request,
26+
wallet_data: WalletCreate,
27+
wallet_manager: Wallet = Depends(get_wallet_manager),
2628
):
2729
try:
2830
wallet = wallet_manager.create_wallet(wallet_data.passphrase)

0 commit comments

Comments
 (0)