-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(contract-standards): Refine public API of NFT events #717
Conversation
…es under respective standard
That was our pain on the Indexer side. While we could parse I don't know why it's not in the standard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Let's drop
Data
suffix from public types -- if every type is "Data", than "Data" word adds zero bit of information. -
I am not super thrilled about inconsistency between
.emit()
method andemit_nft_burns
top level functions. What aboutimpl NftBurn { pub fn emit(self) { ... } pub fn emit_many(events: &[NftBurn]) { ... } }
? Not thrilled about this either:
NftBurn::empt_all(&[NftBurn { ... }])
feels stuttery. -
code wise, I suggest putting all the public stuff on top, and then all the private stuff. It took me some seconds to figure out what is and what isn't public API.
-
I am torn about making all the fields public and using things like
&'a [&'a str]
: if what you have is aVec<String>
, than that's an extra allocation! And, if in the end of the day we just serialize to JSON, one can imagine an iterator-based API which does everything on the fly. I think, on balance, the current API is still the best one! +1 on not havingnew
methods for data. -
I am unsure about versioning story here. There's a delicate interplay between the semantic version of the crate, and the version of the standard itself. If we expect standards themselves to evolve, it'd be better if each standard was a separate crate.
-
We might consider making the stuff
: Clone
. -
The fact that types are publicly
: Serialize
is a compatibility hazard. If, in the future, we decide that we want to hand-write serialization for performance/code size reasons, removing serde impl would be semver breaking. If we want to be super-cautious about this, we might want to have a parallel hierarchies of public !Serde / private Serde types. Probably isn't worth it though.
I was thinking the same, I just think the name on its own might be confusing to a developer who might think they need to use this to actually do the transfer, burn, mint. Anyway, I've changed to drop Data suffix.
Yeah, I think I'll keep as-is for conciseness for now. I'm not too worried since we can still change the internal implementation while keeping
Yeah, I'm pretty indifferent about this, but this suggestion might be slightly easier to use in some cases, I've applied it. |
e6585a2
to
56b4436
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of the NftTransfer { ... }.emit()
syntax but this seems to be the least obtuse way of doing it. Was thinking maybe NftTransfer::emit(...)
instead but its purely sugar
You can do this syntax if you want, but to have the params inside typed it would need to be |
@austinabell Do you ask about TL;DR: |
Refactor of the previous API which had way too much public surface area and opportunities to misuse. Also moves the types so that they are under
near_contract_standards::non_fungible_token::events
since that makes more sense than having all events in a separate module for all standards, which it was before.The main thing I'm not sure about is if constructors should be kept as a replacement or in addition to exposing fields of each log type.
Also curious why Nft Burn is not part of standard, because it doesn't seem possible to determine if the token was burned from the external API so it relies on someone to manually implement if they want the burn event log? @telezhnaya @frol maybe you have context here, is it just not necessary?