1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::borrow::Cow;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{Pool, PoolSlug};
/// Mining pool with block statistics for a time period
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
pub struct PoolStats {
/// Unique pool identifier
#[serde(rename = "poolId")]
pub pool_id: u8,
/// Pool name
pub name: Cow<'static, str>,
/// Pool website URL
pub link: Cow<'static, str>,
/// Number of blocks mined in the time period
#[serde(rename = "blockCount")]
pub block_count: u64,
/// Pool ranking by block count (1 = most blocks)
pub rank: u32,
/// Number of empty blocks mined
#[serde(rename = "emptyBlocks")]
pub empty_blocks: u64,
/// URL-friendly pool identifier
pub slug: PoolSlug,
/// Pool's share of total blocks (0.0 - 1.0)
pub share: f64,
}
impl PoolStats {
/// Create a new PoolStats from a Pool reference
pub fn new(pool: &'static Pool, block_count: u64, rank: u32, share: f64) -> Self {
Self {
pool_id: pool.unique_id(),
name: Cow::Borrowed(pool.name),
link: Cow::Borrowed(pool.link),
block_count,
rank,
empty_blocks: 0, // TODO: track empty blocks if needed
slug: pool.slug(),
share,
}
}
}