This is a small blockchain based on "Bitcoin and Cryptocurrency Technologies" book from here. It uses crow library for rest apis. crow. It is a very fast and easy to use C++ micro web framework (inspired by Python Flask). For the JSON manipulation, I used JSON for Modern C++, nlohmann/json, nlohmann/json. And for calculating sha256, I used sha256.h from Zedwood.
mkdir build
cd build
cmake ..
make
./bc 6000
localhost:6000/chain
localhost:6000/mine
New transaction is a POST method, make sure to add to its body like this:
{
"sender": "x",
"recipient": "y",
"amount":1
}
localhost:6000/transaction/new
Register nodes is a POST method, make sure to add to its body like this:
{
"nodes":["localhost:6001", "localhost:6002"]
}
localhost:6000/nodes/register
localhost:6000/nodes/resolve
Each node, at first, creates the genesis block with no transactions. Then it keeps the current transactions until a mine happens. Then it adds a new block to the chain with transactions.
Run an instance with port 6000, ./bc 6000
, then add some transactions, then a mine, some other transactions and some other mines, now check the chain with localhost:6000/chain
. Now, it's time to add another instance with port 6001, and register other nodes to it. Right now, this one has a smaller chain, so we expect that its chained replaced with the others chain. Run resolve request and see the result.