Skip to content

Instantly share code, notes, and snippets.

@SuddenlyHazel
Created June 1, 2021 03:38
Show Gist options
  • Save SuddenlyHazel/0f0ea39d258e1d41955ccbb0c1d277cb to your computer and use it in GitHub Desktop.
Save SuddenlyHazel/0f0ea39d258e1d41955ccbb0c1d277cb to your computer and use it in GitHub Desktop.
Motoko Event Example
actor {
public type NotifyArgs = {
callback : shared (Text) -> async ();
transaction_id : Nat;
metadata : Text;
};
public type TransferError = {
#InsufficientBalance;
#AmountTooLarge;
#CallFailed;
#Unknown;
};
public type TransferResult = {
#Ok : Nat;
#Err : TransferError
};
public type TransferRequest = {
from : ?Principal;
to : Principal;
amount : Nat;
notify : ?NotifyArgs;
};
public shared func transfer(transferRequest : TransferRequest) : async TransferResult {
// Transfer logic above...
switch (transferRequest.notify) {
case (?v) {
ignore v.callback(v.metadata);
};
case (null){};
};
return #Ok(0);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment