rmrk-tools
rmrk-tools copied to clipboard
NFT and Collection need a static "fromConsolidated" method
A conoslidated NFT looks like this:
It contains all the information of what happened to it. If we build a fromConsolidated
static call into Collection and NFT, we can have an instance of such an entity which is up to date with the recent state of the world, without having to reconsolidate against the entire set.
Normal instantiation does not keep track of changes and has no idea what happened to an entity since genesis, so needs full reconsolidation. But with changelogs being included by default alongside every consolidated entity, we have an advantage in that we can rebuild that corner of the entity's world accurately and as up to date as the consolidated set we're fetching from is.
This then lets us easily call child functions like list
, emote
, changeissuer
etc on the instantiated up-to-date entity.
Another example of why this is useful:
const n = new NFT( ...);
n.list(...) // ok?
vs
const n = NFT.fromConsolidated(nft);
n.list(...) // Can't list if you're not the owner!! < --- CAN DO CHECKS live, without full set to read from