A blockchain implementation written in Rust, based off of the tutorial found here
This project was built with Cargo using the Rust stable compiler. To build:
cargo build
To run:
cargo run
the pencil
dependency requires rust-openssl
, which requires openssl
headers.
Ubuntu:
sudo apt-get install libssl-dev
Mac:
brew install openssl
export DEP_OPENSSL_INCLUDE=/usr/local/opt/openssl/include
export OPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include
Brew doesn't symlink the paths so you have to export the OpenSSL headers that you installed with homebrew.
There are three ways to interact with the binary via HTTP requests:
/transactions/new
creates a new transaction/mine
has the server mine a new block/chain
returns the entire Blockchain
This webapp runs as a REST endpoint. Here are the three methods available:
Accepts a JSON dictionary in the format "transaction" : {JSON serialized Transaction struct}
If you want to do this manually, this is what the JSON request should look like:
{ "transaction":
{
"sender":"a string",
"recipient":"a string",
"amount":<a float>
}
}
This will return the entire blockchain serialized in JSON with serde-json
This will mine a new block and return the following information:
- the transaction awarded (
serde-json
serializedTransaction
struct) - the index of the Block/node in the blockchain
- the proof for the block you mined