-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
140 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
use std::convert::TryInto; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
let max_amount_string = if let JsValue::String(js_string) = argv.get(0).unwrap() { | ||
js_string.to_string() | ||
} else { | ||
panic!("conversion from JsValue to JsString failed") | ||
}; | ||
let max_amount: u64 = max_amount_string.parse().unwrap(); | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let max_amount_vec_u8: Vec<u8> = args | ||
.get(0) | ||
.expect("msgCyclesAccept must have one argument") | ||
.to_js_value()? | ||
.try_into()?; | ||
|
||
let max_amount: u64 = candid::decode_one(&max_amount_vec_u8)?; | ||
|
||
let return_js_value: JSValue = | ||
candid::encode_one(ic_cdk::api::call::msg_cycles_accept(max_amount))?.into(); | ||
to_qjs_value(&context, &return_js_value) | ||
context | ||
.new_string(&ic_cdk::api::call::msg_cycles_accept(max_amount).to_string()) | ||
.into() | ||
} | ||
} |
32 changes: 14 additions & 18 deletions
32
src/compiler/rust/canister/src/ic/msg_cycles_accept128.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
use std::convert::TryInto; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
let max_amount_string = if let JsValue::String(js_string) = argv.get(0).unwrap() { | ||
js_string.to_string() | ||
} else { | ||
panic!("conversion from JsValue to JsString failed") | ||
}; | ||
let max_amount: u128 = max_amount_string.parse().unwrap(); | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let max_amount_vec_u8: Vec<u8> = args | ||
.get(0) | ||
.expect("msgCyclesAccept128 must have one argument") | ||
.to_js_value()? | ||
.try_into()?; | ||
|
||
let max_amount: u128 = candid::decode_one(&max_amount_vec_u8)?; | ||
|
||
let return_js_value: JSValue = | ||
candid::encode_one(ic_cdk::api::call::msg_cycles_accept128(max_amount))?.into(); | ||
to_qjs_value(&context, &return_js_value) | ||
context | ||
.new_string(&ic_cdk::api::call::msg_cycles_accept128(max_amount).to_string()) | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
_args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let return_js_value: JSValue = | ||
candid::encode_one(ic_cdk::api::call::msg_cycles_available())?.into(); | ||
to_qjs_value(&context, &return_js_value) | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
context | ||
.new_string(&ic_cdk::api::call::msg_cycles_available().to_string()) | ||
.into() | ||
} | ||
} |
17 changes: 8 additions & 9 deletions
17
src/compiler/rust/canister/src/ic/msg_cycles_available128.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
_args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let return_js_value: JSValue = | ||
candid::encode_one(ic_cdk::api::call::msg_cycles_available128())?.into(); | ||
to_qjs_value(&context, &return_js_value) | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
context | ||
.new_string(&ic_cdk::api::call::msg_cycles_available128().to_string()) | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
_args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let return_js_value: JSValue = | ||
candid::encode_one(ic_cdk::api::call::msg_cycles_refunded())?.into(); | ||
to_qjs_value(&context, &return_js_value) | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
context | ||
.new_string(&ic_cdk::api::call::msg_cycles_refunded().to_string()) | ||
.into() | ||
} | ||
} |
17 changes: 8 additions & 9 deletions
17
src/compiler/rust/canister/src/ic/msg_cycles_refunded128.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
use quickjs_wasm_rs::{to_qjs_value, CallbackArg, JSContextRef, JSValue, JSValueRef}; | ||
use wasmedge_quickjs::{Context, JsFn, JsValue}; | ||
|
||
pub fn native_function<'a>( | ||
context: &'a JSContextRef, | ||
_this: &CallbackArg, | ||
_args: &[CallbackArg], | ||
) -> Result<JSValueRef<'a>, anyhow::Error> { | ||
let return_js_value: JSValue = | ||
candid::encode_one(ic_cdk::api::call::msg_cycles_refunded128())?.into(); | ||
to_qjs_value(&context, &return_js_value) | ||
pub struct NativeFunction; | ||
impl JsFn for NativeFunction { | ||
fn call(context: &mut Context, this_val: JsValue, argv: &[JsValue]) -> JsValue { | ||
context | ||
.new_string(&ic_cdk::api::call::msg_cycles_refunded128().to_string()) | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.