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

mpl_token_metadata::accounts::Metadata::from_bytes() fails #68

Open
julianbraha opened this issue Nov 28, 2023 · 6 comments
Open

mpl_token_metadata::accounts::Metadata::from_bytes() fails #68

julianbraha opened this issue Nov 28, 2023 · 6 comments

Comments

@julianbraha
Copy link

julianbraha commented Nov 28, 2023

I'm trying to decode some token metadata, and mpl_token_metadata::accounts::Metadata::from_bytes() works for most tokens, but it's failing for 2 that I've found.

The raw data is encoded in base64, so I've written a function like this:

// decode the base64 string, then decode those bytes to metadata
fn decode_base64_to_metadata(data: String) -> Metadata {
    let decoded_base64: Vec<u8> =
        base64::Engine::decode(&base64::engine::general_purpose::STANDARD, data).unwrap();

    Metadata::from_bytes(&decoded_base64).unwrap()
}

But the last line Metadata::from_bytes(&decoded_base64).unwrap() is panicking when I call the function with these two strings:

  1. BIujMfe1f4+f62sriKcmF5frjExh19LNVTFjEoOTb4ZALGkR7Ylov5UYZr/5UvSvSNprO4d+aL0S4JjpVvWiOb4VAAAATG9sbGFwYWxvb3phIDIwMTggQXJ0BgAAADExNDgzMxAAAABsb2xsYXBhbG9vemFhcnQzAAABAQAAAIujMfe1f4+f62sriKcmF5frjExh19LNVTFjEoOTb4ZAAWQAASAgICAgAAABAQAAAIujMfe1f4+f62sriKcmF5frjExh19LNVTFjEoOTb4ZAAWQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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Hh9/FsK4AGQEBAf0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==

The panics I get are:

`Err` value: Custom { kind: InvalidInput, error: "Invalid Option representation: 32. The first byte must be 0 or 1" }

and

`Err` value: Custom { kind: InvalidInput, error: "Invalid Option representation: 51. The first byte must be 0 or 1" }

However, it works just fine for many others, for example:

  • BAJ1ZqOecDcJSJlLWEeVJqYqAzJvsU73TL2Jgt2pFgWBLlGyyN/11z+5nu30lmHn6VqbuESYLKZ6rpEo09v71vEgAAAAQk9CIElTIFRIRSBUSUNLRVIAAAAAAAAAAAAAAAAAAAAKAAAAJEJPQgAAAAAAAMgAAABodHRwczovL2JhZmtyZWlib3pvdmtxeHRybm56aXV3aDR4dm1qMzVkeTZ4azJjYmp2M3dna3U2dW5pcWViZDdjdjd5LmlwZnMubmZ0c3RvcmFnZS5saW5rAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAf8BAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==

If you attempt to decode these using https://www.base64decode.org/, then you'll see in the text that they correspond to Flunk Donkey #5284, BOB IS THE TICKER, and Lollapalooza 2018 Art

I'm using the latest version of the mpl-token-metadata crate (3.2.3) and the latest version of the base64 crate (0.21.5).

@febo
Copy link
Contributor

febo commented Dec 21, 2023

Can you try Metadata::safe_deserialize to see if this works?

@KartikSoneji
Copy link

That does work, at least for the ones I tried.
Thanks!

@taimurey
Copy link

how are you fetching metadata for the token? Tried using find_pda but it returns the program address. is there any method to fetch the data?

@KartikSoneji
Copy link

@taimurey find_pda() will only derive the pda address.
You have to use an RPC Client to actually make an RPC call and fetch the data from the chain.

See: metaboss_lib/src/decode/mod.rs:41-48

pub fn decode_metadata(client: &RpcClient, pubkey: &Pubkey) -> Result<Metadata, DecodeError> {
    let account_data = client
        .get_account_data(pubkey)
        .map_err(|e| DecodeError::ClientError(e.kind))?;


    Metadata::safe_deserialize(&mut account_data.as_ref())
        .map_err(|e| DecodeError::DecodeMetadataFailed(e.to_string()))
}

@taimurey
Copy link

Thanks a lot, Kartik!

@iamnotstatic
Copy link

iamnotstatic commented Apr 7, 2024

I can see this issue is till open this is how i manage to get to work, incase anyone still needs it

let metadata = Metadata::find_pda(&token_a_pub);
let account_data = connection.get_account_data(&metadata.0).unwrap();
let safe_deserialize_data = Metadata::safe_deserialize(&account_data);

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

5 participants