aptos-core
aptos-core copied to clipboard
[aptos-token] Add OwnerStore to support get latest owner of token id
Description
Currently in aptos-token
, unable to get the latest token owner. This means that changes in token ownership cannot be detected in the contract
In this PR, we're adding a OwnerStore
table to store token_id
and the latest owner
, and add some related functions
-
fun owner_upsert(token_id: TokenId, owner: address)
: Add or update thelatest owner
of thetoken_id
. -
fun owner_remove(token_id: TokenId)
: Remove thelatest owner
bytoken_id
. -
public fun latest_owner_of(token_id: TokenId): Option<address>
: Retrieve thelatest owner
by thetoken_id
. -
public fun is_latest_owner(account: address, token_id: TokenId): bool
: Check if the specified account and the owner of token_id are equal.
Important
-
Similar to ERC721, only one
owner
hold the token, that is aretoken_id
andowner
in one-to-one correspondence. In this PR, it will be works correct.
In this case, it is often necessary to obtain the latest owner of thetoken_id
. -
Similar to ERC1155, many
owners
hold the same token, that is a token_id can correspond to manyowners
. In this PR, it will be overwritten by the latest detected owner.
Test Plan
unit tests
Does anyone have a review ? if I'm wrong please point it out. I only changed the move code, the code inside aptos-core is a bit difficult for me, I can't fix the tests
Does anyone have a review ? if I'm wrong please point it out. I only changed the move code, the code inside aptos-core is a bit difficult for me, I can't fix the tests
You can use events from token store to get notified of ownership change
You can use events from token store to get notified of ownership change
@areshand
Thank you for your reply. The change of ownership can be notified to the off-chain system through event. But it cannot handle the scenario of calling between contracts on the chain.
Such as the Domain Name System
:
(1) test.apt
is a NFT(aptos-token).
(2) test.apt
is bound to 0xaaa
address.
(3) test.apt
is resolved to 0xaaa
address.
Now test.apt
is transferred to 0xbbb
address, to which address test.apt
should be resolved ?
There are two ways of handling:
(1) 0xbbb
rebind test.apt
to 0xbbb
:
The Domain Name System
is unable to detect changes in domain ownership in a timely manner.
test.apt
should still be resolved to 0xaaa
before rebinding.
(2) aptos-token
provides the latest_owner_of
interface:
The Domain Name System
can resolve test.apt
to 0xbbb
in time after test.apt
is transferred without relying on other operations.
As an aptos nft standard, aptos-token
should provide a similar interface for other contracts to call, not just detect ownership changes through off-chain systems
ship can be notified to the off-chain system through event. But it cannot handle the scenario of calling between contracts on the chain.
Such as the
Domain Name System
: (1)test.apt
is a NFT(aptos-token).
This requires maintain a mapping between the name service token and all their owner. I think this is an ideal usecase for indexer. If you want the logic to purely happen on-chain, the application contract can maintain this mapping itself instead of having it in the standard. For example, you can deploy a contract to create name service tokens, which maintains a mapping between the owner address and the token.