C-3PFLO / flow-rpg

RPG your NFT
1 stars 0 forks source link

Refactor Attachment #20

Open C-3PFLO opened 1 year ago

C-3PFLO commented 1 year ago

Per discussion here: https://discord.com/channels/613813861610684416/1090817311000244336

Attachments are meant to be a glue to add behavior/state but not directly the behavior/state itself. So instead of

pub attachment RPGCharacter for NonFungibleToken.INFT {
  // my valuable state and behavior here
}

where anyone can create and attach the RPGCharacter in a transaction, it should be

pub resource RPGCharacter {
  // my valuable state and behavior here
}

pub attachment RPGAttacher for NonFungibleToken.INFT {
  pub fun attachRPG(rpg: RPGCharacter) {
    base.rpg: <- rpg
  }
}

Then RPGAttacher is "open" for users to add/remove "freely", but the creation of RPGCharacter can be gated following traditional patterns.

C-3PFLO commented 1 year ago

It's not clear how you could prevent someone from removing the RPGCharacter from their NFT, ex: if it should be permanent (including if the character "dies").

There's no way to prevent someone from removing the RPGAttacher which would need to remove the RPGCharacter in it's destroy function (and it is an anti-pattern to always panic in destroy since that would also prevent destroying the parent NFT).

You could disincentivize it by gating the RPGAttacher constructor function. Then it would cost to attach the first time, free to remove/destroy and then cost again to attach a replacement.

C-3PFLO commented 1 year ago

Maybe the naming convention should be something like RPGMixin