Skip to content

Commit 3d541d6

Browse files
committed
chore: fix ruff lint errors
1 parent 833750e commit 3d541d6

File tree

1 file changed

+73
-82
lines changed

1 file changed

+73
-82
lines changed

app/api/nft/routes.py

Lines changed: 73 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,6 @@ async def _transform_solana_asset_to_simplehash(asset: SolanaAsset) -> SimpleHas
198198
description = description or raw_content_data.description
199199
image_url = image_url or raw_content_data.image
200200

201-
cg_nft = next(
202-
(
203-
nft
204-
for nft in cg_nfts
205-
if nft["chain_id"] == ChainId.SOLANA and nft["contract_address"] == asset.id
206-
),
207-
None,
208-
)
209-
210201
return SimpleHashNFT(
211202
chain=SimpleHashChain.SOLANA,
212203
contract_address=asset.id,
@@ -331,78 +322,6 @@ async def get_nfts_by_owner(
331322
return SimpleHashNFTResponse(next_cursor=next_page_key, nfts=nfts)
332323

333324

334-
@router.get("/v1/getSolanaAssetProof", response_model=SolanaAssetMerkleProof)
335-
async def get_solana_asset_proof(
336-
token_address: str = Query(
337-
..., description="The token address to fetch the proof for"
338-
),
339-
) -> SolanaAssetMerkleProof:
340-
async with httpx.AsyncClient() as client:
341-
url = f"https://solana-mainnet.g.alchemy.com/v2/{settings.ALCHEMY_API_KEY}"
342-
params = {
343-
"jsonrpc": "2.0",
344-
"method": "getAssetProof",
345-
"params": [token_address],
346-
"id": 1,
347-
}
348-
response = await client.post(url, json=params)
349-
response.raise_for_status()
350-
json_response = response.json()
351-
if "error" in json_response:
352-
raise ValueError(f"Alchemy API error: {json_response['error']}")
353-
return SolanaAssetMerkleProof.model_validate(json_response["result"])
354-
355-
356-
@simplehash_router.get("/nfts/owners", response_model=SimpleHashNFTResponse)
357-
async def get_nfts_by_owner(
358-
wallet_addresses: list[str] = Query(
359-
..., description="The wallet addresses to fetch NFTs for"
360-
),
361-
chains: list[str] | None = Query(
362-
..., description="List of chains to fetch NFTs from"
363-
),
364-
cursor: str | None = Query(None, description="Cursor for pagination"),
365-
) -> SimpleHashNFTResponse:
366-
# Filter chains to only include valid chain IDs
367-
filtered_chains = (
368-
[
369-
SimpleHashChain(chain)
370-
for chain_raw in chains
371-
for chain in chain_raw.split(",")
372-
if chain in SimpleHashChain
373-
]
374-
if chains
375-
else list(SimpleHashChain)
376-
)
377-
378-
params = httpx.QueryParams(
379-
wallet_address=wallet_addresses[0],
380-
chain_ids=[_simplehash_chain_to_chain_id(chain) for chain in filtered_chains],
381-
)
382-
383-
if cursor:
384-
params = params.set("page_key", cursor)
385-
386-
return RedirectResponse(
387-
url=router.url_path_for("get_nfts_by_owner") + f"?{params}", status_code=307
388-
)
389-
390-
391-
@simplehash_router.get(
392-
"/nfts/proof/solana/{token_address}", response_model=SolanaAssetMerkleProof
393-
)
394-
async def get_compressed_nft_proof(
395-
token_address: str = Path(
396-
..., description="The token address to fetch the proof for"
397-
),
398-
) -> SolanaAssetMerkleProof:
399-
return RedirectResponse(
400-
url=router.url_path_for("get_solana_asset_proof")
401-
+ f"?token_address={token_address}",
402-
status_code=307,
403-
)
404-
405-
406325
@router.get("/v1/getNFTsByIds", response_model=SimpleHashNFTResponse)
407326
async def get_nfts_by_ids(
408327
ids: str = Query(
@@ -497,8 +416,80 @@ async def get_nfts_by_ids(
497416
return SimpleHashNFTResponse(next_cursor=None, nfts=nfts)
498417

499418

419+
@router.get("/v1/getSolanaAssetProof", response_model=SolanaAssetMerkleProof)
420+
async def get_solana_asset_proof(
421+
token_address: str = Query(
422+
..., description="The token address to fetch the proof for"
423+
),
424+
) -> SolanaAssetMerkleProof:
425+
async with httpx.AsyncClient() as client:
426+
url = f"https://solana-mainnet.g.alchemy.com/v2/{settings.ALCHEMY_API_KEY}"
427+
params = {
428+
"jsonrpc": "2.0",
429+
"method": "getAssetProof",
430+
"params": [token_address],
431+
"id": 1,
432+
}
433+
response = await client.post(url, json=params)
434+
response.raise_for_status()
435+
json_response = response.json()
436+
if "error" in json_response:
437+
raise ValueError(f"Alchemy API error: {json_response['error']}")
438+
return SolanaAssetMerkleProof.model_validate(json_response["result"])
439+
440+
441+
@simplehash_router.get("/nfts/owners", response_model=SimpleHashNFTResponse)
442+
async def get_simplehash_nfts_by_owner(
443+
wallet_addresses: list[str] = Query(
444+
..., description="The wallet addresses to fetch NFTs for"
445+
),
446+
chains: list[str] | None = Query(
447+
..., description="List of chains to fetch NFTs from"
448+
),
449+
cursor: str | None = Query(None, description="Cursor for pagination"),
450+
) -> SimpleHashNFTResponse:
451+
# Filter chains to only include valid chain IDs
452+
filtered_chains = (
453+
[
454+
SimpleHashChain(chain)
455+
for chain_raw in chains
456+
for chain in chain_raw.split(",")
457+
if chain in SimpleHashChain
458+
]
459+
if chains
460+
else list(SimpleHashChain)
461+
)
462+
463+
params = httpx.QueryParams(
464+
wallet_address=wallet_addresses[0],
465+
chain_ids=[_simplehash_chain_to_chain_id(chain) for chain in filtered_chains],
466+
)
467+
468+
if cursor:
469+
params = params.set("page_key", cursor)
470+
471+
return RedirectResponse(
472+
url=router.url_path_for("get_nfts_by_owner") + f"?{params}", status_code=307
473+
)
474+
475+
476+
@simplehash_router.get(
477+
"/nfts/proof/solana/{token_address}", response_model=SolanaAssetMerkleProof
478+
)
479+
async def get_simplehash_compressed_nft_proof(
480+
token_address: str = Path(
481+
..., description="The token address to fetch the proof for"
482+
),
483+
) -> SolanaAssetMerkleProof:
484+
return RedirectResponse(
485+
url=router.url_path_for("get_solana_asset_proof")
486+
+ f"?token_address={token_address}",
487+
status_code=307,
488+
)
489+
490+
500491
@simplehash_router.get("/nfts/assets", response_model=SimpleHashNFTResponse)
501-
async def get_nfts_by_ids(
492+
async def get_simplehash_nfts_by_ids(
502493
nft_ids: str = Query(
503494
...,
504495
description="Comma separated list of NFT IDs in format <chain>.<address> for Solana or <chain>.<address>.<token_id> for EVM chains",

0 commit comments

Comments
 (0)