dig_chainsource_interface/provider.rs
1//! Provider-registration descriptors: how a concrete [`ChainSource`](crate::ChainSource) describes
2//! itself to the aggregating registry (its identity, kind, try-order priority, and trust posture).
3
4use std::borrow::Cow;
5
6/// A stable, human-readable identifier for a chain-source provider (e.g. `"coinset.org"`,
7/// `"local-node"`). Borrowed-or-owned so a static provider name costs no allocation.
8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9pub struct ProviderId(pub Cow<'static, str>);
10
11/// The category of a chain-source provider, so the registry can order and trust-weight providers.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum ProviderKind {
14 /// A public oracle/gateway (e.g. coinset.org) — convenient, but trusted only as chain data.
15 PublicOracle,
16 /// A local full/wallet node the operator controls — the most trustworthy source.
17 LocalNode,
18 /// Chain data served over the DIG peer network.
19 DigPeers,
20 /// Any other provider not covered by the categories above.
21 Custom,
22}
23
24/// The self-description a provider hands the registry when it registers.
25///
26/// The registry uses [`priority`](Self::priority) to order providers (lower = tried first) and
27/// [`trustless`](Self::trustless) to reason about whether an answer needs cross-checking.
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct ProviderInfo {
30 /// The provider's stable identifier.
31 pub id: ProviderId,
32 /// The provider's category.
33 pub kind: ProviderKind,
34 /// Try-order priority — lower is tried first.
35 pub priority: i32,
36 /// Whether the provider's answers are independently verifiable (e.g. merkle/lineage-proved)
37 /// rather than taken on trust.
38 pub trustless: bool,
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn provider_info_carries_its_descriptor() {
47 let info = ProviderInfo {
48 id: ProviderId(Cow::Borrowed("coinset.org")),
49 kind: ProviderKind::PublicOracle,
50 priority: 10,
51 trustless: false,
52 };
53 assert_eq!(info.id, ProviderId(Cow::Borrowed("coinset.org")));
54 assert_eq!(info.kind, ProviderKind::PublicOracle);
55 assert_eq!(info.priority, 10);
56 assert!(!info.trustless);
57 }
58}