Function hdk::p2p::call_remote

source ·
pub fn call_remote<I, Z>(
    agent: AgentPubKey,
    zome: Z,
    fn_name: FunctionName,
    cap_secret: Option<CapSecret>,
    payload: I
) -> ExternResult<ZomeCallResponse>
where I: Serialize + Debug, Z: Into<ZomeName>,
Expand description

Wrapper for __call_remote host function.

Remote calls differ from local calls because they run on a different agent on the same DNA. Remote calls are synchronous and require an active network connection between local and the remote peer. The remote peer may reject the incoming call and manage capability grants to determine who to selectively grant access to. The call on the remote will run exactly as a local call, all commits will be to the remote source chain NOT the local chain. The only difference between the remote calling itself vs. accepting an incoming remote call will be the provenance of the call visible on the call info.

There are several positional arguments:

  • agent: The address of the agent to call the RPC style remote function on.
  • zome: The zome to call the remote function in. Use zome_info() to get the current zome info.
  • fn_name: The name of the function in the zome to call.
  • cap_secret: Optional cap claim secret to allow access to the remote call.
  • payload: The payload to send to the remote function; receiver needs to deserialize cleanly.

Response is ExternResult which returns ZomeCallResponse of the function call. ZomeCallResponse::NetworkError if there was a network error. ZomeCallResponse::Unauthorized if the provided cap grant is invalid. The unauthorized case should always be handled gracefully because gap grants can be revoked at any time and the claim holder has no way of knowing until they provide a secret for a call.

An Ok response already includes an ExternIO to be deserialized with extern_io.decode()?.

...
let foo: Foo = call_remote(bob, "foo_zome", "do_it", secret, serializable_payload)?;
...