0xMiden / 0xMiden/protocol

Move `NonFungibleAsset` to `miden-standards`

Offen
#3,637 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
standards
Vorherrschende Sprache
Rust
Sterne
132
Forks
167
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
110

Beschreibung

With https://github.com/0xMiden/protocol/pull/3625 `NonFungibleAsset` became a standard asset and so should be moved to `miden-standards`, next to the `NonFungibleFaucet` implementation. It can now be adapted to be specific to that faucet and the logic of `NonFungibleFaucet::compute_asset_commitment` can move to it.

It could be defined as:

```rust
pub struct NonFungibleAsset(Asset);

impl NonFungibleAsset {
pub fn new(faucet_id: AccountId, data: &[u8], salt: Word) -> Self {
let data_digest = Hasher::hash(data);
let value = AssetValue::from_raw(Hasher::merge(&[data_digest, salt]));

let asset_class_suffix = value.as_elements()[0];
let asset_class_prefix = value.as_elements()[1];
let asset_class = AssetClass::new(asset_class_suffix, asset_class_prefix);

let asset_id = AssetId::new(asset_class, faucet_id, AssetComposition::None)
.expect("non-fungible composition is always valid");
let asset = Asset::new(asset_id, value.as_word())
.expect("non-fungible asset should be a valid asset");

Self(asset)
}

// ... public accessors ...
}

impl From for Asset {
fn from(asset: NonFungibleAsset) -> Self {
asset.0
}
}
```

Other required changes are migrating all miden-protocol tests that use `NonFungibleAsset` to a `testing`-only `MockAsset` that uses `AssetComposition::None`.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.