Inbound Transaction Handler
Handles inbound transactions, specifically those initiated by users.
Overview
This module provides the functionality to handle and process inbound transactions on the Nostr platform.
Dependencies
@nostr-dev-kit/ndk
: Provides necessary types and filters for Nostr events.@lib/events
: Event-related constants and functions.@lib/transactions
: Transaction-related utilities and handlers.@lib/utils
: General utility functions.@prisma/client
: Prisma ORM client for database interactions.
Constants
REPUBLISH_INTERVAL_MS
: Interval for republishing balance events.MAX_RETRIES
: Maximum number of retries for handling a transaction.
Filter
filter
: The filter used to select relevant inbound transactions.
Functions
getHandler(ctx: Context, ntry: number): (nostrEvent: NostrEvent) => void
Returns the inbound transaction handler function.
Parameters
ctx
: The context containing necessary information for transaction handling.ntry
: The number of retries for handling the transaction.
Returns
A function that handles inbound transactions and initiates the necessary processes.
Handler Function
Parameters
nostrEvent
: The inbound transaction Nostr event.
Functionality
- Validates the author of the transaction.
- Initiates the transaction in the database.
- Manages balances for the receiver's account.
- Publishes corresponding success or error events.
Retries
- The handler supports a limited number of retries in case of failures.
Usage Example
import { filter, getHandler } from '@path/to/inboundTransaction';
// Create a context (ctx) with necessary dependencies
const inboundTransactionHandler = getHandler(ctx, 0);
// Subscribe to relevant Nostr events
subscribeToNostrEvents(filter, inboundTransactionHandler);