Simple distributed blockchain experiment written in Crystal
To build zincir, you will need Crystal and OpenSSL installed on your system. You can use Homebrew on Mac to install these dependencies.
> git clone git@github.com:oguzbilgic/zincir-crystal.git
...
> shards install
...
> shards build --release
Dependencies are satisfied
Building: zincird
> ./bin/zincird --help
Usage: zincir [arguments]
-s IP, --seed-ip=IP First node to connect, TestNet by default
-i IP, --host-ip=IP Node's public ip, If the node is public
-p PORT, --port=PORT Node's public port, If the node is public
-l, --local-net Prevents node from connecting to public nodes
-w, --web Start web server without making the node public
-m, --mine Enable mining
-h, --help Show this help
-v, --version Show node version
> ./bin/zincird --mine
Connecting to testnet.zincir.xyz:9147
Added <1-0878bff02..ec7> 1544946023
...
Node will connect to TestNet
by default and sync the blockchain, before mining.
Blockchain will be cached in ./blocks/
folder.
> ./bin/zincird --ip mynode.mywebsite.com --port 1234 --mine
Connecting to testnet.zincir.xyz:9147
Added <1-0878bff02..ec7> 1544946023
...
In public mode, node will advertise it's ip and host to the network for other nodes to connect. Therefore, node needs to be publicly accessible with the provided ip and port configuration
- Read and add cached blocks from
.blocks/
folder to blockchain. Whenever a new block is added to the chain, store it in the.blocks/
folder - Unless
--local-net
is set, connect to seed host (testnet by default, can be updated with--seed-ip
option)- Compare our last block to network's last block
- Find the highest common block between network and local
- If network has a higher last block download all blocks between
common_block
and network's last block - If our last block is higher, broadcast all blocks between the
common_block
and our last block - Once the network download or broadcast is complete, wait for 5 seconds and compare local and network last block's to ensure network and local is synced
- If
--web
or--port
option is provided start local web server - If
--host-ip
option is provided start public web server and broadcast our ip to all the connected hosts. - If
--mine
option is set start the miner to mine new blocks. When a new block is mined broadcast it to network
> crystal spec
...