feat: add withdraw
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from src.presentation.messaging.crypto_transfer import crypto_transfer_router
|
||||
from src.presentation.messaging.sbp_withdrawal import sbp_withdrawal_messaging_router
|
||||
|
||||
|
||||
__all__=['crypto_transfer_router']
|
||||
__all__=['crypto_transfer_router','sbp_withdrawal_messaging_router']
|
||||
|
||||
|
||||
55
src/presentation/messaging/sbp_withdrawal.py
Normal file
55
src/presentation/messaging/sbp_withdrawal.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from fastapi import Depends
|
||||
from faststream.rabbit import RabbitQueue
|
||||
from faststream.rabbit.fastapi import RabbitMessage,RabbitRouter
|
||||
from decimal import Decimal
|
||||
from pydantic import BaseModel
|
||||
from src.application.commands import HandleSbpWithdrawalWalletEventCommand
|
||||
from src.application.contracts import ILogger
|
||||
from src.infrastructure.config import settings
|
||||
from src.infrastructure.context_vars import trace_id_var
|
||||
from src.presentation.dependencies.commands import get_sbp_withdrawal_wallet_event_command
|
||||
from src.presentation.dependencies.logger import get_logger
|
||||
|
||||
|
||||
sbp_withdrawal_messaging_router=RabbitRouter(settings.RABBIT_URL)
|
||||
|
||||
|
||||
class SbpWithdrawalWalletEventMessage(BaseModel):
|
||||
user_id: str
|
||||
withdraw_id: str
|
||||
event_type: str
|
||||
trace_id: str | None = None
|
||||
received_usdt_amount: Decimal | None = None
|
||||
tx_hash: str | None = None
|
||||
error: str | None = None
|
||||
|
||||
|
||||
@sbp_withdrawal_messaging_router.subscriber(RabbitQueue(settings.RABBIT_SBP_WITHDRAWAL_WALLET_EVENTS_QUEUE,durable=True))
|
||||
async def sbp_withdrawal_wallet_event_handler(
|
||||
msg_body: SbpWithdrawalWalletEventMessage,
|
||||
message: RabbitMessage,
|
||||
command: HandleSbpWithdrawalWalletEventCommand = Depends(get_sbp_withdrawal_wallet_event_command),
|
||||
logger: ILogger = Depends(get_logger),
|
||||
) -> None:
|
||||
headers=message.headers or {}
|
||||
trace_id=msg_body.trace_id or message.correlation_id or str(headers.get('trace_id') or '')
|
||||
token=trace_id_var.set(trace_id)
|
||||
try:
|
||||
logger.info({
|
||||
'event':'sbp_withdrawal_wallet_event_received',
|
||||
'withdraw_id':msg_body.withdraw_id,
|
||||
'user_id':msg_body.user_id,
|
||||
'wallet_event_type':msg_body.event_type,
|
||||
'rabbit_message_id':message.message_id,
|
||||
'rabbit_correlation_id':message.correlation_id,
|
||||
})
|
||||
await command(
|
||||
withdraw_id=msg_body.withdraw_id,
|
||||
user_id=msg_body.user_id,
|
||||
event_type=msg_body.event_type,
|
||||
received_usdt_amount=msg_body.received_usdt_amount,
|
||||
tx_hash=msg_body.tx_hash,
|
||||
error=msg_body.error,
|
||||
)
|
||||
finally:
|
||||
trace_id_var.reset(token)
|
||||
Reference in New Issue
Block a user