Struct pow_sha256::Config

source ·
pub struct Config {
    pub salt: String,
}
Expand description

Configuration for generting proof of work Please choose a long, unique value for salt Resistance to dictionary/rainbow attacks depend on uniqueness of the salt

Fields§

§salt: String

Implementations§

source§

impl Config

source

pub fn stepped_prove_work<T>( &self, t: &T, difficulty: u32, step: usize, inter: Option<IncrementalSolve<T>> ) -> Result<IncrementalSolve<T>>where T: Serialize,

step is used to control the number of cycles after which the function should exit, even when the proof isn’t ready inter is used to keep track of state and complete proof generation. Set inter to None during first cyle and pass the returned value of the previous cycle to continue proof generation

source

pub fn prove_work<T>(&self, t: &T, difficulty: u32) -> Result<PoW<T>>where T: Serialize,

Create Proof of Work over item of type T.

Make sure difficulty is not too high. A 64 bit difficulty, for example, takes a long time on a general purpose processor. Returns bincode::Error if serialization fails.

source

pub fn prove_work_serialized<T>(&self, prefix: &[u8], difficulty: u32) -> PoW<T>where T: Serialize,

Create Proof of Work on an already serialized item of type T. The input is assumed to be serialized using network byte order.

Make sure difficulty is not too high. A 64 bit difficulty, for example, takes a long time on a general purpose processor.

source

pub fn calculate<T>(&self, pow: &PoW<T>, t: &T) -> Result<u128>where T: Serialize,

Calculate the PoW score with the provided input T.

source

pub fn calculate_serialized<T>(&self, pow: &PoW<T>, target: &[u8]) -> u128where T: Serialize,

Calculate the PoW score of an already serialized T and self. The input is assumed to be serialized using network byte order.

source

pub fn is_valid_proof<T>(&self, pow: &PoW<T>, t: &T) -> boolwhere T: Serialize,

Verifies that the PoW is indeed generated out of the phrase provided.

source

pub fn is_sufficient_difficulty<T>( &self, pow: &PoW<T>, target_diff: u32 ) -> boolwhere T: Serialize,

Checks if the PoW result is of sufficient difficulty

Trait Implementations§

source§

impl Clone for Config

source§

fn clone(&self) -> Config

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Config

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Config

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq<Config> for Config

source§

fn eq(&self, other: &Config) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Config

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,