Questions about EarmarkedCoin

Hi there,

I don’t get the claim_for_creator function in the EarmarkedCoin module:

  // Allow the creator of the earmarked coin to reclaim it.
  public claim_for_creator(): R#Self.T {
    let t: R#Self.T;
    let coin: R#LibraCoin.T;
    let recipient: address;
    let sender: address;

    sender = get_txn_sender();
    // This will fail if no resource of type T under the sender's address.
    t = move_from<T>(move(sender));
    return move(t);
  1. Why is recipient defined, but never used? Shouldn’t this result in a compiler error or at least warning?
  2. What happens here? If the sender Alice calls this function, the Resource is returned from Alice to Alice? Is it just to be able to access the Resource, as it is returned by the function?

I tried to remove recipient and it still compiles. Why is it included in the samples then?

I understand that people around here have a lot of other things to do, but this forum doesn’t feel like a techie-learners-stupid-questions-quickly-answered forum.
That’s ok, but it would be great if there was some forum like this. The Telegramgroups are cool, but still not very good for these kind of questions. Would be great to hear of some (self-organized) dev learners forum.

Yes, If the creator Alice calls this function, the Resource is returned from Alice to Alice. The script should looks like this:

import 0x0.LibraAccount;
import 0x0.LibraCoin;
import {{sender}}.EarmarkedLibraCoin;

main() {
  let coin: LibraCoin.T;
  let earmarked_coin: EarmarkedLibraCoin.T;
  let sender: address;

  earmarked_coin = EarmarkedLibraCoin.claim_for_creator();
  coin = EarmarkedLibraCoin.unwrap(move(earmarked_coin));

  sender = get_txn_sender();
  LibraAccount.deposit(move(sender), move(coin));
1 Like