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 #1213

Closed
cold-briu opened this issue Nov 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@cold-briu
Copy link
Contributor

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,
}

First incidence reported here.

@cold-briu
Copy link
Contributor Author

cold-briu commented Nov 23, 2023

Please check this blocker issue for further details.

@hal3e
Copy link
Contributor

hal3e commented May 8, 2024

With the new encoding (v1) this is not an issue anymore.

@hal3e hal3e closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants