Skip to content
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

Can't invoke SRC7 metadata method from the rust SDK due to arbitrary nesting of heap types #38

Closed
cold-briu opened this issue Nov 9, 2023 · 3 comments

Comments

@cold-briu
Copy link

Motivation

Description

Can't invoke SRC7 metadata method from the rust SDK due to arbitrary nesting of heap types
Since metadata Returns an Option wrapping an Enum that evaluate to string.

let meta = contract_instance
        .methods()
        .metadata(asset_id, "key".to_string())
        .simulate()
        .await
        .unwrap();

Throws the following error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidType("Enums currently support only one level deep heap types.")

contract_instance comes from the following implementation:

contract;

use src_7::{Metadata, SRC7};
use std::{call_frames::contract_id, hash::Hash, storage::storage_string::*, string::String};

impl SRC7 for Contract {
    #[storage(read)]
    fn metadata(asset: AssetId, key: String) -> Option<Metadata> {
        if key == String::from_ascii_str("key") {
            Some(Metadata::String(String::from_ascii_str("value")))
        } else {
            None
        }
    }
}

Then, the execution should return something like:

let result: Option<Enum<String>> = SRC7.metadata(myAsset, myKey);

Considering:

/// Universal return type for metadata.
pub enum Metadata {
    // Used when the stored metadata is a `b256`.
    B256: b256,
    /// Used when the stored metadata is `Bytes`.
    Bytes: Bytes,
    /// Used when the stored metadata is a `u64`.
    Int: u64,
    /// Used when the stored metadata is a `String`.
    String: String,
}

Is this an implementation error, sdk limitation o src7 error? 🤔

@bitzoic
Copy link
Member

bitzoic commented Nov 10, 2023

This is an SDK limitation

@mpoplavkov
Copy link

Could this be resolved either in the standard or on the SDK side? That's important for ecosystem projects if you want them to support the standard
@cold-briu
@bitzoic

@cold-briu
Copy link
Author

Closing since it's out of scope: SDK Limitation.
Please check fuels-rs/issues/1213.

@cold-briu cold-briu closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants