bee_pow/providers/mod.rs
1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! Contains nonce providers for Proof of Work.
5
6pub mod miner;
7pub mod u64;
8
9/// A trait to build nonce providers.
10pub trait NonceProviderBuilder: Default + Sized {
11 /// The type of the built nonce provider.
12 type Provider: NonceProvider<Builder = Self>;
13
14 /// Creates a new nonce provider builder.
15 fn new() -> Self {
16 Self::default()
17 }
18
19 /// Constructs the nonce provider from the builder.
20 fn finish(self) -> Self::Provider;
21}
22
23/// A trait describing how a nonce is provided.
24pub trait NonceProvider: Sized {
25 /// The type of the nonce provider builder.
26 type Builder: NonceProviderBuilder<Provider = Self>;
27 /// Type of errors occurring when providing nonces.
28 type Error: std::error::Error;
29
30 /// Returns a builder for this nonce provider.
31 fn builder() -> Self::Builder {
32 Self::Builder::default()
33 }
34
35 /// Provides a nonce given bytes and a target score.
36 fn nonce(&self, bytes: &[u8], target_score: u32) -> Result<u64, Self::Error>;
37}