Package dev.mintychochip.mint
Interface Service
@AvailableSince("1.1")
public interface Service
Primary service interface for managing economy accounts and transactions.
All account operations are asynchronous and return CompletableFuture. Transactions are
synchronously created but execute asynchronously on commit.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault TransactionbeginTransaction(UUID accountId) Begins a new transaction against the specified account with empty context.beginTransaction(UUID accountId, TransactionContext ctx) Begins a new transaction against the specified account with provided context.createAccount(UUID holderId, String name) Asynchronously creates a new account for the specified holder.deleteAccount(UUID accountId) Asynchronously deletes the specified account.deposit(UUID holderId, BigDecimal amount) Asynchronously deposits funds into the specified holder's account.getAccount(UUID accountId) Asynchronously retrieves an account by its identifier.getBalanceByAccount(UUID accountId) Asynchronously retrieves the balance of the specified account.getBalanceByHolder(UUID holderId) Asynchronously retrieves the balance of the account for the specified holder.getBalances(List<UUID> accountIds) Asynchronously retrieves balances for multiple accounts in a single batch operation.intReturns the maximum number of fractional digits allowed for currency amounts.getName()Returns the name of this service implementation.getTopBalances(int limit) Asynchronously retrieves all holder balances sorted by balance in descending order.hasAccount(UUID holderId) Asynchronously checks if an account exists for the specified holder.transfer(UUID fromHolderId, UUID toHolderId, BigDecimal amount) Asynchronously transfers funds from one holder's account to another holder's account.updateAccountName(UUID accountId, String name) Asynchronously updates the display name of the specified account.withdraw(UUID holderId, BigDecimal amount) Asynchronously withdraws funds from the specified holder's account.
-
Method Details
-
getName
String getName()Returns the name of this service implementation.- Returns:
- the service name
-
getMaxFractionalDigits
int getMaxFractionalDigits()Returns the maximum number of fractional digits allowed for currency amounts.- Returns:
- maximum decimal places for monetary values
-
beginTransaction
Begins a new transaction against the specified account with empty context.Equivalent to
beginTransaction(accountId, TransactionContext.empty()).- Parameters:
accountId- the account to transact against- Returns:
- a new active transaction
-
beginTransaction
Begins a new transaction against the specified account with provided context.The transaction is created in
Transaction.State.ACTIVEstate. Operations can be chained before callingTransaction.commit().- Parameters:
accountId- the account to transact againstctx- context containing actor and optional reason- Returns:
- a new active transaction
-
getBalanceByAccount
Asynchronously retrieves the balance of the specified account.- Parameters:
accountId- the account identifier- Returns:
- future completing with the account balance
-
getBalanceByHolder
Asynchronously retrieves the balance of the account for the specified holder.- Parameters:
holderId- the holder's unique identifier- Returns:
- future completing with the account balance
-
getBalances
Asynchronously retrieves balances for multiple accounts in a single batch operation.- Parameters:
accountIds- list of account identifiers- Returns:
- future completing with list of balances in the same order as input
-
hasAccount
Asynchronously checks if an account exists for the specified holder.- Parameters:
holderId- the holder's unique identifier- Returns:
- future completing with
trueif account exists,falseotherwise
-
createAccount
Asynchronously creates a new account for the specified holder.- Parameters:
holderId- the holder's unique identifiername- the display name for the account- Returns:
- future completing with the newly created account
-
getAccount
Asynchronously retrieves an account by its identifier.- Parameters:
accountId- the account identifier- Returns:
- future completing with optional containing the account if found, empty otherwise
-
deleteAccount
Asynchronously deletes the specified account.- Parameters:
accountId- the account identifier- Returns:
- future completing with
trueif account was deleted,falseif not found
-
updateAccountName
Asynchronously updates the display name of the specified account.- Parameters:
accountId- the account identifiername- the new display name for the account- Returns:
- future completing with
trueif account name was updated,falseif account not found
-
transfer
Asynchronously transfers funds from one holder's account to another holder's account.- Parameters:
fromHolderId- the holder transferring fundstoHolderId- the holder receiving fundsamount- the amount to transfer- Returns:
- future completing with the amount actually transferred
-
deposit
Asynchronously deposits funds into the specified holder's account.- Parameters:
holderId- the holder's unique identifieramount- the amount to deposit- Returns:
- future completing with the amount actually deposited
-
withdraw
Asynchronously withdraws funds from the specified holder's account.- Parameters:
holderId- the holder's unique identifieramount- the amount to withdraw- Returns:
- future completing with the amount actually withdrawn
-
getTopBalances
Asynchronously retrieves all holder balances sorted by balance in descending order.This is useful for leaderboards and statistics. The returned map contains holder UUIDs as keys and their corresponding balances as values.
- Parameters:
limit- the maximum number of entries to return- Returns:
- future completing with a list of holder-balance pairs sorted by balance (highest first)
-