I want to write Motoko code that will add cycles to another (not the same as the current actor) canister as necessary.
To add cycles only as necessary, it would be beneficial to know the amount of cycles that the canister already has. But available
and balance
(BTW, what is the difference?) return amount of cycles for the current canister only. (BTW, it would be a great feature addition to query cycles of another canister.)
So, how to do this? Is it a good idea to add a query
function that will return the number of cycles of the canister? Should I call this function before every other Motoko call to the canister, to count how many cycles to .add()
?
It is all because I have a potentially infinite tree of canisters (the tree is going to have 3 levels) and don’t want to add cycles to a canister, if it is already “rich” in cycles, to save money.