Categorygithub.com/adonese/ledger
modulepackage
1.200.100
Repository: https://github.com/adonese/ledger.git
Documentation: pkg.go.dev

# README

API Documentation for Ledger Package

Overview

The ledger package is designed to manage user balances and transactions within a ledger system. It uses AWS DynamoDB for storage and integrates with AWS SES for email notifications.

Use the package

You can import the package directly, go get github.com/adonese/ledger@latest

Authentication

To use the API, authenticate with AWS by initializing a DynamoDB client using InitializeLedger.

InitializeLedger

func InitializeLedger(accessKey, secretKey, region string) (*dynamodb.Client, error)

Parameters:

  • accessKey: AWS access key.
  • secretKey: AWS secret key.
  • region: AWS region.

Returns:

  • *dynamodb.Client: A client for interacting with AWS DynamoDB.
  • error: Error message, if any.

User Balance

CheckUsersExist

func CheckUsersExist(dbSvc *dynamodb.Client, accountIds []string) ([]string, error)

Purpose: Checks if users exist in the DynamoDB table.

Parameters:

  • dbSvc: DynamoDB client.
  • accountIds: List of user account IDs.

Returns:

  • []string: List of account IDs that do not exist.
  • error: Error message if the operation fails.

CreateAccountWithBalance

func CreateAccountWithBalance(dbSvc *dynamodb.Client, accountId string, amount float64) error

Purpose: Creates a new account with an initial balance.

Parameters:

  • dbSvc: DynamoDB client.
  • accountId: The unique identifier for the account.
  • amount: Initial amount to be set for the account.

Returns:

  • error: Error message if the operation fails.

InquireBalance

func InquireBalance(dbSvc *dynamodb.Client, AccountID string) (float64, error)

Purpose: Inquires about the balance of a user's account.

Parameters:

  • dbSvc: DynamoDB client.
  • AccountID: The unique identifier for the account.

Returns:

  • float64: The current balance of the account.
  • error: Error message if the operation fails.

Transactions

TransferCredits

func TransferCredits(dbSvc *dynamodb.Client, fromAccountID, toAccountID string, amount float64) error

Purpose: Transfers credits from one account to another.

Parameters:

  • dbSvc: DynamoDB client.
  • fromAccountID: The account ID to debit.
  • toAccountID: The account ID to credit.
  • amount: The amount to be transferred.

Returns:

  • error: Error message if the operation fails.

GetTransactions

func GetTransactions(dbSvc *dynamodb.Client, accountID string, limit int32, lastTransactionID string) ([]LedgerEntry, string, error)

Purpose: Retrieves a list of transactions for an account.

Parameters:

  • dbSvc: DynamoDB client.
  • accountID: The account ID.
  • limit: Maximum number of transactions to retrieve.
  • lastTransactionID: ID of the last transaction retrieved (for pagination).

Returns:

  • []LedgerEntry: List of ledger entries.
  • string: The ID of the last transaction retrieved.
  • error: Error message if the operation fails.

Notifications

HandleDynamoDBStream

func HandleDynamoDBStream(ctx context.Context, event events.DynamoDBEvent) error

Purpose: Handles DynamoDB stream events to send email notifications.

Parameters:

  • ctx: Context.
  • event: DynamoDB event.

Returns:

  • error: Error message if the operation fails.

SendEmail

func SendEmail(sesSvc *ses.Client, msg Message) error

Purpose: Sends an email notification.

Parameters:

  • sesSvc: AWS SES client.
  • msg: Message containing email details.

Returns:

  • error: Error message if the operation fails.

SendSMS

func SendSMS(sms SMS) error

Purpose: Sends an SMS notification.

Parameters:

  • sms: SMS structure containing the details for the SMS message.

Returns:

  • error: Error message if the operation fails.

Roadmap for Planned Features

Short-term Goals:

  1. Refine the current DynamoDB schema to improve performance for high transaction volumes.
  2. Implement a caching layer to reduce read latency for frequently accessed data.
  3. Develop a more robust error handling and logging mechanism for easier debugging and maintenance.

Mid-term Goals:

  1. Integrate

with additional AWS services for analytics and real-time monitoring of transactions. 2. Support multi-currency transactions and automatic currency conversion based on real-time exchange rates. 3. Provide a user interface for account management and transaction history.

Long-term Goals:

  1. Expand the ledger system to support blockchain technologies for increased security and transparency.
  2. Establish a plugin system allowing third-party extensions and integrations.
  3. Implement AI-driven fraud detection and prevention systems.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

CheckUsersExist checks if the provided account IDs exist in the DynamoDB table.
No description provided by the author
No description provided by the author
CreateAccountWithBalance creates a new user account with an initial balance.
No description provided by the author
DeleteAccount by its tenantID and accountID.
No description provided by the author
No description provided by the author
No description provided by the author
GetAccount retrieves an account by tenant ID and account ID.
No description provided by the author
No description provided by the author
GetDetailedTransactions retrieves a list of transactions for a specified tenant and account.
No description provided by the author
No description provided by the author
No description provided by the author
GetTransactions retrieves a list of transactions for a specified tenant and account.
HandleDynamoDBStream handles sending notifications to nil users after payments.
InitializeLedger initializes the DynamoDB client using AWS credentials.
InquireBalance inquires the balance of a given user account.
No description provided by the author
No description provided by the author
No description provided by the author
NewS3 initializes an S3 client using AWS credentials.
Create a new transacton entry and populate it with default time and status of 1, using the current time.
No description provided by the author
No description provided by the author
No description provided by the author
The StoreTransaction function stores the details of a transaction.
No description provided by the author
No description provided by the author
StoreLocalWebhooks saves transactions in webhooks into a state so that it is retrievable later.
TransferCredits transfers a specified amount from one account to another.
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Define possible statuses.
Define possible statuses.
Define possible statuses.
Define possible statuses.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Balances represents the amount of money in a user's account.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LedgerEntry represents a single entry in the ledger table.
Message defines the structure for sending email messages.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SMS defines the structure for sending SMS notifications.
No description provided by the author
No description provided by the author
User represent a user entry in nil users table.
UserBalance represents the user's balance in the DynamoDB table.

# Type aliases

Status represents the status of a transaction.