0.2.7 |
|
---|---|
0.2.6 |
|
0.2.2 |
|
0.1.7 |
|
#14 在 #open-source
90KB
259 行
Rust区块链
Rust编程语言的区块链crate。
这个库受到了这个教程的启发。
你能展示如何使用这个crate吗?
这是一个入门示例
use std::env;
use rs_blockchain::add_transaction;
use rs_blockchain::rust_blockchain::blockchain::Blockchain;
use rs_blockchain::Unwrap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = env::args().collect();
let mut new_blockchain = Blockchain::init();
let mut collected_args: String = String::new();
for arg in args[0..].iter() {
collected_args.push_str(arg);
}
let amount = rs_blockchain::remove_non_digits(&collected_args).arg_unwrap();
new_blockchain.set_difficulty(4);
println!("{}", rs_blockchain::VERSION_INFO);
if amount != 0 {
for i in 1..=amount {
add_transaction!(
new_blockchain, "Jane Doe" => "John Doe", i as f32,
new_blockchain, "John Doe" => "Jane Doe", 1 << i,
);
new_blockchain.mine();
}
} else {
for i in 1..=25 {
add_transaction!(
new_blockchain, "Jane Doe" => "John Doe", i as f32,
new_blockchain, "John Doe" => "Jane Doe", 1 << i,
);
new_blockchain.mine();
}
}
new_blockchain.list_transactions();
new_blockchain.write_chain_to_file()?;
Ok(())
}
我可以为这个项目做贡献吗?
当然,任何人都可以!
依赖关系图
依赖
~1.1–2MB
~46K SLoC