Session 3 - Blockchain Data Structures

In this session, after making a quick recap of Session 2, we continue understanding blockchain systems.

Understanding the Transaction Data Structure

The blockchain related datatypes used by the simulator are found in the max.datatype.ledger project.

...
public class Transaction {

    /**
     * The address of the sender of the assets
     */
    private Address sender;

    /**
     * The address of the receiver of the assets
     */
    private Address receiver;

    /**
     * The fee given by the sender to pay the block validators
     */
    private Double fee;

    /**
     * The amount of assets transfered to the receiver from the sender
     */
    private Payload payload;

    /**
     * The size of the transaction
     */
    private Integer size;

    /**
     * Block height or time-stamp when transaction is final
     */
    private BigDecimal lockTime;
    
    /**
     * True if this transaction is endorsed. False by default.
     */
    private boolean isEndorsed;
...

The Address class used in Transaction is found in the max.datatype.com project.

Now clone these two projects to your Eclipse, check their source code and check their tests.

Simple Standalone Bank Application in Java

Write a simple standalone (working only in one computer) bank application in Java.

Part I

  • Create a dedicated Gitlab project called Standalone Bank Application.

  • Issue: Create a Java project called Standalone Bank Application and create its corresponding merge request.

    Remember that the merge request will create a new dedicated branch.

  • Clone this empty project using your Java IDE (Eclipse or IntelliJ) and check out the new branch as local branch.

    Remember that you should never work on the main branch.

  • Create a dedicated Java project called Standalone Bank Application in your IDE and then share it on Gitlab.

  • Push your empty Java project to Gitlab.

    Remember that the commit message should be in the #n Issue title format.

  • Now, for each following item, create a dedicated issue on Gitlab, then create the dedicated merge request, and then implement it in your IDE and finally push it.

  • Issue: Create an Account class

    • that holds the account id, first name, last name and balance of a client.
    • that has the necessary constructor and getter/setter methods for Account.
    • suppose that by default each account has 100 in its balance.
  • Issue: Create a Bank class that holds a list accounts.

    • that has a constructor method where you initialize the list of accounts for Bank.
    • that has the following methods:
    • public Account get(int accountID): searched for an account with accountID and returns it, if not found returns null,
    • public boolean addAccount(accountID, firstName, lastName, initialBalance): creates and adds a new account,
    • public void registerAccount(): creates and add a new account by asking user account information,
    • public boolean transferMoney(fromAccountID, toAccountID, amount, fee): transfers the given amount from a given account to another given account and the fee is taken from the from account.
  • Issue: Create a Main class

    • that has a public static void main(String[] args) method where a Bank is created, and a menu with 3 options:
      • 1. Register a new account
      • 2. Show balance of an account
      • 3. Transfer money
  • Note that you can use Scanner scanner = new Scanner(System.in); for getting input from the user.

Previous
Next