Struct holochain::core::ribosome::CallContext
source · pub struct CallContext { /* private fields */ }
Implementations§
source§impl CallContext
impl CallContext
sourcepub fn new(
zome: Zome,
function_name: FunctionName,
host_context: HostContext,
auth: InvocationAuth
) -> Self
pub fn new(
zome: Zome,
function_name: FunctionName,
host_context: HostContext,
auth: InvocationAuth
) -> Self
Examples found in repository?
src/test_utils/host_fn_caller.rs (lines 201-207)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
pub async fn unpack(&self) -> (Arc<RealRibosome>, Arc<CallContext>, HostFnWorkspace) {
let HostFnCaller {
authored_db,
dht_db,
cache,
network,
keystore,
ribosome,
signal_tx,
zome_path,
call_zome_handle,
dht_db_cache,
} = self.clone();
let (cell_id, zome_name) = zome_path.into();
let workspace_lock = HostFnWorkspace::new(
authored_db,
dht_db,
dht_db_cache,
cache,
keystore.clone(),
Some(cell_id.agent_pubkey().clone()),
Arc::new(ribosome.dna_def().as_content().clone()),
)
.await
.unwrap();
let host_access = ZomeCallHostAccess::new(
workspace_lock.clone(),
keystore,
network,
signal_tx,
call_zome_handle,
);
let ribosome = Arc::new(ribosome);
let zome = ribosome.dna_def().get_zome(&zome_name).unwrap();
let call_context = Arc::new(CallContext::new(
zome,
FunctionName::new("not_sure_what_should_be_here"),
host_access.into(),
// Auth as the author.
InvocationAuth::Cap(cell_id.agent_pubkey().clone(), None),
));
(ribosome, call_context, workspace_lock)
}
pub fn zome(&self) -> &Zome
sourcepub fn function_name(&self) -> &FunctionName
pub fn function_name(&self) -> &FunctionName
Examples found in repository?
src/core/ribosome/host_fn/sys_time.rs (line 23)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
pub fn sys_time(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
_input: (),
) -> Result<Timestamp, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
non_determinism: Permission::Allow,
..
} => Ok(holochain_zome_types::Timestamp::now()),
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"sys_time".into(),
)
.to_string(),
)).into()),
}
}
More examples
src/core/ribosome/host_fn/create_x25519_keypair.rs (line 28)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
pub fn create_x25519_keypair(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
_input: (),
) -> Result<X25519PubKey, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess{ keystore: Permission::Allow, .. } => tokio_helper::block_forever_on(async move {
call_context
.host_context
.keystore()
.new_x25519_keypair_random()
.await
.map(|k| (*k).into())
})
.map_err(|keystore_error| wasm_error!(WasmErrorInner::Host(keystore_error.to_string())).into()),
_ => Err(wasm_error!(WasmErrorInner::Host(RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"create_x25519_keypair".into()
).to_string())).into())
}
}
src/core/ribosome/host_fn/verify_signature.rs (line 30)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
pub fn verify_signature(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
input: VerifySignature,
) -> Result<bool, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
keystore_deterministic: Permission::Allow,
..
} => Ok(tokio_helper::block_forever_on(async move {
let VerifySignature {
key,
signature,
data,
} = input;
key.verify_signature_raw(&signature, data.into()).await
})),
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"verify_signature".into(),
)
.to_string(),
))
.into()),
}
}
src/core/ribosome/host_fn/zome_info.rs (line 27)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
pub fn zome_info(
ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
_input: (),
) -> Result<ZomeInfo, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
bindings_deterministic: Permission::Allow,
..
} => ribosome
.zome_info(call_context.zome.clone())
.map_err(|e| match e {
RibosomeError::WasmRuntimeError(wasm_error) => wasm_error,
other_error => wasm_error!(WasmErrorInner::Host(other_error.to_string())).into(),
}),
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"zome_info".into()
)
.to_string()
))
.into()),
}
}
src/core/ribosome/host_fn/sign.rs (line 31)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
pub fn sign(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
input: Sign,
) -> Result<Signature, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
keystore: Permission::Allow,
..
} => tokio_helper::block_forever_on(async move {
call_context
.host_context
.keystore()
.sign(input.key, input.data.into_vec().into())
.await
})
.map_err(|keystore_error| -> RuntimeError {
wasm_error!(WasmErrorInner::Host(keystore_error.to_string())).into()
}),
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"sign".into(),
)
.to_string(),
)).into()),
}
}
src/core/ribosome/host_fn/random_bytes.rs (line 31)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
pub fn random_bytes(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
input: u32,
) -> Result<holochain_types::prelude::Bytes, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
non_determinism: Permission::Allow,
..
} => {
let mut bytes = vec![0; input as _];
getrandom::getrandom(&mut bytes)
.map_err(|error| -> RuntimeError {
wasm_error!(WasmErrorInner::Host(error.to_string())).into()
})?;
Ok(holochain_types::prelude::Bytes::from(bytes))
}
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"random_bytes".into()
)
.to_string()
))
.into()),
}
}
Additional examples can be found in:
- src/core/ribosome/host_fn/emit_signal.rs
- src/core/ribosome/host_fn/dna_info.rs
- src/core/ribosome/host_fn/query.rs
- src/core/ribosome/host_fn/schedule.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_shared_secret_create_random.rs
- src/core/ribosome/host_fn/agent_info.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_encrypt.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_shared_secret_export.rs
- src/core/ribosome/host_fn/sign_ephemeral.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_decrypt.rs
- src/core/ribosome/host_fn/get_details.rs
- src/core/ribosome/host_fn/x_25519_x_salsa20_poly1305_encrypt.rs
- src/core/ribosome/host_fn/delete.rs
- src/core/ribosome/host_fn/x_25519_x_salsa20_poly1305_decrypt.rs
- src/core/ribosome/host_fn/get_agent_activity.rs
- src/core/ribosome/host_fn/get_link_details.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_shared_secret_ingest.rs
- src/core/ribosome/host_fn/create_link.rs
- src/core/ribosome/host_fn/call_info.rs
- src/core/ribosome/host_fn/update.rs
- src/core/ribosome/host_fn/create.rs
- src/core/ribosome/host_fn/delete_link.rs
- src/core/ribosome/host_fn/accept_countersigning_preflight_request.rs
- src/core/ribosome/host_fn/must_get_agent_activity.rs
- src/core/ribosome/host_fn/must_get_entry.rs
- src/core/ribosome/host_fn/must_get_action.rs
- src/core/ribosome/host_fn/must_get_valid_record.rs
- src/core/ribosome/host_fn/call.rs
sourcepub fn host_context(&self) -> HostContext
pub fn host_context(&self) -> HostContext
Examples found in repository?
src/test_utils/host_fn_caller.rs (line 440)
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
pub async fn call_zome_direct(&self, invocation: ZomeCallInvocation) -> ExternIO {
let (ribosome, call_context, workspace_lock) = self.unpack().await;
let (_, output) = {
let host_access = call_context.host_context();
let zcha = unwrap_to!(host_access => HostContext::ZomeCall).clone();
call_zome_function_authorized((*ribosome).clone(), zcha, invocation)
.await
.unwrap()
};
// Write
workspace_lock.flush(&self.network).await.unwrap();
unwrap_to!(output.unwrap() => ZomeCallResponse::Ok).to_owned()
}
More examples
src/core/ribosome/host_fn/sys_time.rs (line 15)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
pub fn sys_time(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
_input: (),
) -> Result<Timestamp, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
non_determinism: Permission::Allow,
..
} => Ok(holochain_zome_types::Timestamp::now()),
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"sys_time".into(),
)
.to_string(),
)).into()),
}
}
src/core/ribosome/host_fn/create_x25519_keypair.rs (line 16)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
pub fn create_x25519_keypair(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
_input: (),
) -> Result<X25519PubKey, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess{ keystore: Permission::Allow, .. } => tokio_helper::block_forever_on(async move {
call_context
.host_context
.keystore()
.new_x25519_keypair_random()
.await
.map(|k| (*k).into())
})
.map_err(|keystore_error| wasm_error!(WasmErrorInner::Host(keystore_error.to_string())).into()),
_ => Err(wasm_error!(WasmErrorInner::Host(RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"create_x25519_keypair".into()
).to_string())).into())
}
}
src/core/ribosome/host_fn/verify_signature.rs (line 15)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
pub fn verify_signature(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
input: VerifySignature,
) -> Result<bool, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
keystore_deterministic: Permission::Allow,
..
} => Ok(tokio_helper::block_forever_on(async move {
let VerifySignature {
key,
signature,
data,
} = input;
key.verify_signature_raw(&signature, data.into()).await
})),
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"verify_signature".into(),
)
.to_string(),
))
.into()),
}
}
src/core/ribosome/host_fn/zome_info.rs (line 14)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
pub fn zome_info(
ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
_input: (),
) -> Result<ZomeInfo, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
bindings_deterministic: Permission::Allow,
..
} => ribosome
.zome_info(call_context.zome.clone())
.map_err(|e| match e {
RibosomeError::WasmRuntimeError(wasm_error) => wasm_error,
other_error => wasm_error!(WasmErrorInner::Host(other_error.to_string())).into(),
}),
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"zome_info".into()
)
.to_string()
))
.into()),
}
}
src/core/ribosome/host_fn/sign.rs (line 14)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
pub fn sign(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
input: Sign,
) -> Result<Signature, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
keystore: Permission::Allow,
..
} => tokio_helper::block_forever_on(async move {
call_context
.host_context
.keystore()
.sign(input.key, input.data.into_vec().into())
.await
})
.map_err(|keystore_error| -> RuntimeError {
wasm_error!(WasmErrorInner::Host(keystore_error.to_string())).into()
}),
_ => Err(wasm_error!(WasmErrorInner::Host(
RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"sign".into(),
)
.to_string(),
)).into()),
}
}
Additional examples can be found in:
- src/core/ribosome/host_fn/random_bytes.rs
- src/core/ribosome/host_fn/emit_signal.rs
- src/core/ribosome/host_fn/dna_info.rs
- src/core/ribosome/host_fn/query.rs
- src/core/ribosome/host_fn/schedule.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_shared_secret_create_random.rs
- src/core/ribosome/host_fn/agent_info.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_encrypt.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_shared_secret_export.rs
- src/core/ribosome/host_fn/sign_ephemeral.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_decrypt.rs
- src/core/ribosome/host_fn/get_details.rs
- src/core/ribosome/host_fn/x_25519_x_salsa20_poly1305_encrypt.rs
- src/core/ribosome/host_fn/delete.rs
- src/core/ribosome/host_fn/x_25519_x_salsa20_poly1305_decrypt.rs
- src/core/ribosome/host_fn/get_agent_activity.rs
- src/core/ribosome/host_fn/get_link_details.rs
- src/core/ribosome/host_fn/x_salsa20_poly1305_shared_secret_ingest.rs
- src/core/ribosome/host_fn/create_link.rs
- src/core/ribosome/host_fn/call_info.rs
- src/core/ribosome/host_fn/update.rs
- src/core/ribosome/host_fn/create.rs
- src/core/ribosome/host_fn/delete_link.rs
- src/core/ribosome/host_fn/accept_countersigning_preflight_request.rs
- src/core/ribosome/host_fn/must_get_agent_activity.rs
- src/core/ribosome/host_fn/must_get_entry.rs
- src/core/ribosome/host_fn/must_get_action.rs
- src/core/ribosome/host_fn/must_get_valid_record.rs
- src/core/ribosome/host_fn/call.rs
sourcepub fn auth(&self) -> InvocationAuth
pub fn auth(&self) -> InvocationAuth
Examples found in repository?
src/core/ribosome/host_fn/call_info.rs (line 21)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
pub fn call_info(
_ribosome: Arc<impl RibosomeT>,
call_context: Arc<CallContext>,
_input: (),
) -> Result<CallInfo, RuntimeError> {
match HostFnAccess::from(&call_context.host_context()) {
HostFnAccess {
bindings: Permission::Allow,
..
} => {
let (provenance, cap_grant) = {
match call_context.auth() {
InvocationAuth::Cap(provenance, cap_secret) => {
let check_function = (
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
);
let check_agent = provenance.clone();
let call_context = call_context.clone();
let cap_grant = tokio_helper::block_forever_on(async move {
Result::<_, WasmError>::Ok(call_context
.host_context
.workspace()
.source_chain()
.as_ref()
.expect("Must have source chain if bindings access is given")
.valid_cap_grant(
check_function,
check_agent,
cap_secret,
).await.map_err(|e| wasm_error!(WasmErrorInner::Host(e.to_string())))?
// This is really a problem.
// It means that the host function calling into `call_info`
// is using a cap secret that never had authorization to call in the first place.
// The host must NEVER allow this so `None` is a critical bug.
.expect("The host is using an unauthorized cap_secret, which should never happen"))
})?;
(provenance, cap_grant)
}
InvocationAuth::LocalCallback => {
let author = call_context
.host_context
.workspace()
.source_chain()
.as_ref()
.expect("Must have source chain if bindings access is given")
.agent_pubkey()
.clone();
(author.clone(), CapGrant::ChainAuthor(author))
}
}
};
Ok(CallInfo {
function_name: call_context.function_name.clone(),
as_at: call_context
.host_context
.workspace()
.source_chain()
.as_ref()
.expect("Must have source chain if bindings access is given")
.persisted_chain_head(),
provenance,
cap_grant,
})
}
_ => Err(wasm_error!(WasmErrorInner::Host(RibosomeError::HostFnPermissions(
call_context.zome.zome_name().clone(),
call_context.function_name().clone(),
"call_info".into()
).to_string())).into())
}
}
Trait Implementations§
source§impl Clone for CallContext
impl Clone for CallContext
source§fn clone(&self) -> CallContext
fn clone(&self) -> CallContext
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for CallContext
impl Send for CallContext
impl Sync for CallContext
impl Unpin for CallContext
impl !UnwindSafe for CallContext
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
TODO: once 1.33.0 is the minimum supported compiler version, remove
Any::type_id_compat and use StdAny::type_id instead.
https://github.com/rust-lang/rust/issues/27745
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> 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> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.§impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
impl<T> Upcastable for Twhere
T: 'static + Any + Send + Sync,
§fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
§fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref