This project aims to create a simple implementation of blockchain concept and demostrate it in a user friendly way.
This project consists of two main parts: agent and interface.
An agent stands for one peer which is able to store and mine blocks in the network. Every agent is connected to all the other agents in the network to construct a P2P distributed network. The basic functions for an agent are:
The algorithm for mining is the key of a blockchain. In this project we only use SHA256 hash to simulate the mining procedure.
An interface implemented with Springboot is included in this project to demostrate the usage of the blockchain. It might make people feel like a centralized management interface, however we need to understand that agents can also run independently. The interface is RESTful and all return data is in json format. A single page application is also provided to visualize the blockchain concept in a better way.
Navigate to project root dir and start the server:
$ gradle bootRun
Open http://localhost:8080/ in browser and try it from web page. Basic actions are:
Use curl directly from command line to interact with the server:
curl -X POST "http://localhost:8080/agent?name=A1&port=1001"
{"name":"A1","port":1001,"blockchain":[{"index":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"}]}
curl -X POST "http://localhost:8080/agent?name=A2&port=1002"
{"name":"A2","port":1002,"blockchain":[{"index":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"}]}
curl -X POST "http://localhost:8080/agent?name=A3&port=1003"
{"name":"A3","port":1003,"blockchain":[{"index":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"}]}
curl -X POST "http://localhost:8080/agent/mine?agent=A1"
{"index":1,"timestamp":1502194172250,"hash":"2461f27f811df15a969391c70f136869a282224e8cc6fe8b628d16a499515d21","previousHash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480"}
curl -X POST "http://localhost:8080/mine?name=A3"
{"timestamp":1502194200235,"status":404,"error":"Not Found","message":"No message available","path":"/mine"}
curl http://localhost:8080/agent?name=A1
{"name":"A1","port":1001,"blockchain":[{"index":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"},{"index":1,"timestamp":1502194172250,"hash":"2461f27f811df15a969391c70f136869a282224e8cc6fe8b628d16a499515d21","previousHash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480"}]}
curl http://localhost:8080/agent?name=A3
{"name":"A3","port":1003,"blockchain":[{"index":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"},{"index":1,"timestamp":1502194172250,"hash":"2461f27f811df15a969391c70f136869a282224e8cc6fe8b628d16a499515d21","previousHash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480"}]}
curl http://localhost:8080/agent/all
curl -X DELETE http://localhost:8080/agent/all
This project is inspired by naivechain.
今天为大家汇总一下区块链专业术语,以防聊天时不知道对方在说什么。 1.区块链(BlockChain) 区块链是一个信息技术领域的术语。从本质上讲,它是一个共享数据库,存储于其中的数据或信息,具有“不可伪造”、“全程留痕”、“可以追溯”、“公开透明”、“集体维护”等特征。基于这些特征,区块链技术奠定了坚实的“信任“基础,创造了可靠的“合作”机制,具有广阔的运用前景。 2.区块(Blo