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,

source

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.

source

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>

source

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.

source

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.

source

pub fn store(&self) -> &S

Get an immutable reference to the BlockStore that is in use by this Sphere view

source

pub fn store_mut(&mut self) -> &mut S

Get a mutable reference to the BlockStore that is in use by this Sphere view

source

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

source

pub async fn to_memo(&self) -> Result<MemoIpld>

Load the wrapping MemoIpld of the sphere data

source

pub async fn to_body(&self) -> Result<SphereIpld>

Load the body SphereIpld of this sphere

source

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

source

pub async fn bundle_until_ancestor( &self, cid: Option<&Link<MemoIpld>> ) -> Result<Bundle>

Produce a bundle that contains the sparse set of blocks needed to produce a series of sequential revisions of this sphere, up to but excluding the given Link (or until the genesis revision of the sphere if no Link is given).

source

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

source

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.

source

pub async fn get_authority(&self) -> Result<Authority<S>>

Attempt to load the Authority of this sphere. If no authorizations or revocations have been added to this sphere yet, this initializes an empty Authority and returns it for the caller to populate.

source

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.

source

pub async fn get_identity(&self) -> Result<Did>

Get the Did identity of the sphere

source

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.

source

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.

source

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

source

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.

source

pub async fn hydrate_range( from: Option<&Link<MemoIpld>>, to: &Link<MemoIpld>, store: &S ) -> Result<()>

👎Deprecated: Use hydrate_timeslice instead

“Hydrate” a range of revisions of a sphere. See the comments on the try_hydrate method for details and implications.

source

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.

source

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.

source

pub async fn hydrate_with_cid(cid: &Link<MemoIpld>, store: &mut S) -> Result<()>

Same as try_hydrate, but specifying the CID to hydrate at

source

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).

source

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.

source

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).

source

pub 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

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.

source

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.

source

pub async fn verify_authorization( &self, authorization: &Authorization ) -> Result<(), NoosphereError>

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.

source

pub async fn verify_signature(&self) -> Result<()>

Validate this sphere revision’s signature and proof chain

source

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.

source

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.

Trait Implementations§

source§

impl<S: Clone + BlockStore> Clone for Sphere<S>

source§

fn clone(&self) -> Sphere<S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for Sphere<S>

§

impl<S> Send for Sphere<S>

§

impl<S> Sync for Sphere<S>

§

impl<S> Unpin for Sphere<S>where S: Unpin,

§

impl<S> !UnwindSafe for Sphere<S>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> References<RawCodec> for T

source§

fn references<R, E>(_c: RawCodec, _r: &mut R, _set: &mut E) -> Result<(), Error>where R: Read, E: Extend<Cid<64>>,

Scrape the references from an impl Read. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<S> ConditionalSend for Swhere S: Send,

source§

impl<S> ConditionalSync for Swhere S: Send + Sync,

source§

impl<S> TargetConditionalSendSync for Swhere S: Send + Sync,

source§

impl<T> TryBundleSendSync for Twhere T: Send + Sync,

source§

impl<U> UcanStoreConditionalSend for Uwhere U: Send,

source§

impl<U> UcanStoreConditionalSendSync for Uwhere U: Send + Sync,