This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #752 from holochain/bridges-dna-definition
Bridges DNA definition
- Loading branch information
Showing
6 changed files
with
237 additions
and
5 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
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,66 @@ | ||
use crate::{cas::content::Address, dna::capabilities::Capability}; | ||
use std::collections::BTreeMap; | ||
|
||
/// A bridge is the definition of a connection to another DNA that runs under the same agency, | ||
/// i.e. in the same container. | ||
/// | ||
/// Defining a bridge means that the code in this DNA can call zome functions of that other | ||
/// DNA. | ||
/// | ||
/// The other DNA can either be referenced statically by exact DNA address/hash or dynamically | ||
/// by defining the capabilities that other DNA has to provide in order to be usable as bridge. | ||
/// | ||
/// Bridges can be required or optional. If a required bridge DNA is not installed this DNA | ||
/// can't run, so required bridges are hard dependencies that have to be enforced by the container. | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash)] | ||
pub struct Bridge { | ||
/// Required or optional | ||
pub presence: BridgePresence, | ||
|
||
/// An arbitrary name of this bridge that is used as handle to reference this | ||
/// bridge in according zome API functions | ||
pub handle: String, | ||
|
||
/// Define what other DNA(s) to bridge to | ||
pub reference: BridgeReference, | ||
} | ||
|
||
/// This enum represents the two different ways of referring to another DNA instance. | ||
/// If we know a priori what exact version of another DNA we want to bridge to we can | ||
/// specify the DNA address (i.e. hash) and lock it in. | ||
/// Often, we need more flexibility when | ||
/// * the other DNA gets replaced by a newer version | ||
/// * the other DNA gets created from a template and thus we don't know the exact hash | ||
/// during build-time | ||
/// * we want to build a complex system of components that should be pluggable. | ||
/// Bridges can therefore also be specified by capabilities (read traits or interfaces). | ||
/// That means we specify a list of functions with their signatures and allow the container | ||
/// (through the container bridge config) to resolve this bridge by any DNA instance that | ||
/// implements all specified functions, just like a dynamic binding of function calls. | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash)] | ||
#[serde(untagged)] | ||
pub enum BridgeReference { | ||
/// A bridge reference that defines another DNA statically by its address (i.e. hash). | ||
/// If this variant is used the other DNA gets locked in as per DNA hash | ||
Address { dna_address: Address }, | ||
|
||
/// A bridge reference that defines another DNA loosely by expecting a DNA that implements | ||
/// a given set of capabilities, i.e. that has specific sets of zome functions with | ||
/// matching signatures. | ||
Capability { | ||
capabilities: BTreeMap<String, Capability>, | ||
}, | ||
} | ||
|
||
/// Required or optional | ||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum BridgePresence { | ||
/// A required bridge is a dependency to another DNA. | ||
/// This DNA won't load without it. | ||
Required, | ||
|
||
/// An optional bridge may be missing. | ||
/// This DNA's code can check via API functions if the other DNA is installed and connected. | ||
Optional, | ||
} |
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