diff --git a/Cargo.toml b/Cargo.toml index dab7363..ef431ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pow" -version = "0.1.4" +version = "0.1.5" authors = ["Andrew Dirksen "] description = """ Generate or verify sha256 based proofs of work over arbitrary typed data. diff --git a/readme.md b/readme.md index 76fc88d..8836545 100644 --- a/readme.md +++ b/readme.md @@ -30,6 +30,16 @@ let pw = Pow::prove_work(&now, difficulty).unwrap(); assert!(pw.score(&now).unwrap() >= difficulty); ``` +Define a blockchain block. + +```rust +struct Block { + prev: [u8; 32], // hash of last block + payload: T, // generic data + proof_of_work: Pow<([u8; 32], T)>, +} +``` + # Score scheme To score a proof of work for a given (target, Pow) pair: diff --git a/src/lib.rs b/src/lib.rs index 6de49be..f151ec7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,18 @@ //! let pw = Pow::prove_work(&now, difficulty).unwrap(); //! assert!(pw.score(&now).unwrap() >= difficulty); //! ``` - +//! +//! Define a blockchain block. +//! +//! ```rust +//! # use pow::Pow; +//! struct Block { +//! prev: [u8; 32], // hash of last block +//! payload: T, // generic data +//! proof_of_work: Pow<([u8; 32], T)>, +//! } +//! ``` +//! //! # Score scheme //! //! To score a proof of work for a given (target, Pow) pair: @@ -91,7 +102,7 @@ //! let m = u128::max_value(); //! if difficulty == m { //! return m; -//! } +//! } //! m / (m - difficulty) //! } //! ``` diff --git a/src/proof_of_work.rs b/src/proof_of_work.rs index 04d80f2..1ce87b5 100644 --- a/src/proof_of_work.rs +++ b/src/proof_of_work.rs @@ -6,7 +6,7 @@ const SALT: &str = "35af8f4890981391c191e6df45b5f780812ddf0213f29299576ac1c98e18 /// Proof of work over concrete type T. T can be any type that implements serde::Serialize. #[derive(Serialize, Deserialize, PartialEq, Clone, Copy, Debug)] -pub struct Pow { +pub struct Pow { proof: u128, _spook: PhantomData, }