Process List of Commands
The system simulates a transaction intent management tool to handle the process from initialization to completion and calculate the final balances of merchants' accounts. Transaction states include:
Core Features:
Extended Features:
Time-Limited Refunds:
- If no limit is set, refunds are allowed indefinitely.
- A limit of 0 means no refunds are allowed.
Task Objective:
Process a list of commands to manage transaction intents and output the final balances of all accounts.
Input Format:
A time-ordered list of commands.
Output Format:
A list of account balances in ascending order by account ID.
1Example 1
The commands are processed as follows:
- START account1 0: Initializes account1 with a balance of 0.
- NEW txn1 account1 50: Creates a new transaction intent txn1 for account1 with an amount of 50 in PENDING state.
- PROCESS txn1: Moves txn1 to IN_PROGRESS state.
- COMPLETE txn1: Moves txn1 to DONE state and adds the amount to account1's balance, resulting in a final balance of 50.
2Example 2
The commands are processed as follows:
- START account1 0: Initializes account1 with a balance of 0.
- NEW txn1 account1 50: Creates a new transaction intent txn1 for account1 with an amount of 50 in PENDING state.
- PROCESS txn1: Moves txn1 to IN_PROGRESS state.
- CANCEL txn1: Reverts txn1 to PENDING state.
- PROCESS txn1: Moves txn1 back to IN_PROGRESS state.
- COMPLETE txn1: Moves txn1 to DONE state and adds the amount to account1's balance, resulting in a balance of 50.
- RETURN txn1: Processes a refund for txn1 and deducts the amount from account1's balance, resulting in a final balance of 0.
3Example 3
The commands are processed as follows:
- 1 START account1 0 5: Initializes account1 with a balance of 0 and a refund limit of 5.
- 2 NEW txn1 account1 100: Creates a new transaction intent txn1 for account1 with an amount of 100 in PENDING state.
- 8 COMPLETE txn1: Moves txn1 to DONE state and adds the amount to account1's balance, resulting in a balance of 100.
- 11 RETURN txn1: Processes a refund for txn1 within the refund limit and deducts the amount from account1's balance, resulting in a balance of 0.
- 16 RETURN txn1: The refund is not processed because it is outside the refund limit, so the balance remains 100.