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

to_json crash on MIRToStakeCredentials #115

Closed
SebastienGllmt opened this issue Aug 23, 2022 · 1 comment · Fixed by #116
Closed

to_json crash on MIRToStakeCredentials #115

SebastienGllmt opened this issue Aug 23, 2022 · 1 comment · Fixed by #116
Labels
bug Something isn't working

Comments

@SebastienGllmt
Copy link
Contributor

SebastienGllmt commented Aug 23, 2022

Any transaction that contains a MIR certificate crashes when calling to_json. This may be caused by our good old friend linked_hash_map

Crash log:

Err` value: JsError { msg: "to_json: key must be a string" }

Steps to reproduce

#[test]
    fn foo_bar() {
        let mut cred = MIRToStakeCredentials::new();
        cred.insert(
        &StakeCredential::from_keyhash(
            &Ed25519KeyHash::from_bytes(
                hex::decode("b861eeadde300385d88aaa98cad0f0ed1f95419bbb9971a0fb7c96fb").unwrap()
            ).unwrap()
        ),
        &Int::from_str("5").unwrap()
        );
        println!("{}", cred.to_json().unwrap());
    }
@SebastienGllmt SebastienGllmt added the bug Something isn't working label Aug 23, 2022
@SebastienGllmt
Copy link
Contributor Author

SebastienGllmt commented Aug 23, 2022

I believe the root cause is a missing implementation of serde::Serialize for StakeCredential such as

impl serde::Serialize for TransactionMetadatum {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where S: serde::Serializer {
        let json_str = decode_metadatum_to_json_str(self, MetadataJsonSchema::DetailedSchema)
            .map_err(|e| serde::ser::Error::custom(&format!("{:?}", e)))?;
        serializer.serialize_str(&json_str)
    }
}

Note sure why the derived implementation doesn't give us what we want

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

Successfully merging a pull request may close this issue.

1 participant