I want to create local blockchain for my application. New blocks should be created while giving reference to previous block. But I am not getting exactly how will I do it in MySQL? I got some idea from http://blog.theodorejb.me/sql-linked-lists/ . Now I want to retrieve top block every time I create a new block. But Is it possible in MySQL to retrieve Newly inserted row's primary key? Or Is is possible to implement stack(with reference) in MySQL ? So that I can retrieve top block.
I believe you are over complicating your life.
Having a BlockChain (a Linked Ledger) in SQL can be prototyped in the following manner
Create a table, such as:
CREATE TABLE IF NOT EXISTS MyBlockChain ( LedgerID int(10) NOT NULL auto_increment, block varchar(255), datetimestamp datetime, guid varchar(255), --Have a Default GUID Generated PRIMARY KEY( `LedgerID` ) );
Having an AutoGenerated Sequence Number (as a primary key) - This creates the sequence in your ledger.
Assign Proper Security to only allow INSERTS to happen over a Public API.
- Only the GUID is used to access a Record (block) via ReadOnly permissions.
- When users can only INSERT Data (No DELETE or UPDATE) you, in essence, created a Ledger.
- And since the Sequence Number will be used to determine ordering of actions.
The biggest challenge to distributing the MySQL database over multiple instances an having an API interface and ensuring ReadOnly and Insert Only security.
That by default is a simple implementation of a BlockChain