txpipe / pallas

Rust-native building blocks for the Cardano blockchain ecosystem
Apache License 2.0
150 stars 60 forks source link

Upgrade minicbor past 0.20.0 #513

Closed SupernaviX closed 1 month ago

SupernaviX commented 2 months ago

👋

The pallas projects use minicbor version 0.20.0. If you make a new project with the latest pallas and minicbor libs, and try decoding a transaction,

use anyhow::Result;
use pallas_primitives::conway::Tx;

fn parse(tx_bytes: &[u8]) -> Result<Tx> {
    let tx: Tx = minicbor::decode(&tx_bytes).context("Invalid transaction")?;
    Ok(tx)
}

You get strange errors about the Decode impl not being found, and it takes some debugging to realize that they're due to a version mismatch. This minicbor version is a year old, would it be possible to upgrade to the latest?

scarmuega commented 1 month ago

we'll update the minicbor lib but since it's an integral part of Pallas, I want to make sure we can run end-to-end tests that make sure we can decode the whole history of Cardano mainnet / preview / preprod / sanchonet.

In the meantime, unless you have specific requirements, my recommendation is to rely on pallas_codec::minicbor. This is a re-export of the lib that you can use throughout your code while making sure it's compatible with Pallas.

You could do the following to avoid those weird errors you're getting:

fn parse(tx_bytes: &[u8]) -> Result<Tx> {
    let tx: Tx = pallas_codec::minicbor::decode(&tx_bytes).context("Invalid transaction")?;
    Ok(tx)
}
scarmuega commented 1 month ago

actually, I see that we're already at 0.20. Closing the issue but JFYI, we'll probably be moving to 0.24 in the short term.