blockchain-cli 0.1.7

Provides a command-line interface (CLI) for interacting with blockchain
Documentation

Blockchain CLI

Reference implementation

test docs crate Crates.io (recent) GitHub issues GitHub

A Rust library provides a command-line interface (CLI) for interacting with blockchain.

Features

  • Create a blockchain
  • Add a transaction
  • Get a transaction
  • Get all transactions
  • Generate a block
  • Change a reward
  • Change a difficulty

Usage

Run the following Cargo command in your project directory::

cargo add blockchain-cli

Usage

extern crate blockchain;

use blockchain::Chain;

fn main() {
  // Initialise a new blockchain
  let mut chain = Chain::new(
    String::from("bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"),
    2,
    100.0
  );

  // Add a transaction
  chain.add_transaction(
    String::from("mxwgXGHxtjmGJ1cFebRW9emcV2vV1aPGfk"),
    String::from("n2zet2T3KNRjD69oF9ZquLsigH1ZBJcraR"),
    1.25
  );

  // Get a transaction
  let transaction = chain.get_transaction(
    String::from("6e8c5dc01145016e5a979683ba7e13bafaf85e765490aa33c0bba1f41cf581ed")
  );

  match transaction {
    Some(trx) => println!("📦 Transaction: {:?}", trx),
    None => println!("❌ Transaction was not found"),
  }

  // Get all transactions
  let transactions = chain.get_transactions();
  println!("📦 Transactions: {:?}", transactions);

  // Others
}

Contributing

  • Build an application:
cargo build
  • Test an application:
cargo test
  • Run an application:
cargo run
cargo clippy --all-targets --all-features -- -D warnings
  • Generate documentation in HTML format:
cargo doc --open