Struct noosphere_core::view::Sphere
source · pub struct Sphere<S: BlockStore> { /* private fields */ }Expand description
High-level Sphere I/O
Implementations§
source§impl<S> Sphere<SphereDb<S>>where
S: Storage,
impl<S> Sphere<SphereDb<S>>where S: Storage,
sourcepub async fn traverse_by_petnames<F, Fut>(
&self,
petname_path: &[String],
replicate: &F
) -> Result<Option<Self>>where
F: Fn(Link<MemoIpld>, Option<Link<MemoIpld>>) -> Fut,
Fut: Future<Output = Result<()>>,
pub async fn traverse_by_petnames<F, Fut>( &self, petname_path: &[String], replicate: &F ) -> Result<Option<Self>>where F: Fn(Link<MemoIpld>, Option<Link<MemoIpld>>) -> Fut, Fut: Future<Output = Result<()>>,
The same as Sphere::traverse_by_petname, but accepts a linear sequence of petnames and attempts to recursively traverse through spheres using that sequence. The sequence is traversed from back to front. So, if the sequence is “gold”, “cat”, “bob”, it will traverse to bob, then to bob’s cat, then to bob’s cat’s gold.
sourcepub async fn traverse_by_petname<F, Fut>(
&self,
petname: &str,
replicate: &F
) -> Result<Option<Self>>where
F: Fn(Link<MemoIpld>, Option<Link<MemoIpld>>) -> Fut,
Fut: Future<Output = Result<()>>,
pub async fn traverse_by_petname<F, Fut>( &self, petname: &str, replicate: &F ) -> Result<Option<Self>>where F: Fn(Link<MemoIpld>, Option<Link<MemoIpld>>) -> Fut, Fut: Future<Output = Result<()>>,
Given a petname that has been assigned to a sphere identity within this sphere’s address book, produce a Sphere backed by the same storage as this one, but that accesses the sphere referred to by the designated Did identity. If the local data for the sphere being traversed to is not available, an attempt will be made to replicate the data from a Noosphere Gateway.
source§impl<S: BlockStore> Sphere<S>
impl<S: BlockStore> Sphere<S>
sourcepub fn at(cid: &Link<MemoIpld>, store: &S) -> Sphere<S>
pub fn at(cid: &Link<MemoIpld>, store: &S) -> Sphere<S>
Initialize a Sphere at the given Cid version; even though a version and BlockStore are provided, the initialized Sphere is lazy and won’t load the associated MemoIpld or SphereIpld unless they are accessed.
sourcepub fn from_memo(memo: &MemoIpld, store: &S) -> Result<Sphere<S>>
pub fn from_memo(memo: &MemoIpld, store: &S) -> Result<Sphere<S>>
Given a memo that refers to a SphereIpld body, compute the memo’s Cid and initialize a Sphere for it.
sourcepub fn store(&self) -> &S
pub fn store(&self) -> &S
Get an immutable reference to the BlockStore that is in use by this Sphere view
sourcepub fn store_mut(&mut self) -> &mut S
pub fn store_mut(&mut self) -> &mut S
Get a mutable reference to the BlockStore that is in use by this Sphere view
sourcepub fn cid(&self) -> &Link<MemoIpld>
pub fn cid(&self) -> &Link<MemoIpld>
Get the CID that points to the sphere’s wrapping memo that corresponds to this revision of the sphere
sourcepub async fn to_body(&self) -> Result<SphereIpld>
pub async fn to_body(&self) -> Result<SphereIpld>
Load the body SphereIpld of this sphere
sourcepub async fn to_bundle(&self) -> Result<Bundle>
pub async fn to_bundle(&self) -> Result<Bundle>
Produce a bundle that contains the sparse set of blocks needed to produce this revision to the sphere
sourcepub async fn get_parent(&self) -> Result<Option<Sphere<S>>>
pub async fn get_parent(&self) -> Result<Option<Sphere<S>>>
Get a Sphere view over the parent revision of the sphere relative to this revision, if one exists
sourcepub async fn get_content(&self) -> Result<Content<S>>
pub async fn get_content(&self) -> Result<Content<S>>
Attempt to load the [Links] of this sphere. If no links have been set for this sphere yet, this initializes an empty [Links] and returns it for the caller to populate.
sourcepub async fn get_address_book(&self) -> Result<AddressBook<S>>
pub async fn get_address_book(&self) -> Result<AddressBook<S>>
Attempt to load the [AddressBook] of this sphere. If no address book is found, an empty one is initialized.
sourcepub async fn get_identity(&self) -> Result<Did>
pub async fn get_identity(&self) -> Result<Did>
Get the Did identity of the sphere
sourcepub async fn derive_mutation(&self) -> Result<SphereMutation>
pub async fn derive_mutation(&self) -> Result<SphereMutation>
Derive the mutation that would be required to produce the current sphere revision given its immediate ancestral parent. Note that this only considers changes that are internal to the sphere, and is not inclusive of the headers of the sphere’s memo.
sourcepub async fn apply_mutation(
&self,
mutation: &SphereMutation
) -> Result<SphereRevision<S>>
pub async fn apply_mutation( &self, mutation: &SphereMutation ) -> Result<SphereRevision<S>>
Apply a mutation to the sphere, producing a new sphere revision that must then be signed as an additional step.
sourcepub async fn apply_mutation_with_cid(
cid: &Link<MemoIpld>,
mutation: &SphereMutation,
store: &mut S
) -> Result<SphereRevision<S>>
pub async fn apply_mutation_with_cid( cid: &Link<MemoIpld>, mutation: &SphereMutation, store: &mut S ) -> Result<SphereRevision<S>>
Apply a mutation to the sphere given a revision CID, producing a new sphere revision that must then be signed as an additional step
sourcepub async fn rebase_version(
cid: &Link<MemoIpld>,
onto: &Link<MemoIpld>,
store: &mut S
) -> Result<SphereRevision<S>>
pub async fn rebase_version( cid: &Link<MemoIpld>, onto: &Link<MemoIpld>, store: &mut S ) -> Result<SphereRevision<S>>
“Rebase” the given version of a sphere so that its change is made with the “onto” version as its base.
sourcepub async fn hydrate_range(
from: Option<&Link<MemoIpld>>,
to: &Link<MemoIpld>,
store: &S
) -> Result<()>
👎Deprecated: Use hydrate_timeslice instead
pub async fn hydrate_range( from: Option<&Link<MemoIpld>>, to: &Link<MemoIpld>, store: &S ) -> Result<()>
“Hydrate” a range of revisions of a sphere. See the comments on
the try_hydrate method for details and implications.
sourcepub async fn hydrate_timeslice<'a>(timeslice: &Timeslice<'a, S>) -> Result<()>
pub async fn hydrate_timeslice<'a>(timeslice: &Timeslice<'a, S>) -> Result<()>
“Hydrate” a range of revisions of a sphere, defined by a Timeslice.
See the comments on the try_hydrate method for details and
implications.
sourcepub async fn hydrate(&self) -> Result<()>
pub async fn hydrate(&self) -> Result<()>
Attempt to “hydrate” the sphere at the current revision by replaying all of the changes that were made according to the sphere’s changelogs. This is necessary if the blocks of the sphere were retrieved using sparse synchronization in order to ensure that interstitial nodes in the various versioned maps (which are each backed by a HAMT) are populated.
sourcepub async fn hydrate_with_cid(cid: &Link<MemoIpld>, store: &mut S) -> Result<()>
pub async fn hydrate_with_cid(cid: &Link<MemoIpld>, store: &mut S) -> Result<()>
Same as try_hydrate, but specifying the CID to hydrate at
sourcepub async fn compact<K>(
&self,
until: &Link<MemoIpld>,
author: &Author<K>
) -> Result<Link<MemoIpld>>where
K: KeyMaterial + Clone + 'static,
pub async fn compact<K>( &self, until: &Link<MemoIpld>, author: &Author<K> ) -> Result<Link<MemoIpld>>where K: KeyMaterial + Clone + 'static,
Compact sphere history through a given version, producing a single combined history that reflects all of the changes of the intermediate versions. The given history version must have a parent version to base the compacted history on top of. The new compacted history will be signed by the given author (authorship of the intermediate versions will be lost).
sourcepub async fn rebase<Credential: KeyMaterial>(
&self,
old_base: &Link<MemoIpld>,
new_base: &Link<MemoIpld>,
credential: &Credential,
authorization: Option<&Authorization>
) -> Result<Link<MemoIpld>>
pub async fn rebase<Credential: KeyMaterial>( &self, old_base: &Link<MemoIpld>, new_base: &Link<MemoIpld>, credential: &Credential, authorization: Option<&Authorization> ) -> Result<Link<MemoIpld>>
Attempt to linearize the canonical history of the sphere by re-basing the history onto a branch with an implicitly common lineage.
sourcepub async fn generate(
owner_did: &str,
store: &mut S
) -> Result<(Sphere<S>, Authorization, Mnemonic)>
pub async fn generate( owner_did: &str, store: &mut S ) -> Result<(Sphere<S>, Authorization, Mnemonic)>
Generate a new sphere and assign a DID as its owner. The returned tuple includes the UCAN authorization that enables the owner to manage the the sphere, as well as a mnemonic string that should be stored side-band by the owner for the case that they wish to transfer ownership (e.g., if key rotation is called for).
sourcepub async fn change_owner(
&self,
mnemonic: &str,
next_owner_did: &str,
current_authorization: &Authorization,
did_parser: &mut DidParser
) -> Result<(Sphere<S>, Authorization)>
👎Deprecated: Use SphereAuthorityWrite::recover_authority instead
pub async fn change_owner( &self, mnemonic: &str, next_owner_did: &str, current_authorization: &Authorization, did_parser: &mut DidParser ) -> Result<(Sphere<S>, Authorization)>
Change ownership of the sphere, producing a new UCAN authorization for the new owner and registering a revocation of the previous owner’s authorization within the sphere.
sourcepub fn into_history_stream(
self,
since: Option<&Link<MemoIpld>>
) -> impl Stream<Item = Result<(Link<MemoIpld>, Sphere<S>)>>
pub fn into_history_stream( self, since: Option<&Link<MemoIpld>> ) -> impl Stream<Item = Result<(Link<MemoIpld>, Sphere<S>)>>
Consume the Sphere and get a [Stream] that yields a (Cid, Sphere)
tuple for each step in the sphere’s history (excluding the version
represented by since). History is traversed in reverse-chronological
order. If None is given for since, the entire history of the sphere
will be streamed.
Verify that a given authorization is a valid with regards to operating on this Sphere; it is issued by the sphere (or appropriately delegated), and it has not been revoked.
sourcepub async fn verify_signature(&self) -> Result<()>
pub async fn verify_signature(&self) -> Result<()>
Validate this sphere revision’s signature and proof chain
sourcepub fn into_identities_changelog_stream(
self,
since: Option<&Link<MemoIpld>>
) -> impl Stream<Item = Result<(Link<MemoIpld>, ChangelogIpld<MapOperation<String, IdentityIpld>>)>>
pub fn into_identities_changelog_stream( self, since: Option<&Link<MemoIpld>> ) -> impl Stream<Item = Result<(Link<MemoIpld>, ChangelogIpld<MapOperation<String, IdentityIpld>>)>>
Consume the Sphere and get a [Stream] that yields the ChangelogIpld for petnames and resolutions at each version of the sphere. This stream will skip versions where no petnames or resolutions changed.
sourcepub fn into_content_changelog_stream(
self,
since: Option<&Link<MemoIpld>>
) -> impl Stream<Item = Result<(Link<MemoIpld>, ChangelogIpld<MapOperation<String, Link<MemoIpld>>>)>>
pub fn into_content_changelog_stream( self, since: Option<&Link<MemoIpld>> ) -> impl Stream<Item = Result<(Link<MemoIpld>, ChangelogIpld<MapOperation<String, Link<MemoIpld>>>)>>
Consume the Sphere and get a [Stream] that yields the ChangelogIpld for content slugs at each version of the sphere. This stream will skip versions where no content changed.