Thoughts on the token standard

the next notation is given in rust

trait IFungibleToken {
  
  // adds a caller's *callback* to the subscriber list, 
  // from now on each time there appears a transfer *from* -> *to*, 
  // the *callback* method will be called asynchronously,
  // without an awaiting
  // 
  //
  // *from* and *to* are filters applied by AND rule:
  //
  // subscribe(Some(Some("aaaa-a")), Some(Some("bbbb-b")), "cb")
  // creates a subscription that is triggered only when there is a transfer
  // from "aaaa-a" to "bbbb-b"
  //
  // subscribe(Some(Some("aaaa-a")), None), "cb")
  // creates a subscription that is triggered only when "aaaa-a" is a sender
  //
  // subscribe(None, Some(Some("bbbb-b")), "cb")
  // creates a subscription that is triggered only when "bbbb-b" is a recipient
  //
  // subscribe(None, None), "cb")
  // creates a subscription that is triggered on each transfer, no matter
  // who are the participants
  fn subscribe(
    from: Option<Option<Principal>>, 
    to: Option<Option<Principal>>,
    callback: String
  );

  // removes the caller's *callback* from the subscriber list
  fn unsubscribe(callback: String);

  // NOT A PART OF THE STANDARD - just for demo purposes
  // calls a subscriber's *callback* method with transfer details as a payload
  fn _publish(
    sub_canister_id: Principal,
    sub_method_name: String,
    from: Option<Principal>,
    to: Option<Principal>,
    qty: u64
  );

  // creates new tokens for *to*
  // calls every callback method subscribed 
  // to *from: Some(None)* or *to: Some(to)*
  fn mint(to: Principal, qty: u64);

  // sends token from caller to *to*
  // calls every callback method subscribed 
  // to *from: Some(caller)* or *to: Some(to)*
  fn send(to: Principal, qty: u64);

  // destroys tokens of the caller
  // calls every callback method subscribed 
  // to *from: Some(caller)* or *to: Some(None)*
  fn burn(qty: u64);

  // returns the balance of *token_holder*
  fn balance_of(token_holder: Principal) -> u64;

  // returns the total amount of tokens in circulation
  fn total_supply() -> u64;

}
3 Likes