Move LedgerState into the block module

This commit is contained in:
teor 2021-04-23 13:19:33 +10:00 committed by Deirdre Connolly
parent 9b3d56db0c
commit 0d8ffc367e
4 changed files with 43 additions and 42 deletions

View File

@ -22,6 +22,9 @@ pub use header::{BlockTimeError, CountedHeader, Header};
pub use height::Height;
pub use serialize::MAX_BLOCK_BYTES;
#[cfg(any(test, feature = "proptest-impl"))]
pub use arbitrary::LedgerState;
use serde::{Deserialize, Serialize};
use crate::{

View File

@ -7,13 +7,49 @@ use chrono::{TimeZone, Utc};
use std::sync::Arc;
use crate::{
parameters::Network,
parameters::{Network, NetworkUpgrade},
work::{difficulty::CompactDifficulty, equihash},
LedgerState,
};
use super::*;
#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
/// The configuration data for proptest when generating arbitrary chains
pub struct LedgerState {
/// The tip height of the block or start of the chain
pub tip_height: Height,
/// The network to generate fake blocks for
pub network: Network,
/// Make this fake transaction a coinbase transaction
pub(crate) is_coinbase: bool,
}
impl LedgerState {
/// Construct a new ledger state for generating arbitrary chains via proptest
pub fn new(tip_height: Height, network: Network) -> Self {
Self {
tip_height,
is_coinbase: true,
network,
}
}
}
impl Default for LedgerState {
fn default() -> Self {
let network = Network::Mainnet;
let tip_height = NetworkUpgrade::Canopy.activation_height(network).unwrap();
Self {
tip_height,
is_coinbase: true,
network,
}
}
}
impl Arbitrary for Block {
type Parameters = LedgerState;

View File

@ -34,42 +34,5 @@ pub mod transaction;
pub mod transparent;
pub mod work;
#[derive(Debug, Clone, Copy)]
#[cfg(any(test, feature = "proptest-impl"))]
#[non_exhaustive]
/// The configuration data for proptest when generating arbitrary chains
pub struct LedgerState {
/// The tip height of the block or start of the chain
pub tip_height: block::Height,
is_coinbase: bool,
/// The network to generate fake blocks for
pub network: parameters::Network,
}
#[cfg(any(test, feature = "proptest-impl"))]
impl LedgerState {
/// Construct a new ledger state for generating arbitrary chains via proptest
pub fn new(tip_height: block::Height, network: parameters::Network) -> Self {
Self {
tip_height,
is_coinbase: true,
network,
}
}
}
#[cfg(any(test, feature = "proptest-impl"))]
impl Default for LedgerState {
fn default() -> Self {
let network = parameters::Network::Mainnet;
let tip_height = parameters::NetworkUpgrade::Canopy
.activation_height(network)
.unwrap();
Self {
tip_height,
is_coinbase: true,
network,
}
}
}
pub use block::LedgerState;

View File

@ -3,13 +3,12 @@ use std::{convert::TryInto, sync::Arc};
use chrono::{TimeZone, Utc};
use proptest::{arbitrary::any, array, collection::vec, option, prelude::*};
use crate::LedgerState;
use crate::{
amount::Amount,
block,
parameters::NetworkUpgrade,
primitives::{Bctv14Proof, Groth16Proof, ZkSnarkProof},
sapling, sprout, transparent,
sapling, sprout, transparent, LedgerState,
};
use super::{FieldNotPresent, JoinSplitData, LockTime, Memo, Transaction};