The BlockChainServer application has been tested on windows and mac. It has not been tested on Linux, but it will probably work. The server uses 2 ports. The 8080 port is for the API interface and the 8081 is for communicating between servers.
On unix
mkdir build
cd build
cmake ..
make
make install
On windows You can create VS files using cmake-gui.
You can use --http-port to change the default HTTP port and --tcp-port to change the TCP port. Example usage:
./blockchainserver --tcp-port 81 --http-port 80
For getting help
http://127.0.0.1:8080/help
It is using to create a new block.
curl -X POST -d "Test Data" http://127.0.0.1:8080/createblock
{"Status":true,"Index":2}
Get block information via index.
curl -X POST -d "2" http://127.0.0.1:8080/getblock
{"Status":true,"Data":"VGVzdCBEYXRh"}
Data is encoded in Base64.
Total blocks count.
curl http://127.0.0.1:8080/totalblocks
{"Status":true,"TotalBlock":2}
Fetch all blocks.
curl http://127.0.0.1:8080/blocks
{"Status":true,"Blocks":[{"Index":1,"Hash":"d9b5d942a14db7a408328b178bfb531b508b322a08264cbf189c008947512634","PreviousHash":"8bb60170a7a13686c3c651dac9038ce96eed1ff208cd5e29b4b16bbfec5c9c20","TimeStamp":1508090809,"Nonce":0,"Data":"R2VuZXNpcyBibG9jaw=="},{"Index":2,"Hash":"35da1352558b78801f3ed2c91520ab2bffac7fceaf3338b2c767f2a463aab3ec","PreviousHash":"d9b5d942a14db7a408328b178bfb531b508b322a08264cbf189c008947512634","TimeStamp":1508236436,"Nonce":0,"Data":"VGVzdCBEYXRh"}]}
Add new blockchain server.
curl -X POST -d "127.0.0.1:9787" http://127.0.0.1:8080/addnode
{"Status":true,"Message":"Node will be added."}
Synchronization could take a time.
Connected node list.
curl http://127.0.0.1:8080/nodes
{"Status":true,"Nodes":["127.0.0.1:9787"]}
Disconnect from remote node.
curl -X POST -d "127.0.0.1:9787" http://127.0.0.1:8080/removenode
{"Status":true}
The system automatically synchronize other servers continuously but can be used if you want to trigger this manually.
curl -X POST -d "127.0.0.1:9787" http://127.0.0.1:8080/removenode
{"Status":true}
It is used to check the validity of block information.
curl -X POST -d "{\"Index\":2,\"Hash\":\"35da1352558b78801f3ed2c91520ab2bffac7fceaf3338b2c767f2a463aab3ec\",\"PreviousHash\":\"d9b5d942a14db7a408328b178bfb531b508b322a08264cbf189c008947512634\",\"TimeStamp\":1508236436,\"Nonce\":0}" http://127.0.0.1:8080/validate
{"Status":true}