Skip to content

feat!: Separate fungible and non-fungible assets#5308

Merged
dima74 merged 6 commits intohyperledger-iroha:mainfrom
dima74:diralik/separate-store-assets
Feb 27, 2025
Merged

feat!: Separate fungible and non-fungible assets#5308
dima74 merged 6 commits intohyperledger-iroha:mainfrom
dima74:diralik/separate-store-assets

Conversation

@dima74
Copy link
Copy Markdown
Contributor

@dima74 dima74 commented Feb 7, 2025

Context

Currently, there are two asset types: Numeric and Store. Because they are quite different entities, it is proposed to separate them. See #4087 for details.

Solution

This PR removes Store asset type and instead introduces new Nft entity. Nft is similar to AssetDefinition (from implementation point of view), see #4672 (comment) for types visualization.

Naming:

  • NFT (added):
    • nft$domain
  • Numeric assets (no change):
    • asset#domain#account@domain or asset##account@domain

ISI changes:

  • Before:
    • Both numeric and store assets:
      • Register<Asset> / Unregister<Asset>
    • Only for numeric assets:
      • Mint<Numeric, Asset> / Burn<Numeric, Asset>
      • Transfer<Asset, Numeric, Account>
    • Only for store assets:
      • Transfer<Asset, Metadata, Account>
        • Transfer asset from one account to another
        • Very strange instruction, first of all Metadata argument is ignored. Also looks like we have bug in implementation, and asset is not moved, but copied
      • SetKeyValue<Asset>
        • Creates asset implicitly if it is not registered
      • RemoveKeyValue<ASset>
  • After:
    • Numeric assets or just assets:
      • No register/unregister instructions. Use Mint<Numeric, Asset> instead of register, and Burn<Numeric, Asset> to zero value instead of unregister.
      • Mint<Numeric, Asset> / Burn<Numeric, Asset>
      • Transfer<Asset, Numeric, Account>
    • Nft:
      • Register<Nft> / Unregister<Nft>
      • Transfer<Account, NftId, Account>
        • Transfer NFT to another account
      • SetKeyValue<Nft>
        • Error if NFT is not registered
      • RemoveKeyValue<Nft>

Queries changes:

  • Added query FindNfts

Permission changes:

  • Removed permissions:
    • CanRegisterAsset / CanUnregisterAsset
    • CanModifyAssetMetadata
  • Added permissions:
    • CanRegisterNft / CanUnregisterNft
    • CanTransferNft
    • CanModifyNftMetadata

Migration Guide

If you use only numeric assets, and don't use store assets:

  • Removed Register<Asset> / Unregister<Asset> ISI for numeric assets.
    • Use Mint<Numeric, Asset> instead of Register<Asset>
    • Use Burn<Numeric, Asset> to zero value instead of Unregister<Asset>
  • Asset changes: value field was inlined (previously had type AssetValue, now has type Numeric)
  • AssetDefinition changes: type_: AssetType field was replaced with spec: NumericSpec field
  • genesis.json: it is needed to change from
"Register": {
  "AssetDefinition": {
    "type": "Numeric",
    ...

to

"Register": {
  "AssetDefinition": {
    "spec": {
      "scale": null
    },
    ...

(if you had "type": "Numeric(N)", replace with "scale": N)

If you use store assets:

  • Removed AssetDefinition::store, AssetType::Store, AssetValue::Store. Use Nft instead
  • Detailed description of changes is in the Solution section

Review notes

Files with important changes:

  • crates/iroha_data_model/src/nft.rs - New structs Nft and NftId
  • crates/iroha_data_model/src/asset.rs - Changes to Asset and AssetDefinition
  • crates/iroha_core/src/smartcontracts/isi/nft.rs - ISI and Queries implementation for NFT
  • crates/iroha_executor/src/default/mod.rs - default executor visit_* methods for NFT
  • crates/iroha_cli/src/main.rs - CLI changes

Todo:

  • Fix python tests (e.g. test_register_asset_definitions.py)

Checklist

  • I've read CONTRIBUTING.md.
  • (optional) I've written unit tests for the code changes.
  • All review comments have been resolved.
  • All CI checks pass.

@dima74 dima74 added the api-changes Changes in the API for client libraries label Feb 7, 2025
@dima74 dima74 self-assigned this Feb 7, 2025
@github-actions github-actions bot added the config-changes Changes in configuration and start up of the Iroha label Feb 7, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 7, 2025

@BAStos525

Comment thread crates/iroha_data_model/src/nft.rs Outdated
Comment thread crates/iroha_core/src/smartcontracts/isi/nft.rs Outdated
Comment thread crates/iroha_core/src/smartcontracts/isi/nft.rs
@s8sato s8sato self-assigned this Feb 10, 2025
Comment thread crates/iroha_data_model/src/nft.rs
Comment thread crates/iroha_executor/src/permission.rs Outdated
Comment thread crates/iroha_cli/src/main.rs
Comment thread crates/iroha_core/src/smartcontracts/isi/nft.rs Outdated
Comment thread crates/iroha_executor/src/permission.rs Outdated
Copy link
Copy Markdown
Contributor

@mversic mversic left a comment

Choose a reason for hiding this comment

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

IMO this looks great. @0x009922 what do you think?

@0x009922 0x009922 self-assigned this Feb 20, 2025
Copy link
Copy Markdown
Contributor

@0x009922 0x009922 left a comment

Choose a reason for hiding this comment

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

IMO looks great too!

Finally, this separation makes sense, and it's easier to understand how to use both types.

Comment thread crates/iroha_core/src/smartcontracts/isi/nft.rs Outdated
Comment thread crates/iroha_core/src/smartcontracts/isi/nft.rs Outdated
Comment thread defaults/genesis.json
@dima74 dima74 force-pushed the diralik/separate-store-assets branch 2 times, most recently from 20431ef to f2820cf Compare February 24, 2025 17:58
Signed-off-by: Dmitry Murzin <diralik@yandex.ru>
Signed-off-by: Dmitry Murzin <diralik@yandex.ru>
Signed-off-by: Dmitry Murzin <diralik@yandex.ru>
Signed-off-by: Dmitry Murzin <diralik@yandex.ru>
Signed-off-by: Dmitry Murzin <diralik@yandex.ru>
Signed-off-by: Dmitry Murzin <diralik@yandex.ru>
@dima74 dima74 force-pushed the diralik/separate-store-assets branch from f2820cf to ced33ed Compare February 27, 2025 21:10
@dima74
Copy link
Copy Markdown
Contributor Author

dima74 commented Feb 27, 2025

@s8sato suggested to merge this PR and finish remaining tasks separately (opened #5335 and #5336)

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

Labels

api-changes Changes in the API for client libraries config-changes Changes in configuration and start up of the Iroha

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[suggestion] Eliminate AssetType inconsistencies

4 participants