openmina / mina-p2p-messages-rs

0 stars 0 forks source link

Can't deserialize ShiftedValue - s from JSONs #31

Closed adonagy closed 1 year ago

adonagy commented 1 year ago

Example:

...

#[derive(Debug, Deserialize)]
struct PartialDeferredValues {
    combined_inner_product: PicklesProofProofsVerified2ReprStableV2StatementFp
}

let raw = r#"{"combined_inner_product":["Shifted_value","0x2BA90D5E3D6E4A54295760341B8C8EB0CDA4CA27AA48B34024D0E5BFED981917"]}"#;

// this fails
let des: PartialDeferredValues = serde_json::from_str(raw).unwrap();

println!("Des: {:?}", des);
...

The error:

Error("expected value", line: 1, column: 27)

In JSON:

"combined_inner_product": [
          "Shifted_value",
          "0x2BA90D5E3D6E4A54295760341B8C8EB0CDA4CA27AA48B34024D0E5BFED981917"
        ]

The core of the problem is that PicklesProofProofsVerified2ReprStableV2StatementFp type is an enum with a single ShiftedValue variant. And in the JSON mina uses a very "specific" list with the first element being "Shifted_value" string followed by the actual shifted value