Skip to content

Conversation

@erikzhang
Copy link
Member

Description

Add NFT to TokenManagement

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit Testing
  • Run Application
  • Local Computer Tests
  • No Testing

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@github-actions github-actions bot added the N4 label Dec 5, 2025
{
Notify(engine, "NFTTransfer", uniqueId, from, to);
if (!callOnPayment || to is null || !ContractManagement.IsContract(engine.SnapshotCache, to)) return;
await engine.CallFromNativeContractAsync(Hash, to, "onNFTPayment", uniqueId, from, data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if the NFT creator wants to implement royalty, it will use this callback, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a callback to the receiver contract.

if (nft.Owner != from) return false;
if (!engine.CheckWitnessInternal(from)) return false;
StorageKey key = CreateStorageKey(Prefix_TokenState, nft.AssetId);
TokenState token = engine.SnapshotCache.TryGet(key)!.GetInteroperable<TokenState>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TokenState token = engine.SnapshotCache.TryGet(key)!.GetInteroperable<TokenState>();
TokenState token = engine.SnapshotCache.TryGet(key)!.GetInteroperable<TokenState>();
if (token.Type != TokenType.NonFungible)
throw new InvalidOperationException("The asset id and the token type do not match");

Should not add a check like the fungible case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need. It is obtained through nft.AssetId.

/// </summary>
/// <param name="integer">The integer value to set.</param>
public void Set(BigInteger integer)
public BigInteger Set(BigInteger integer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be void as before, just return the sum in the Add method

[ContractMethod(CpuFee = 1 << 17, StorageFee = 1 << 10, RequiredCallFlags = CallFlags.All)]
internal async Task<UInt160> MintNFT(ApplicationEngine engine, UInt160 assetId, UInt160 account, Map properties)
{
if (properties.Count > 8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assetId is not checked

const FindOptions options = FindOptions.KeysOnly | FindOptions.RemovePrefix;
var prefixKey = CreateStorageKey(Prefix_NFTOwnerUniqueIdIndex, account);
var enumerator = snapshot.Find(prefixKey).GetEnumerator();
return new StorageIterator(enumerator, 21, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return new StorageIterator(enumerator, 21, options);
return new StorageIterator(enumerator, Prefix_NFTOwnerUniqueIdIndex, options);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants