Skip to main content

borderless_abi/
lib.rs

1//! Definition of the wasm interface
2//!
3//! This library does not implement the interface by itself.
4
5#![no_std]
6extern "C" {
7    pub fn print(ptr: u64, len: u64, level: u32);
8
9    // --- Register functions
10    pub fn read_register(register_id: u64, wasm_ptr: u64);
11    pub fn write_register(register_id: u64, wasm_ptr: u64, wasm_ptr_len: u64);
12    pub fn register_len(register_id: u64) -> u64;
13
14    // --- Control flow
15    pub fn panic() -> !;
16    pub fn panic_utf8(len: u64, ptr: u64) -> !;
17
18    // --- Storage API ( Basic )
19    pub fn storage_write(base_key: u64, sub_key: u64, value_ptr: u64, value_len: u64);
20    pub fn storage_read(base_key: u64, sub_key: u64, register_id: u64);
21    pub fn storage_remove(base_key: u64, sub_key: u64);
22    pub fn storage_cursor(base_key: u64) -> u64;
23    pub fn storage_has_key(base_key: u64, sub_key: u64) -> u64;
24
25    // --- Storage API ( Advanced )
26    pub fn storage_gen_sub_key() -> u64; // WARNING: Introduces side-effects ! Use with caution
27    pub fn storage_next_subkey(base_key: u64, from_sub_key: u64) -> u64;
28    pub fn storage_query_subkey_range(base_key: u64, sub_key_start: u64, sub_key_end: u64) -> u64;
29
30    // --- Ledger-API
31    pub fn create_ledger_entry(wasm_ptr: u64, wasm_len: u64) -> u64;
32
33    // Profiling
34    pub fn tic(); // matlab style
35    pub fn toc() -> u64; // << TODO: Let's not do that, but instead print out the result, so we don't create side-effects
36
37    // Testing
38    pub fn rand(min: u64, max: u64) -> u64;
39
40    // --- SW-Agent API
41
42    // Sends a http-request to some remote entity and returns the result
43    //
44    // NOTE: We use registers here instead of pointers to make our live easier,
45    // because we essentially return multiple values from this function with unknown size.
46    pub fn send_http_rq(
47        register_rq_head: u64,
48        register_rq_body: u64,
49        register_rs_head: u64,
50        register_rs_body: u64,
51        register_failure: u64,
52    ) -> u64;
53
54    // Returns the current timestamp as milliseconds since epoch
55    pub fn timestamp() -> i64;
56
57    // Send a message via websocket
58    pub fn send_ws_msg(msg_ptr: u64, msg_len: u64) -> u64;
59
60    // Subscribes to a new topic (only applicable to SwAgents)
61    pub fn subscribe(wasm_ptr: u64, wasm_len: u64) -> u64;
62
63    // Unsubscribes from a topic (only applicable to SwAgents)
64    pub fn unsubscribe(wasm_ptr: u64, wasm_len: u64) -> u64;
65}
66
67#[derive(Debug)]
68#[repr(u32)]
69pub enum LogLevel {
70    Trace = 0,
71    Debug = 1,
72    Info = 2,
73    Warn = 3,
74    Error = 4,
75}