-
-
Save SuddenlyHazel/8a482f38e3e3a21811e266d32ddb83d2 to your computer and use it in GitHub Desktop.
Events with Method References
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
#[derive(CandidType, Deserialize)] | |
struct NotifyArgs { | |
pub callback: candid::Func, | |
pub transaction_id: candid::Nat, | |
pub metadata: String, | |
} | |
#[derive(CandidType, Deserialize)] | |
enum TransferError { | |
InsufficientBalance, | |
AmountTooLarge, | |
CallFailed, | |
Unknown | |
} | |
#[derive(CandidType, Deserialize)] | |
enum TransferResult { | |
Ok(candid::Nat), | |
Err(TransferError), | |
} | |
#[derive(CandidType, Deserialize)] | |
struct TransferRequest { | |
pub from: Option<candid::Principal>, | |
pub to: candid::Principal, | |
pub amount: candid::Nat, | |
pub notify: Option<NotifyArgs>, | |
} | |
#[update] | |
async fn transfer(transfer_request : TransferRequest) -> TransferResult { | |
// Transfer logic above... | |
let a = transfer_request.notify.borrow(); | |
ic_cdk::print(a.is_some().to_string()); | |
match transfer_request.notify { | |
Some(v) => { | |
ic_cdk::print("Here"); | |
let _ = call::<(String,),()>(v.callback.principal, v.callback.method.as_str(), (v.metadata, )).await; | |
} | |
_ => {} | |
} | |
return TransferResult::Ok(candid::Nat::from(0)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment