-
Notifications
You must be signed in to change notification settings - Fork 148
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
feat: add NFT mint/transfer/burn event standard #256
Merged
Merged
Changes from 23 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f9a0885
feat: add batch
ecc0d62
refactor: change interface to typescript
8d8af42
feat: update batch standard
f260197
feat: update standard https://github.com/near/NEPs/issues/254#issueco…
6c68eaa
feat: update docs
e8d9a70
feat: update issue
285003e
feat: add `owner_id` https://github.com/near/NEPs/issues/254#issuecom…
4f54dee
feat: add `event_json` https://github.com/near/NEPs/issues/254#issuec…
d6ec110
feat: update specs/Standards/NonFungibleToken/Event.md
1dcc59f
feat: update specs/Standards/NonFungibleToken/Event.md
2bb7941
feat: update specs/Standards/NonFungibleToken/Event.md
67660a7
feat: update specs/Standards/NonFungibleToken/Event.md
f27284b
feat: update specs/Standards/NonFungibleToken/Event.md
bfb082a
feat: update specs/Standards/NonFungibleToken/Event.md
a7222af
feat: update specs/Standards/NonFungibleToken/Event.md https://github…
76655a0
feat: update specs/Standards/NonFungibleToken/Event.md
d00daef
feat: add single line sentence
6d7d8d4
feat: update specs/Standards/NonFungibleToken/Event.md
02b4e3d
feat: add memo
b99596d
feat: update specs/Standards/NonFungibleToken/Event.md
4dfbd6e
feat: bake `token_ids`
a544365
feat: add delegatee
ebd8412
feat: add delegatee description
b3dbea3
feat: update specs/Standards/NonFungibleToken/Event.md
e3c7f2a
feat: add authorised_id
4de0431
feat: apply suggestions from code review
947e575
feat: update specs/Standards/NonFungibleToken/Event.md
ab02604
feat: update transfer event
6fafebd
feat: add EventJsonLog comment
77cb81c
feat: update `EventJsonLog`
45c6dbe
Created "Events" and "Examples" sections
frol ad4c8c4
feat: use authorized
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Non-Fungible Token Event | ||
|
||
Version `1.0.0` | ||
|
||
## Summary | ||
|
||
Standard interfaces for NFT contract actions. | ||
|
||
## Motivation | ||
|
||
NFT-driven apps perform many similar actions. | ||
For example - `minting`, `burning` and `transferring`. | ||
Each app may have their own way of performing these actions. | ||
This introduces inconsistency in capturing these events. | ||
This extension addresses that. | ||
|
||
It's common for NFT apps to transfer many or one token at a time. | ||
Other applications need to track these and similar events consistently. | ||
If not, tracking state across many NFT-driven apps become infeasible. | ||
|
||
We need a standard way to capture events. | ||
This was discussed here https://github.com/near/NEPs/issues/254. | ||
|
||
## Interface | ||
|
||
Many apps use different interfaces that represent the same action. | ||
This interface standardizes that process. | ||
It captures these actions through logs. | ||
|
||
```ts | ||
// Interface to capture an event | ||
// and return formatted event string. | ||
interface EventJsonLog { | ||
// Takes `EventLogData` and returns | ||
// `EVENT_JSON: <EVENT_LOG_DATA>` | ||
(e:EventLogData):string | ||
} | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
|
||
// Interface to capture data | ||
// about an event | ||
// Arguments | ||
// * `standard`: name of standard e.g. nep171 | ||
// * `version`: e.g. 1.0.0 | ||
// * `event`: `nft_mint` | `nft_burn` | `nft_transfer` | ||
// * `memo`: optional message | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
// * `data`: associate event data | ||
interface EventLogData { | ||
standard:string, | ||
version:string, | ||
event:string, | ||
data: NftMintLog[]|NftTransferLog[]|NftBurnLog[] | ||
} | ||
|
||
// An event log to capture token minting | ||
// Arguments | ||
// * `owner_id`: "account.near" | ||
// * `token_id`: "1" | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
// * `memo`: optional message | ||
interface NftMintLog { | ||
owner_id:string, | ||
token_ids:string[], | ||
memo?:string | ||
} | ||
|
||
// An event log to capture token burning | ||
// Arguments | ||
// * `owner_id`: owner of tokens to burn | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
// * `delegatee_id`: approved account to burn | ||
// * `token_ids`: ["1","2"] | ||
// * `memo`: optional message | ||
interface NftBurnLog { | ||
owner_id:string, | ||
delegatee_id:string, | ||
token_ids:string[], | ||
memo?:string | ||
} | ||
|
||
// An event log to capture token transfer | ||
// Arguments | ||
// * `delegatee_id`: approved account to burn | ||
// * `sender_id`: "account.near" | ||
// * `receiver_id`: "receiver.near" | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
// * `token_id`: "12345abc" | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
// * `memo`: optional message | ||
interface NftTransferLog { | ||
delegatee_id:string, | ||
sender_id:string, | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
receiver_id:string, | ||
token_ids:string[], | ||
memo?:string | ||
} | ||
``` | ||
|
||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
## Further methods | ||
|
||
Note that the example events covered above cover two different kinds of events: | ||
1. Events that are not specified in the NFT Standard (`nft_mint`, `nft_burn`) | ||
2. An event that is covered in the [NFT Core Standard](https://nomicon.io/Standards/NonFungibleToken/Core.html#nft-interface). (`nft_transfer`) | ||
|
||
This event standard also applies beyond the three events highlighted here, where future events follow the same convention of as the second type. For instance, if an NFT contract uses the [approval management standard](https://nomicon.io/Standards/NonFungibleToken/ApprovalManagement.html), it may emit an event for `nft_approve` if that's deemed as important by the developer community. | ||
|
||
Please feel free to open pull requests for extending the events standard detailed here as needs arise. | ||
|
||
## Drawbacks | ||
|
||
There is a known limitation of 16kb strings when capturing logs. | ||
This can be observed if `token_ids` vary in length across different apps. | ||
This impacts the amount of events that can be processed. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It's important to mention here that string representation of json should not contain line breaks (Ideally: get rid of all space symbols unless they are in string fields).
When Indexer parses these lines, for each line, it just cuts off "EVENT_JSON:", trims everything else, and passes the result into json parsing library.
If you pass
It will give an error because there are 3 lines instead of 1, where the first line contains invalid json, second and third lines do not start from "EVENT_JSON:".
We also need to decide, are we OK with other messages here (without "EVENT_JSON:" at the beginning). We need to say explicitly in the NEP, whether we ignore or restrict them
@mikedotexe @frol
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.
Are we sure that we don't want to put everything into json with the structure like
?
It simplifies everything, we don't need to overcomplicate this doc, Indexer does not need the logic with cutting/trimming.
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.
@mikedotexe
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.
@telezhnaya Individual calls to
near_sdk::env::log
are recorded as individual strings in thelogs
array of the execution outcome, so we don't care about new lines inside. We only want to specify that each event should be a separate call to the log host function.Proof: https://explorer.testnet.near.org/transactions/326HmzvgRYND7skVCdTpCnHMji6qiU8JFhQMNuvS2b74

Contract: