This database has four main tables and an extra table for blockchain parameters. Below is the Entity-Relationship Diagram (ERD):
Following are the descriptions for the tables:
- Represents individual blocks in the blockchain.
- Each block links to the previous block via its
previous_hash
. - Includes fields for block metadata like nonce, timestamp, and hash.
- Stores public keys for senders and receivers involved in transactions.
- Note: While Bitcoin does not store account balances directly, this table allows tracking balances like Ethereum. If you don’t want to store balances, this table is unnecessary and can be bypassed using public keys directly in the Parties table.
- This table records the transfer of value between accounts, like ACH transfers.
- To mimic Bitcoin, each transaction can have multiple senders and multiple receivers. Thus, it has a many-to-many relationship with the Accounts table.
- It is the bridge table that establishes the many-to-many relationship between Transactions and Accounts.
- Tracks the amount (UTXO) associated with each party: Positive for receivers and Negative for senders.
- The sum of inputs can be equal to or greater than the sum of outputs. The extra amount is the fee (tip) that goes to the miner.
- Contains blockchain constants and configurable values such as difficulty target, block reward, and other key protocol settings.
This repository includes four SQL scripts to set up and operate the blockchain simulation. Execute them in the following order:
- Creates the database tables, stored procedures, and functions.
- Enforces access controls to prevent unauthorized changes:
UPDATE
andDELETE
operations are disallowed.- Blocks and transactions can only be added through stored procedures.
- New accounts and Parties records can be added using
INSERT
. - Two triggers secure data integrity in the Parties table.
- Defines the mining procedure and creates the Genesis block.
- Populates the database with test accounts and transactions.
- Mines a few blocks to demonstrate functionality.
- Can be customized to create additional transactions or blocks.
- Resets the database by removing all tables and data.
- You can start over by re-running
Protocol.sql
andInitialize.sql
.
We welcome contributions to improve the codebase or documentation. Here are the steps to make contributions:
-
Fork the Repository
Create a personal copy of the repository to make changes. -
Modify
Make changes in your local. -
Testing
Test in your local and ensure your changes pass all relevant tests. -
Submit a Pull Request
Once changes are complete, submit a pull request for review.
- Note: Discuss significant changes with the repository admin, Dr. Armani, before submitting a PR. Minor bug fixes or corrections do not require prior discussion though.
This project is licensed under the MIT License, ensuring open use with attribution.
Feel free to suggest additional improvements, fork the repository, and experiment with this blockchain simulation!