Skip to content

Module dev_json_iface.erl

A device that provides a way for WASM execution to interact with the HyperBEAM (and AO) systems, using JSON as a shared data representation.

Description

The interface is easy to use. It works as follows:

  1. The device is given a message that contains a process definition, WASM environment, and a message that contains the data to be processed, including the image to be used in part of execute{pass=1}.
  2. The device is called with execute{pass=2}, which reads the result of the process execution from the WASM environment and adds it to the message.

The device has the following requirements and interface:

       M1/Computed when /Pass == 1 ->
           Assumes:
               M1/priv/wasm/instance
               M1/Process
               M2/Message
               M2/Assignment/Block-Height
           Generates:
               /wasm/handler
               /wasm/params
           Side-effects:
               Writes the process and message as JSON representations into the
               WASM environment.
       M1/Computed when M2/Pass == 2 ->
           Assumes:
               M1/priv/wasm/instance
               M2/Results
               M2/Process
           Generates:
               /Results/Outbox
               /Results/Data

Function Index

aos_stack_benchmark_test_/0*
basic_aos_call_test_/0*
compute/3On first pass prepare the call, on second pass get the results.
denormalize_message/2*Normalize a message for AOS-compatibility.
env_read/3*Read the results out of the execution environment.
env_write/5*Write the message and process into the execution environment.
generate_aos_msg/2
generate_stack/1
generate_stack/2
header_case_string/1*
init/3Initialize the device.
json_to_message/2Translates a compute result -- either from a WASM execution using the JSON-Iface, or from a Legacy CU -- and transforms it into a result message.
maybe_list_to_binary/1*
message_to_json_struct/2
message_to_json_struct/3*
normalize_results/1*Normalize the results of an evaluation.
postprocess_outbox/3*Post-process messages in the outbox to add the correct from-process and from-image tags.
prep_call/3*Prepare the WASM environment for execution by writing the process string and the message as JSON representations into the WASM environment.
prepare_header_case_tags/2*Convert a message without an original-tags field into a list of key-value pairs, with the keys in HTTP header-case.
prepare_tags/2*Prepare the tags of a message as a key-value list, for use in the construction of the JSON-Struct message.
preprocess_results/2*After the process returns messages from an evaluation, the signing node needs to add some tags to each message and spawn such that the target process knows these messages are created by a process.
results/3*Read the computed results out of the WASM environment, assuming that the environment has been set up by prep_call/3 and that the WASM executor has been called with computed{pass=1}.
safe_to_id/1*
tags_to_map/2*Convert a message with tags into a map of their key-value pairs.
test_init/0*

Function Details

aos_stack_benchmark_test_/0 *

aos_stack_benchmark_test_() -> any()

basic_aos_call_test_/0 *

basic_aos_call_test_() -> any()

compute/3

compute(M1, M2, Opts) -> any()

On first pass prepare the call, on second pass get the results.

denormalize_message/2 *

denormalize_message(Message, Opts) -> any()

Normalize a message for AOS-compatibility.

env_read/3 *

env_read(M1, M2, Opts) -> any()

Read the results out of the execution environment.

env_write/5 *

env_write(ProcessStr, MsgStr, Base, Req, Opts) -> any()

Write the message and process into the execution environment.

generate_aos_msg/2

generate_aos_msg(ProcID, Code) -> any()

generate_stack/1

generate_stack(File) -> any()

generate_stack/2

generate_stack(File, Mode) -> any()

header_case_string/1 *

header_case_string(Key) -> any()

init/3

init(M1, M2, Opts) -> any()

Initialize the device.

json_to_message/2

json_to_message(JSON, Opts) -> any()

Translates a compute result -- either from a WASM execution using the JSON-Iface, or from a Legacy CU -- and transforms it into a result message.

maybe_list_to_binary/1 *

maybe_list_to_binary(List) -> any()

message_to_json_struct/2

message_to_json_struct(RawMsg, Opts) -> any()

message_to_json_struct/3 *

message_to_json_struct(RawMsg, Features, Opts) -> any()

normalize_results/1 *

normalize_results(Msg) -> any()

Normalize the results of an evaluation.

postprocess_outbox/3 *

postprocess_outbox(Msg, Proc, Opts) -> any()

Post-process messages in the outbox to add the correct from-process and from-image tags.

prep_call/3 *

prep_call(RawM1, RawM2, Opts) -> any()

Prepare the WASM environment for execution by writing the process string and the message as JSON representations into the WASM environment.

prepare_header_case_tags/2 *

prepare_header_case_tags(TABM, Opts) -> any()

Convert a message without an original-tags field into a list of key-value pairs, with the keys in HTTP header-case.

prepare_tags/2 *

prepare_tags(Msg, Opts) -> any()

Prepare the tags of a message as a key-value list, for use in the construction of the JSON-Struct message.

preprocess_results/2 *

preprocess_results(Msg, Opts) -> any()

After the process returns messages from an evaluation, the signing node needs to add some tags to each message and spawn such that the target process knows these messages are created by a process.

results/3 *

results(M1, M2, Opts) -> any()

Read the computed results out of the WASM environment, assuming that the environment has been set up by prep_call/3 and that the WASM executor has been called with computed{pass=1}.

safe_to_id/1 *

safe_to_id(ID) -> any()

tags_to_map/2 *

tags_to_map(Msg, Opts) -> any()

Convert a message with tags into a map of their key-value pairs.

test_init/0 *

test_init() -> any()