Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Bridge call roundtrip #779

Merged
merged 23 commits into from
Dec 21, 2018
Merged

Bridge call roundtrip #779

merged 23 commits into from
Dec 21, 2018

Conversation

lucksus
Copy link
Collaborator

@lucksus lucksus commented Dec 19, 2018

Context

This is basic bridging. But no checks and no capability tokens. If the bridge is set in the config the caller can call any zome function of the callee.

screenshot 2018-12-19 at 22 52 45

hdk::call for bridge calls

Added instance handle to hdk::call(), which can also be hdk::THIS_INSTANCE to call other local zomes.

hdk::call("test-callee", "greeter", "public", "token", "hello", JsonString::from("{}"))

implement bridged call via Context::container_api

core/src/nucleus/ribosome/api/call.rs:

    let handler = container_api.write().unwrap();

    let id = ProcessUniqueId::new();
    let request = format!(
        r#"{{"jsonrpc": "2.0", "method": "{}", "params": {}, "id": "{}"}}"#,
        method, input.fn_args, id
    );

    let response = handler
        .handle_request_sync(&request)
        .ok_or("Bridge call failed".to_string())?;

Bridge roundtrip test in container_api crate

The test container config sets up a caller and a callee instance. The callee is created completely in the tests section in container.rs with WAT code. In there is a function "hello" that returns the string "Holo World" (set as ascii in WAT). The caller is the new WASM Rust project "test-bridge-caller" so I can use hdk::call. Test shows that "Holo World" arrives at the caller side.

@lucksus lucksus added the review label Dec 19, 2018
@lucksus lucksus changed the base branch from develop to capabilities December 19, 2018 21:39
@lucksus lucksus changed the title WIP: Bridge call Bridge call Dec 19, 2018
@lucksus lucksus changed the title Bridge call Bridge call roundtrip Dec 19, 2018
callee_id = "test-instance-1"
handle = "DPKI"
handle = "test-callee"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handle is the "instance_handle" that the bridge caller has to provide to hdk::call to reference this bridged instance.



fn handle_call_bridge() -> JsonString {
hdk::call("test-callee", "greeter", "public", "token", "hello", JsonString::from("{}")).unwrap()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"test-callee" is the handle set in the container config for this bridge. This actually has to be defined in the DNA but currently the container does not enforce these handles to match up (next PR). Then we will also have a way of defining the needed bridges in the define_zome! macro below. A bridge handle would then be like the declaration of binding: if declared in the zome as required, zome code can expect a call to such a bridge to work because the container would not load a config in which a matching bridge definition was missing..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, it kind of looks like hdk::call should accept a struct maybe, instead of so many params

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, though it will lose at least one again soon when the capability stuff is completely switched to tokens..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly. also the capability name is in the current call and that will go away too.

# Conflicts:
#	core/src/nucleus/ribosome/api/call.rs


fn handle_call_bridge() -> JsonString {
hdk::call("test-callee", "greeter", "public", "token", "hello", JsonString::from("{}")).unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, it kind of looks like hdk::call should accept a struct maybe, instead of so many params

wasm_utils/src/api_serialization/call.rs Show resolved Hide resolved
@zippy zippy changed the base branch from capabilities to develop December 20, 2018 05:24
Copy link
Member

@zippy zippy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super great. Woot!

.unwrap();

// "Holo World" comes for the callee_wat above which runs in the callee instance
assert_eq!(result, JsonString::from(RawString::from("Holo World")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woot woot!!!



fn handle_call_bridge() -> JsonString {
hdk::call("test-callee", "greeter", "public", "token", "hello", JsonString::from("{}")).unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly. also the capability name is in the current call and that will go away too.

@lucksus lucksus merged commit 1f5adb3 into develop Dec 21, 2018
@lucksus lucksus removed the review label Dec 21, 2018
@lucksus lucksus deleted the bridge-call branch January 9, 2019 13:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants