Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit - start here to follow along with the videos
- Loading branch information
0 parents
commit 8f94f4d
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "blockchain-in-rust" | ||
version = "0.1.0" | ||
authors = ["Jacob <jacob@geeklaunch.net>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
name = "blockchainlib" | ||
path = "src/lib.rs" | ||
|
||
[[bin]] | ||
name = "blockchain" | ||
path = "src/main.rs" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::fmt::{ self, Debug, Formatter }; | ||
|
||
pub struct Block { | ||
} | ||
|
||
impl Debug for Block { | ||
fn fmt (&self, f: &mut Formatter) -> fmt::Result { | ||
write!(f, "Block") | ||
} | ||
} | ||
|
||
impl Block { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
type BlockHash = Vec<u8>; | ||
|
||
// Credit: https://stackoverflow.com/a/44378174/2773837 | ||
use std::time::{ SystemTime, UNIX_EPOCH }; | ||
|
||
pub fn now () -> u128 { | ||
let duration = SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.unwrap() | ||
; | ||
|
||
duration.as_secs() as u128 * 1000 + duration.subsec_millis() as u128 | ||
} | ||
|
||
pub fn u32_bytes (u: &u32) -> [u8; 4] { | ||
[ | ||
(u >> 8 * 0x0) as u8, | ||
(u >> 8 * 0x1) as u8, | ||
(u >> 8 * 0x2) as u8, | ||
(u >> 8 * 0x3) as u8, | ||
] | ||
} | ||
|
||
pub fn u64_bytes (u: &u64) -> [u8; 8] { | ||
[ | ||
(u >> 8 * 0x0) as u8, | ||
(u >> 8 * 0x1) as u8, | ||
(u >> 8 * 0x2) as u8, | ||
(u >> 8 * 0x3) as u8, | ||
|
||
(u >> 8 * 0x4) as u8, | ||
(u >> 8 * 0x5) as u8, | ||
(u >> 8 * 0x6) as u8, | ||
(u >> 8 * 0x7) as u8, | ||
] | ||
} | ||
|
||
pub fn u128_bytes (u: &u128) -> [u8; 16] { | ||
[ | ||
(u >> 8 * 0x0) as u8, | ||
(u >> 8 * 0x1) as u8, | ||
(u >> 8 * 0x2) as u8, | ||
(u >> 8 * 0x3) as u8, | ||
|
||
(u >> 8 * 0x4) as u8, | ||
(u >> 8 * 0x5) as u8, | ||
(u >> 8 * 0x6) as u8, | ||
(u >> 8 * 0x7) as u8, | ||
|
||
(u >> 8 * 0x8) as u8, | ||
(u >> 8 * 0x9) as u8, | ||
(u >> 8 * 0xa) as u8, | ||
(u >> 8 * 0xb) as u8, | ||
|
||
(u >> 8 * 0xc) as u8, | ||
(u >> 8 * 0xd) as u8, | ||
(u >> 8 * 0xe) as u8, | ||
(u >> 8 * 0xf) as u8, | ||
] | ||
} | ||
|
||
mod block; | ||
pub use crate::block::Block; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main () { | ||
println!("Hello, blockchain!"); | ||
} |