35 lines
857 B
Python
35 lines
857 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
|
||
|
|
def resolve_account(
|
||
|
|
accounts: dict[str, Any],
|
||
|
|
account_id: str | None = None,
|
||
|
|
sender_address: str | None = None,
|
||
|
|
) -> dict[str, Any] | None:
|
||
|
|
if account_id and account_id in accounts:
|
||
|
|
return accounts[account_id]
|
||
|
|
|
||
|
|
if not accounts:
|
||
|
|
return None
|
||
|
|
|
||
|
|
if "default" in accounts:
|
||
|
|
return accounts["default"]
|
||
|
|
|
||
|
|
first_key = next(iter(accounts))
|
||
|
|
return accounts[first_key]
|
||
|
|
|
||
|
|
|
||
|
|
def resolve_account_for_handle(
|
||
|
|
accounts: dict[str, Any],
|
||
|
|
handle: str,
|
||
|
|
) -> dict[str, Any] | None:
|
||
|
|
for acc_id, acc_config in accounts.items():
|
||
|
|
if not isinstance(acc_config, dict):
|
||
|
|
continue
|
||
|
|
mapping = acc_config.get("handle_mapping", {})
|
||
|
|
if isinstance(mapping, dict) and handle in mapping:
|
||
|
|
return acc_config
|
||
|
|
return None
|