Skip to content

Commit

Permalink
Fix cbor-in-cbor for byron witnesses
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Aug 3, 2022
1 parent 148156c commit 560c890
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions rust/src/builders/witness_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,4 +878,13 @@ mod tests {

assert!(builder.try_build().is_ok());
}

#[test]
fn tx_witness_set_roundtrip_test() {
let data = "a102818458205e8379f58f0838234af67f73738f0fee0d8185232e200b8e42887f4f06544a9a5840f5cfea560d2f8645ed624b65bf08cf83346eb5168ee4df0f63ce2d0d5f677db88fef2d5d9f032f09223889b5e85504ab44dd0a0cde1f1fd8f57deefde8c2080658202d3b7d9b806f88f10f1193e94ef97e5c02370c1464f61a30a8f1ac1a46115b2d5829a201581e581c072931653330243cf126aea85d39e73c6bd04601fe77424efb9e371002451a4170cb17";
let witness_set = TransactionWitnessSet::from_bytes(hex::decode(data).unwrap()).unwrap();
let round_trip = witness_set.to_bytes();

assert_eq!(data, hex::encode(&round_trip));
}
}
6 changes: 4 additions & 2 deletions rust/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ impl cbor_event::se::Serialize for BootstrapWitness {
self.vkey.serialize(serializer)?;
self.signature.serialize(serializer)?;
serializer.write_bytes(&self.chain_code)?;
self.attributes.serialize(serializer)?;
cbor_event::se::serialize_cbor_in_cbor(&self.attributes, serializer)?;
Ok(serializer)
}
}
Expand Down Expand Up @@ -637,7 +637,9 @@ impl DeserializeEmbeddedGroup for BootstrapWitness {
Ok(raw.bytes()?)
})().map_err(|e| e.annotate("chain_code"))?;
let attributes = (|| -> Result<_, DeserializeError> {
Ok(AddrAttributes::deserialize(raw)?)
let bytes = raw.bytes()?;
let mut inner_cbor = Deserializer::from(std::io::Cursor::new(bytes));
Ok(AddrAttributes::deserialize(&mut inner_cbor)?)
})().map_err(|e| e.annotate("attributes"))?;
Ok(BootstrapWitness {
vkey,
Expand Down

0 comments on commit 560c890

Please sign in to comment.