afnanenayet / rustchain

A blockchain implemented in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rustchain

A blockchain implementation written in Rust, based off of the tutorial found here

Build

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.

Endpoint

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

Usage

This webapp runs as a REST endpoint. Here are the three methods available:

/transactions/new

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>
    }
}

/chain

This will return the entire blockchain serialized in JSON with serde-json

/mine

This will mine a new block and return the following information:

  • the transaction awarded (serde-json serialized Transaction struct)
  • the index of the Block/node in the blockchain
  • the proof for the block you mined

About

A blockchain implemented in Rust

License:MIT License


Languages

Language:Rust 100.0%