casper_rust_wasm_sdk/js/
externs.rs

1use js_sys::Promise;
2use wasm_bindgen::prelude::*;
3
4/// Logs a message, prefixing it with "log wasm" and sends it to the console in JavaScript when running in a WebAssembly environment.
5/// When running outside WebAssembly, it prints the message to the standard output.
6#[wasm_bindgen]
7extern "C" {
8    #[wasm_bindgen(js_namespace = console, js_name = log)]
9    fn log_with_prefix(s: &str);
10}
11
12/// Logs a message, prefixing it with "log wasm" and sends it to the console in JavaScript when running in a WebAssembly environment.
13/// When running outside WebAssembly, it prints the message to the standard output.
14pub fn log(s: &str) {
15    let prefixed_s = format!("log wasm {}", s);
16    #[cfg(target_arch = "wasm32")]
17    log_with_prefix(&prefixed_s);
18    #[cfg(not(target_arch = "wasm32"))]
19    println!("{}", prefixed_s);
20}
21
22/// Logs an error message, prefixing it with "error wasm" and sends it to the console in JavaScript when running in a WebAssembly environment.
23/// When running outside WebAssembly, it prints the error message to the standard output.
24#[wasm_bindgen]
25extern "C" {
26    #[wasm_bindgen(js_namespace = console, js_name = error)]
27    fn error_with_prefix(s: &str);
28}
29
30/// Logs an error message, prefixing it with "error wasm" and sends it to the console in JavaScript when running in a WebAssembly environment.
31/// When running outside WebAssembly, it prints the error message to the standard output.
32pub fn error(s: &str) {
33    let prefixed_s = format!("error wasm {}", s);
34    #[cfg(target_arch = "wasm32")]
35    error_with_prefix(&prefixed_s);
36    #[cfg(not(target_arch = "wasm32"))]
37    println!("{}", prefixed_s);
38}
39
40#[wasm_bindgen]
41extern "C" {
42    pub(crate) type CasperWalletProvider;
43
44    #[wasm_bindgen(js_name = CasperWalletProvider)]
45    pub(crate) fn casper_wallet_provider() -> CasperWalletProvider;
46
47    #[wasm_bindgen(method, catch, js_class = "CasperWalletProvider")]
48    pub(crate) fn requestConnection(this: &CasperWalletProvider) -> Result<Promise, JsValue>;
49
50    #[wasm_bindgen(method, catch, js_class = "CasperWalletProvider")]
51    pub(crate) fn sign(
52        this: &CasperWalletProvider,
53        deploy: &str,
54        signing_public_key_hex: &str,
55    ) -> Result<Promise, JsValue>;
56
57    #[wasm_bindgen(method, catch, js_class = "CasperWalletProvider")]
58    pub(crate) fn signMessage(
59        this: &CasperWalletProvider,
60        message: &str,
61        signing_public_key_hex: &str,
62    ) -> Result<Promise, JsValue>;
63
64    #[wasm_bindgen(method, catch, js_class = "CasperWalletProvider")]
65    pub(crate) fn requestSwitchAccount(this: &CasperWalletProvider) -> Result<Promise, JsValue>;
66
67    #[wasm_bindgen(method, catch, js_class = "CasperWalletProvider")]
68    pub(crate) fn disconnectFromSite(this: &CasperWalletProvider) -> Result<Promise, JsValue>;
69
70    #[wasm_bindgen(method, catch, js_class = "CasperWalletProvider")]
71    pub(crate) fn isConnected(this: &CasperWalletProvider) -> Result<Promise, JsValue>;
72
73    #[wasm_bindgen(method, catch, js_class = "CasperWalletProvider")]
74    pub(crate) fn getActivePublicKey(this: &CasperWalletProvider) -> Result<Promise, JsValue>;
75
76    #[wasm_bindgen(method, catch, js_class = "CasperWalletProvider")]
77    pub(crate) fn getVersion(this: &CasperWalletProvider) -> Result<Promise, JsValue>;
78}