Skip to content

Commit 433045a

Browse files
committed
Improve Conway::Tx cbor decoding
1 parent c867fd0 commit 433045a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

pallas-codec/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,11 +1340,11 @@ where
13401340
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
13411341
match d.datatype()? {
13421342
minicbor::data::Type::Null => {
1343-
d.null()?;
1343+
d.skip()?;
13441344
Ok(Self::Null)
13451345
}
13461346
minicbor::data::Type::Undefined => {
1347-
d.undefined()?;
1347+
d.skip()?;
13481348
Ok(Self::Undefined)
13491349
}
13501350
_ => {

pallas-primitives/src/conway/model.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ pub struct Block<'b> {
708708
#[deprecated(since = "1.0.0-alpha", note = "use `Block` instead")]
709709
pub type MintedBlock<'b> = Block<'b>;
710710

711-
#[derive(Clone, Serialize, Deserialize, Encode, Decode, Debug)]
711+
#[derive(Clone, Serialize, Deserialize, Encode, Debug)]
712712
pub struct Tx<'b> {
713713
#[b(0)]
714714
pub transaction_body: KeepRaw<'b, TransactionBody<'b>>,
@@ -723,6 +723,29 @@ pub struct Tx<'b> {
723723
pub auxiliary_data: Nullable<KeepRaw<'b, AuxiliaryData>>,
724724
}
725725

726+
impl<'b, C> minicbor::Decode<'b, C> for Tx<'b>
727+
where
728+
KeepRaw<'b, TransactionBody<'b>>: minicbor::Decode<'b, C>,
729+
KeepRaw<'b, WitnessSet<'b>>: minicbor::Decode<'b, C>,
730+
Nullable<KeepRaw<'b, AuxiliaryData>>: minicbor::Decode<'b, C>,
731+
{
732+
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
733+
d.array()?;
734+
735+
let transaction_body = d.decode_with(ctx)?;
736+
let transaction_witness_set = d.decode_with(ctx)?;
737+
let success = d.decode_with(ctx).unwrap_or(true);
738+
let auxiliary_data = d.decode_with(ctx).unwrap_or(Nullable::Null);
739+
740+
Ok(Self {
741+
transaction_body,
742+
transaction_witness_set,
743+
success,
744+
auxiliary_data,
745+
})
746+
}
747+
}
748+
726749
#[deprecated(since = "1.0.0-alpha", note = "use `Tx` instead")]
727750
pub type MintedTx<'b> = Tx<'b>;
728751

0 commit comments

Comments
 (0)