Skip to content

Commit

Permalink
fix init and post upgrade method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jan 16, 2024
1 parent 8a6a1cb commit 940afb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
10 changes: 3 additions & 7 deletions examples/init/src/index.did
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
type rec_0 = record {id:text};
type rec_1 = variant {Fire; Wave};
type rec_2 = record {id:text};
type rec_3 = variant {Fire; Wave};
service: (rec_0, rec_1, principal) -> {
getUser: () -> (opt rec_2) query;
getReaction: () -> (opt rec_3) query;
service: (record {id:text}, variant {Fire; Wave}, principal) -> {
getOwner: () -> (opt principal) query;
getReaction: () -> (opt variant {Fire; Wave}) query;
getUser: () -> (opt record {id:text}) query;
}
12 changes: 6 additions & 6 deletions src/compiler/rust/canister_methods/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {
let init_method = quote! {
#[ic_cdk_macros::init]
fn init() {
unsafe { ic_wasi_polyfill::init(&[], &[]); }
ic_wasi_polyfill::init(&[], &[]);

let mut rt = wasmedge_quickjs::Runtime::new();

Expand All @@ -74,8 +74,6 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {
// };

// ic_cdk::println!("temp: {:#?}", temp);

#init_method_call
});

ic_cdk::println!("init result: {:#?}", r);
Expand All @@ -84,6 +82,8 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {
let mut runtime = runtime.borrow_mut();
*runtime = Some(rt);
});

#init_method_call
}
};

Expand All @@ -100,7 +100,7 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {
let post_update_method = quote! {
#[ic_cdk_macros::post_upgrade]
fn post_upgrade() {
unsafe { ic_wasi_polyfill::init(&[], &[]); }
ic_wasi_polyfill::init(&[], &[]);

let mut rt = wasmedge_quickjs::Runtime::new();

Expand All @@ -120,8 +120,6 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {
// };

// ic_cdk::println!("temp: {:#?}", temp);

#post_update_method_call
});

ic_cdk::println!("post_upgrade result: {:#?}", r);
Expand All @@ -130,6 +128,8 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {
let mut runtime = runtime.borrow_mut();
*runtime = Some(rt);
});

#post_update_method_call
}
};

Expand Down

0 comments on commit 940afb0

Please sign in to comment.