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
use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use tracing::{debug, error, info, instrument, span, trace, warn, Level};
use url::Url;

use super::ChainKey;

/// Unique reference to a particular chain-of-trust. The design must
/// partition their data space into seperate chains to improve scalability
/// and performance as a single chain will reside on a single node within
/// the cluster.
#[allow(dead_code)]
#[derive(Serialize, Deserialize, Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct ChainRef {
    pub url: Url,
    pub key: ChainKey,
}

impl std::fmt::Display for ChainRef {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}/{}", self.url, self.key)
    }
}

impl ChainRef {
    pub fn new(url: url::Url, key: ChainKey) -> ChainRef {
        ChainRef { url: url, key: key }
    }

    pub fn to_string(&self) -> String {
        format!("{}/{}", self.url, self.key)
    }
}