import Nat64 "mo:base/Nat64";
import Cycles "mo:base/ExperimentalCycles";
shared(msg) actor class HelloCycles (
capacity: Nat
) {
var balance = 0;
//Return the current cycle balance
public shared(msg) func wallet_balance() : async Nat {
return balance;
};
//Return the cycles received up to the capacity allowed
public func wallet_receive() : async { accepted: Nat64 } {
let amount = Cycles.available();
let limit = capacity - balance;
let accepted =
if (amount <= limit) amount
else limit;
let deposit = Cycles.accept(accepted);
assert (deposit == accepted);
balance += accepted;
{ accepted = Nat64.fromNat(accepted) };
};
//Return the greeting
public func greet(name : Text) : async Text {
return "Hello, " # name # "!";
};
//Return the principal of the caller/user identity
public shared(msg) func owner() : async Principal {
let currentOwner = msg.caller;
return currentOwner;
};
};