Skip to content

Commit

Permalink
refactor: refactor to use minicbor decode trait directly
Browse files Browse the repository at this point in the history
- import `decode, decoder, decode` functions from `minicbor` instead of using them with full path.
- refactor `datum` impl block to use `decode` trait from `minicbor` in a more straight forward way.
- change `try_inspect` function to use `decode` trait and `decode` function directly from `minicbor`.
  • Loading branch information
falcucci committed Jan 9, 2024
1 parent c0347b6 commit 55fd951
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mithril-common/src/chain_observer/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{StdError, StdResult};

cfg_fs! {
use serde::Deserialize;
use minicbor::{Decode, Decoder, decode};
use pallas_primitives::{alonzo::PlutusData, ToCanonicalJson};
/// [Datum] represents an inline datum from UTxO.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
Expand All @@ -22,18 +23,18 @@ cfg_fs! {
}
}

impl<'a, C> minicbor::Decode<'a, C> for Datum {
fn decode(d: &mut minicbor::Decoder<'a>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
impl<'a, C> Decode<'a, C> for Datum {
fn decode(d: &mut Decoder<'a>, ctx: &mut C) -> Result<Self, decode::Error> {
PlutusData::decode(d, ctx).map(Datum)
}
}

/// Inspects the given bytes and returns a decoded `R` instance.
pub fn try_inspect<R>(inner: Vec<u8>) -> StdResult<R>
where
for<'b> R: minicbor::Decode<'b, ()>,
for<'b> R: Decode<'b, ()>,
{
minicbor::decode(&inner).map_err(|e| anyhow!(e)).with_context(|| {
decode(&inner).map_err(|e| anyhow!(e)).with_context(|| {
format!(
"failed to decode datum: {}",
hex::encode(&inner)
Expand Down

0 comments on commit 55fd951

Please sign in to comment.