Skip to content

Commit

Permalink
update: ledger module
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaDiazCorreia committed Dec 6, 2023
1 parent 8694101 commit 7462ff8
Show file tree
Hide file tree
Showing 17 changed files with 363 additions and 327 deletions.
7 changes: 5 additions & 2 deletions pages/wallet-provider/_meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"index": "Intro",
"architecture": "Architecture",
"getting-started": "Getting started",
"nostr": "NOSTR Event Anatomy",
"api-gateway": "API Gateway",
"flows": "Flows"
"architecture": "Architecture",
"flows": "Flows",
"ledger": "Ledger",
"extensions": "Extensions"
}
1 change: 1 addition & 0 deletions pages/wallet-provider/ledger/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"index" : "Intro",
"api": "API",
"models": "Models",
"events": "Events"
Expand Down
125 changes: 0 additions & 125 deletions pages/wallet-provider/ledger/api/account/create.mdx

This file was deleted.

5 changes: 5 additions & 0 deletions pages/wallet-provider/ledger/events/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"inbound-transaction": "Inbound Transaction",
"internal-transaction": "Internal Transaction",
"outbound-transaction": "Outbound Transaction"
}
68 changes: 68 additions & 0 deletions pages/wallet-provider/ledger/events/inbound-transaction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 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

1. Validates the author of the transaction.
2. Initiates the transaction in the database.
3. Manages balances for the receiver's account.
4. Publishes corresponding success or error events.

#### Retries

- The handler supports a limited number of retries in case of failures.

## Usage Example

```typescript
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);
68 changes: 68 additions & 0 deletions pages/wallet-provider/ledger/events/internal-transaction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Internal Transaction Handler

Handles internal transactions.

## Overview

This module provides the functionality to handle and process internal transactions initiated by users.

## 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 internal transactions.

## Functions

### `getHandler(ctx: Context, ntry: number): (nostrEvent: NostrEvent) => void`

Returns the internal 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 internal transactions and initiates the necessary processes.

### Handler Function

#### Parameters

- `nostrEvent`: The internal transaction Nostr event.

#### Functionality

1. Validates the sender's balance for each token.
2. Initiates the transaction in the database.
3. Manages balances for the sender's and receiver's accounts.
4. Publishes corresponding success or error events.

#### Retries

- The handler supports a limited number of retries in case of failures.

## Usage Example

```typescript
import { filter, getHandler } from '@path/to/internalTransactions';

// Create a context (ctx) with necessary dependencies

const internalTransactionHandler = getHandler(ctx, 0);

// Subscribe to relevant Nostr events
subscribeToNostrEvents(filter, internalTransactionHandler);
84 changes: 0 additions & 84 deletions pages/wallet-provider/ledger/events/internal-transfer.md

This file was deleted.

Loading

0 comments on commit 7462ff8

Please sign in to comment.