pub struct ContextClient { /* private fields */ }Expand description
A client for interacting with the context management system.
This struct serves as the primary public API, providing methods to create, join, query, and manage contexts and their members. It orchestrates interactions between the datastore, background actors, and external networks.
Implementations§
Source§impl ContextClient
impl ContextClient
Sourcepub fn new_identity(&self) -> Result<PublicKey>
pub fn new_identity(&self) -> Result<PublicKey>
Creates a new cryptographic identity (key pair) and stores it in the datastore.
The private key is randomly generated.
The new identity doesn’t have any sender_key. If needed, the sender_key could be set via
update_identity() method later.
§Note
This identity is not initially tied to a specific context (it is stored under a
zeroed-out ContextId). It can be seen as a “global” identity within the node
that can later be associated with one or more contexts.
§Returns
A Result containing the PublicKey of the newly created identity.
§Errors
Returns an error if there is an issue writing the new identity to the datastore.
Sourcepub fn get_identity(
&self,
context_id: &ContextId,
public_key: &PublicKey,
) -> Result<Option<ContextIdentity>>
pub fn get_identity( &self, context_id: &ContextId, public_key: &PublicKey, ) -> Result<Option<ContextIdentity>>
Retrieves an identity from the datastore for a given context.
§Arguments
context_id- The context in which the identity is being retrieved.public_key- The public key of the identity to fetch.
§Returns
An Option containing the ContextIdentity if found, otherwise None.
§Errors
Returns an error if there is an issue reading from the datastore.
Sourcepub fn update_identity(
&self,
context_id: &ContextId,
new_identity: &ContextIdentity,
) -> Result<()>
pub fn update_identity( &self, context_id: &ContextId, new_identity: &ContextIdentity, ) -> Result<()>
Updates an existing identity in the datastore.
This is typically used to add or change the sender_key or private_key
for an identity that the node already knows about.
§Arguments
context_id- The context of the identity to update.new_identity- TheContextIdentityobject containing the updated fields.
§Errors
Returns an error if the identity does not exist or if there is a datastore issue.
Source§impl ContextClient
impl ContextClient
pub fn context_config( &self, context_id: &ContextId, ) -> Result<Option<ContextConfigParams<'static>>>
Source§impl ContextClient
impl ContextClient
pub const fn external_client<'a>( &'a self, context_id: &ContextId, config: &'a ContextConfigParams<'a>, ) -> Result<ExternalClient<'a>>
Source§impl ContextClient
impl ContextClient
pub async fn sync_context_config( &self, context_id: ContextId, config: Option<ContextConfigParams<'_>>, ) -> Result<Context>
Source§impl ContextClient
impl ContextClient
pub const fn new( datastore: Store, node_client: NodeClient, external_client: ExternalClient<AnyTransport>, context_manager: LazyRecipient<ContextMessage>, ) -> Self
Sourcepub fn datastore_handle(&self) -> Handle<Store>
pub fn datastore_handle(&self) -> Handle<Store>
Returns a handle to the datastore for direct access. Used by node components that need to read stored data.
Sourcepub async fn create_context(
&self,
protocol: String,
application_id: &ApplicationId,
identity_secret: Option<PrivateKey>,
init_params: Vec<u8>,
seed: Option<[u8; 32]>,
) -> Result<CreateContextResponse>
pub async fn create_context( &self, protocol: String, application_id: &ApplicationId, identity_secret: Option<PrivateKey>, init_params: Vec<u8>, seed: Option<[u8; 32]>, ) -> Result<CreateContextResponse>
Sends a request to create a new context.
This operation is asynchronous and is handled by the ContextManager actor.
§Arguments
protocol- The name of the protocol that will be used for the new context.application_id- The ID of the application that will run in the context.identity_secret- An optional private key to use for the initial identity. If not provided, a new identity will be generated.init_params- Raw byte parameters for initializing the application state.seed- An optional 32-byte seed for deterministic context ID and identity creation.
§Returns
A Result containing the CreateContextResponse from the actor upon completion.
Sourcepub async fn invite_member(
&self,
context_id: &ContextId,
inviter_id: &PublicKey,
invitee_id: &PublicKey,
) -> Result<Option<ContextInvitationPayload>>
pub async fn invite_member( &self, context_id: &ContextId, inviter_id: &PublicKey, invitee_id: &PublicKey, ) -> Result<Option<ContextInvitationPayload>>
Invites a new member to an existing context.
This involves an external call to the on-chain contract to register the new member.
§Arguments
context_id- The context to invite the member to.inviter_id- The public key of an existing member who is performing the invitation.invitee_id- The public key of the identity being invited.
§Returns
- A
Resultcontaining anOptionwith the shareableContextInvitationPayload. - Returns
Ok(None)if the context configuration cannot be found locally.
Sourcepub async fn invite_member_by_open_invitation(
&self,
context_id: &ContextId,
inviter_id: &PublicKey,
valid_for_blocks: BlockHeight,
_secret_salt: [u8; 32],
) -> Result<Option<SignedOpenInvitation>>
pub async fn invite_member_by_open_invitation( &self, context_id: &ContextId, inviter_id: &PublicKey, valid_for_blocks: BlockHeight, _secret_salt: [u8; 32], ) -> Result<Option<SignedOpenInvitation>>
Creates and signs a one-time, expiring open invitation for a new member.
This method allows an existing member of a context (the inviter) to generate a shareable invitation. The method fetches the inviter’s private key managed by the local node, signs the invitation details, and returns the resulting payload and signature.
§Arguments
context_id- The context to invite the new member to.inviter_id- The public key of the existing member creating the invitation. This node must have the corresponding private key for this identity.valid_for_blocks- A number of blocks from the current block height for which the invitation is considered to be valid.secret_salt- A 32-byte random value to ensure the invitation is unique.
§Returns
- A
Resultcontaining theSignedOpenInvitationif successful, or an error if the inviter’s private key is not found or signing fails. - Returns
Ok(None)if the context configuration cannot be found locally.
Sourcepub async fn join_context(
&self,
invitation_payload: ContextInvitationPayload,
) -> Result<JoinContextResponse>
pub async fn join_context( &self, invitation_payload: ContextInvitationPayload, ) -> Result<JoinContextResponse>
Sends a request to join a context using an invitation payload.
This is an asynchronous operation handled by the ContextManager actor. The actor
will parse the payload, validate the information, and configure the local node
to participate in the specified context.
§Arguments
invitation_payload- The opaqueContextInvitationPayloadreceived from an inviter.
§Returns
A Result containing the JoinContextResponse from the actor upon completion.
Sourcepub async fn join_context_by_open_invitation(
&self,
signed_invitation: SignedOpenInvitation,
new_member_public_key: &PublicKey,
) -> Result<Option<JoinContextResponse>>
pub async fn join_context_by_open_invitation( &self, signed_invitation: SignedOpenInvitation, new_member_public_key: &PublicKey, ) -> Result<Option<JoinContextResponse>>
Sends a request to join a context using the new commit-reveal open invitation flow.
This is an asynchronous operation handled by the ContextManager actor. The actor
will parse the payload, validate the information, and configure the local node
to participate in the specified context.
§Arguments
invitation_payload- The opaqueContextInvitationPayloadreceived from an inviter.
§Returns
- A
Resultcontaining theJoinContextResponsefrom the actor upon completion. - Returns
Ok(None)if the context configuration cannot be found locally.
Sourcepub fn has_context(&self, context_id: &ContextId) -> Result<bool>
pub fn has_context(&self, context_id: &ContextId) -> Result<bool>
Sourcepub fn update_dag_heads(
&self,
context_id: &ContextId,
dag_heads: Vec<[u8; 32]>,
) -> Result<()>
pub fn update_dag_heads( &self, context_id: &ContextId, dag_heads: Vec<[u8; 32]>, ) -> Result<()>
Sourcepub fn update_context_application_id(
&self,
context_id: &ContextId,
application_id: ApplicationId,
) -> Result<()>
pub fn update_context_application_id( &self, context_id: &ContextId, application_id: ApplicationId, ) -> Result<()>
Sourcepub fn compute_root_hash(&self, context_id: &ContextId) -> Result<[u8; 32]>
pub fn compute_root_hash(&self, context_id: &ContextId) -> Result<[u8; 32]>
Computes the actual root hash from storage by reading the root Index entry.
This reads the EntityIndex for Id::root() from RocksDB and extracts the Merkle full_hash. This is the authoritative hash computed from the actual state, not a claimed value.
§Arguments
context_id- The ID of the context to compute the root hash for.
§Returns
The computed root hash, or [0; 32] if no root index exists (empty state).
Sourcepub fn force_root_hash(
&self,
context_id: &ContextId,
root_hash: Hash,
) -> Result<()>
pub fn force_root_hash( &self, context_id: &ContextId, root_hash: Hash, ) -> Result<()>
Forces the root hash for a context to a specific value.
WARNING: This bypasses verification and should only be used when
the hash has already been verified or during controlled operations.
Prefer compute_root_hash + set_root_hash for safety.
§Arguments
context_id- The ID of the context to update.root_hash- The root hash to set.
§Returns
A Result indicating success or failure.
Sourcepub fn verify_root_hash(
&self,
context_id: &ContextId,
claimed_hash: [u8; 32],
) -> Result<()>
pub fn verify_root_hash( &self, context_id: &ContextId, claimed_hash: [u8; 32], ) -> Result<()>
Verifies that the stored root hash matches the actual state.
Computes the root hash from storage and compares with the claimed hash. Returns Ok(()) if they match, or an error describing the mismatch.
§Arguments
context_id- The ID of the context to verify.claimed_hash- The hash to verify against.
§Returns
A Result indicating success if hashes match, or an error if they don’t.
Sourcepub fn get_context_ids(
&self,
start: Option<ContextId>,
) -> impl Stream<Item = Result<ContextId>>
pub fn get_context_ids( &self, start: Option<ContextId>, ) -> impl Stream<Item = Result<ContextId>>
Sourcepub fn get_context_members(
&self,
context_id: &ContextId,
owned: Option<bool>,
) -> impl Stream<Item = Result<(PublicKey, bool)>>
pub fn get_context_members( &self, context_id: &ContextId, owned: Option<bool>, ) -> impl Stream<Item = Result<(PublicKey, bool)>>
Retrieves and returns a stream of all members of a given context.
§Arguments
context_id- The context to query for members.owned- IfSome(true), the stream returns only members for which this node holds the private key. IfSome(false)orNone, it returns all members.
§Returns
A stream of tuples (PublicKey, bool), where the boolean indicates if the identity is owned.
Sourcepub async fn execute(
&self,
context_id: &ContextId,
executor: &PublicKey,
method: String,
payload: Vec<u8>,
aliases: Vec<Alias<PublicKey>>,
atomic: Option<ContextAtomic>,
) -> Result<ExecuteResponse, ExecuteError>
pub async fn execute( &self, context_id: &ContextId, executor: &PublicKey, method: String, payload: Vec<u8>, aliases: Vec<Alias<PublicKey>>, atomic: Option<ContextAtomic>, ) -> Result<ExecuteResponse, ExecuteError>
Sends a request to execute a method within a context.
This is the primary way to interact with the application running inside a context.
The request is handled asynchronously by the ContextManager actor.
§Arguments
context_id- The ID of the context where the execution should occur.executor- The public key of the identity performing the execution. The executor must be a member of the context.method- The string name of the application method to call.payload- The input data (e.g., serialized JSON) for the method.aliases- A list of public key aliases to use for this specific execution.atomic- An optional handle for batching multiple executions into an atomic transaction.
§Returns
A Result containing the ExecuteResponse on success, or an ExecuteError on failure.
Sourcepub async fn update_application(
&self,
context_id: &ContextId,
application_id: &ApplicationId,
identity: &PublicKey,
migrate_method: Option<String>,
) -> Result<()>
pub async fn update_application( &self, context_id: &ContextId, application_id: &ApplicationId, identity: &PublicKey, migrate_method: Option<String>, ) -> Result<()>
Sends a request to update the application for a given context.
This is an asynchronous operation handled by the ContextManager actor.
§Arguments
context_id- The ID of the context where to update the application.application_id- The ID of the new application to switch to.identity- The public key of the member authorizing the update.migrate_method- Optional name of the migration function to execute.
§Returns
An empty Result indicating the outcome of the application update request.
Sourcepub async fn delete_context(
&self,
context_id: &ContextId,
) -> Result<DeleteContextResponse>
pub async fn delete_context( &self, context_id: &ContextId, ) -> Result<DeleteContextResponse>
Sends a request to delete a context from the local node.
This is an asynchronous operation handled by the ContextManager actor. It will remove
all associated data for the context from the local datastore.
§Arguments
context_id- The ID of the context to delete.
§Returns
A Result containing the DeleteContextResponse from the actor.
Trait Implementations§
Source§impl Clone for ContextClient
impl Clone for ContextClient
Source§fn clone(&self) -> ContextClient
fn clone(&self) -> ContextClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ContextClient
impl !UnwindSafe for ContextClient
impl Freeze for ContextClient
impl Send for ContextClient
impl Sync for ContextClient
impl Unpin for ContextClient
impl UnsafeUnpin for ContextClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Error = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Error>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Reflect for T
impl<T> Reflect for T
fn as_dyn_ref<'a>(&self) -> &(dyn Reflect + 'a)where
T: 'a,
fn as_dyn_mut<'a>(&mut self) -> &mut (dyn Reflect + 'a)where
T: 'a,
fn as_dyn_box<'a>(self: Box<T>) -> Box<dyn Reflect + 'a>where
T: 'a,
fn as_dyn_rc<'a>(self: Rc<T>) -> Rc<dyn Reflect + 'a>where
T: 'a,
fn as_dyn_arc<'a>(self: Arc<T>) -> Arc<dyn Reflect + 'a>where
T: 'a,
fn type_id(&self) -> TypeId
fn type_name(&self) -> &'static str
Source§impl<T> ReflectExt for T
impl<T> ReflectExt for T
fn is<T>(&self) -> bool
fn type_id() -> TypeId
fn downcast_ref<T>(&self) -> Option<&T>where
T: Reflect,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: Reflect,
fn downcast_box<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>where
T: Reflect,
fn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>where
T: Reflect,
fn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>where
T: Reflect,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.