Question: Your will implement a distributed banking system that matches the following architecture: A client can debit an account, credit an account, or transfer funds from
Your will implement a distributed banking system that matches the following architecture:
A client can debit an account, credit an account, or transfer funds from one account to another. Account numbers are unique across all banks. Your virtual bank middleware will keep a mapping of account numbers to banks at which the account exist. If the client credits or debits the account by calling the credit() or debit() procedure at the virtual bank, the virtual bank middleware will look up the account number to determine which bank has that account, and then calls the appropriate procedure, either debit() or credit(), at that bank. If the client wishes to transfer funds, then the client will call transfer() at the virtual bank. The virtual bank middleware will look up the accounts, and call the debit() procedure at the bank from which the money is to be transferred, and call credit() at the bank to which the money is to be transferred.
Below is a table that shows what procedures should be implemented:
| Service | Procedure | Description |
| VIRTUAL_BANK | VB_credit(string account, int amount) | Add the amount to the account at the appropriate bank. |
| VB_debit(string account, int value) | Subtract the amount from the account at the appropriate bank. | |
| VB_transfer(string account1, string account2, int amount) | Debit account1 by amount, at the appropriate bank, and credit account2 by amount at the appropriate bank. | |
| BANK1 | B1_credit(string account, int amount) | Add the amount to the account at BANK1. |
| B1_debit(string account, int amount) | Subtract the amount from the account at BANK1. | |
| BANK2 | B2_credit(string account, int amount) | Add the amount to the account at BANK2. |
| B2_debit(string account, int amount) | Subtract the amount from the account at BANK2. |
You will implement VIRTUAL_BANK, BANK1, and BANK2 as RPC servers. You will implement the client as a RPC client, of course. The virtual bank should load the mapping of accounts to banks. Unfortunately, rpcgen, which generates your server stub, will also generate a main() for you (see my example above), which means that you cannot add any initialization code. You can deal with this in one of two ways: either give the rpcgen program the option not to generate the main and write your own, or add code to your procedures that checks its mapping data structure and initializes it if it is empty (this method is, of course, less efficient). Writing your own main is actually very easy. Just call rpcgen without any options so that it creates everything, then copy the main that it generates, and modify it with the initialization code you need (be sure to include the option that does not generate the main in your Makefile so that you do not get duplicate definition errors). Likewise, the banks should read and write a file that contains persistent account information. Use the SQLite3 embedded database as your storage engine.
Write the client so that it reads commands from standard input. Following is an example of the running client:
| $ ./client Ready> credit A12345 100 OK: Added 100 dollars to account A12345 Ready> debit B12345 2000 Error: not enough funds Ready> transfer A12345 B12345 100 OK: Transfered 100 dollars from account A12345 to account B12345 Ready> quit Goodbye |
All of your code should be written in C/C++ (except for the embedded SQL, of course). You do not have to worry about concurrency or service failure for this assignment. Include a Makefile with these targets: a default all target that builds the client, the virtual bank, and the two bank services, a test target that creates the initial databases, runs the services, and invokes the client. The test target should have the client invoke the following operations on the virtual bank:
credit A12345 100 credit B12345 100 transfer A12345 B12345 25 transfer B12345 A12345 10
Once the accomplishing the above operations, the test target should call the SQLite3 command line program to print the contents of the bank 1 and bank 2 databases. Note that bank1 should manage the A12345 account and bank2 should manage the B12345 account.
This assignment can be written in C or C++!!!!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
