Download the PHP package jamielsharief/blockchain without Composer
On this page you can find all versions of the php package jamielsharief/blockchain. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jamielsharief/blockchain
More information about jamielsharief/blockchain
Files in jamielsharief/blockchain
Package blockchain
Short Description Blockchain
License MIT
Informations about the package blockchain
Blockchain (beta)
A Blockchain database suitable for both private or public blockchains.
- Blocks are stored with transactions as JSON so they are very portable
- Database has been designed to handle large amounts of Blocks and can be quickly synced across multiple servers (if required)
- Transactions are encoded in a Merkle Tree, any attempt to change the transaction will be detected and duplicate transactions submitted in other blocks can also be detected.
- Proof of work can be disabled for private blockchains to remove unnecessary and cumbersome calculations
- It is very fast, you can search for the furthest away hash in the index of 2 million blocks in 0.44 seconds (2012 laptop)
Trying it out
I have included demo.php
which will create a Blockchain
with Blocks
and Transactions
Clone the source code to a directory
Run composer install
Then run the demo script
Create
To create a Blockchain
instance, provide a path to where data for that Blockchain will be stored.
For a private Blockchain, set difficulty to 0, since no proof of work is required.
The Blockchain is created when you add the first Block
of Transactions
.
Create a Transaction
object and pass the data to the constructor.
Create a Block
and add a Transaction
to it, you can add as many Transactions
as you need for
each Block
.
To add the Block
to the Blockchain
Finding Blocks
To get a Block
provide the block number
You can also search by hash
To get the most recent Block
Counting
To count the number of Blocks
in the Blockchain
List
To get a list of hashes of the most recent X Blocks
with the Block
number.
To list a custom amount of Blocks
All
To go through all Blocks
in the Blockchain
, use the all
method which yeilds each Block
so that it can be done in a memory efficient manner.
The following options can be used
- start: default:0 from which block number
- finish: default:[last block] to which block number
- reverse: default: true. Goes through Blocks starting at the most recent block if set
Validating the Blockchain
On my 2012 Mac Book it took me approx 9 minutes to validate a Blockchain with 1.2 million Blocks and roughly 6 million Transactions.
To validate the entire Blockchain
.
Todo
I am thinking the following:
- [ ] If the first set of transactions should define the schema going forward of all future transactions.
- [ ] maybe an encrypted Blockchain could be interesting for private Blockchains to protect data