This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bfe6f1
commit 3268e4c
Showing
15 changed files
with
177 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//! Information about particular Tendermint blockchain networks | ||
|
||
use super::Id; | ||
|
||
/// Information about a particular Tendermint blockchain network | ||
pub struct Chain { | ||
/// ID of a particular chain | ||
pub id: Id, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use super::{Chain, Id}; | ||
use std::{collections::BTreeMap, sync::RwLockReadGuard}; | ||
|
||
/// Wrapper for a `RwLockReadGuard<'static, BTreeMap<Id, Chain>>`, allowing access to | ||
/// global information about particular Tendermint networks / "chains" | ||
pub struct Guard<'lock>(RwLockReadGuard<'lock, BTreeMap<Id, Chain>>); | ||
|
||
impl<'lock> From<RwLockReadGuard<'lock, BTreeMap<Id, Chain>>> for Guard<'lock> { | ||
fn from(guard: RwLockReadGuard<'lock, BTreeMap<Id, Chain>>) -> Guard<'lock> { | ||
Guard(guard) | ||
} | ||
} | ||
|
||
impl<'lock> Guard<'lock> { | ||
/// Get information about a particular chain ID (if registered) | ||
pub fn chain(&self, chain_id: Id) -> Option<&Chain> { | ||
self.0.get(&chain_id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//! Tendermint "chains": metainformation about blockchain networks | ||
|
||
mod chain; | ||
mod guard; | ||
mod registry; | ||
|
||
pub use self::{chain::Chain, guard::Guard, registry::REGISTRY}; | ||
pub use tendermint::chain::Id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Registry of information about known Tendermint blockchain networks | ||
|
||
use super::{Chain, Guard, Id}; | ||
use crate::error::{KmsError, KmsErrorKind::ConfigError}; | ||
use std::{collections::BTreeMap, sync::RwLock}; | ||
|
||
lazy_static! { | ||
pub static ref REGISTRY: Registry = Registry::default(); | ||
} | ||
|
||
/// Registry of blockchain networks known to the KMS | ||
// The `RwLock` is a bit of futureproofing as this data structure is for the | ||
// most part "immutable". New chains should be registered at boot time. | ||
// The only case in which this structure may change is in the event of | ||
// runtime configuration reloading, so the `RwLock` is included as | ||
// futureproofing for such a feature. | ||
// See: <https://github.com/tendermint/kms/issues/183> | ||
#[derive(Default)] | ||
pub struct Registry(RwLock<BTreeMap<Id, Chain>>); | ||
|
||
impl Registry { | ||
/// Acquire a read-only (concurrent) lock to the internal chain registry | ||
pub fn get(&self) -> Guard { | ||
// TODO(tarcieri): better handle `PoisonError` here? | ||
self.0.read().unwrap().into() | ||
} | ||
|
||
/// Register a chain with the registry | ||
pub fn register(&self, chain: Chain) -> Result<(), KmsError> { | ||
// TODO(tarcieri): better handle `PoisonError` here? | ||
let mut chain_map = self.0.write().unwrap(); | ||
|
||
let chain_id = chain.id; | ||
|
||
if chain_map.insert(chain_id, chain).is_none() { | ||
Ok(()) | ||
} else { | ||
// TODO(tarcieri): handle updating the set of registered chains | ||
fail!(ConfigError, "chain ID already registered: {}", chain_id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
//! Configuration for Ledger Tendermint signer | ||
|
||
use crate::chain; | ||
|
||
/// Ledger Tendermint signer configuration | ||
#[derive(Clone, Deserialize, Debug)] | ||
pub struct LedgerTendermintConfig {} | ||
pub struct LedgerTendermintConfig { | ||
/// Chains this signing key is authorized to be used from | ||
pub chains: Vec<chain::Id>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::fmt::{self, Display}; | ||
|
||
/// Enumeration of signing key providers | ||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)] | ||
pub enum SigningProvider { | ||
/// YubiHSM provider | ||
#[cfg(feature = "yubihsm")] | ||
Yubihsm, | ||
|
||
/// Ledger + Tendermint application | ||
#[cfg(feature = "ledgertm")] | ||
LedgerTm, | ||
|
||
/// Software signer (not intended for production use) | ||
#[cfg(feature = "softsign")] | ||
SoftSign, | ||
} | ||
|
||
impl Display for SigningProvider { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
#[cfg(feature = "yubihsm")] | ||
SigningProvider::Yubihsm => write!(f, "yubihsm"), | ||
|
||
#[cfg(feature = "ledgertm")] | ||
SigningProvider::LedgerTm => write!(f, "ledgertm"), | ||
|
||
#[cfg(feature = "softsign")] | ||
SigningProvider::SoftSign => write!(f, "softsign"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters