fix(network): handle end of list in tx monitor response (#305)
This commit is contained in:
parent
b07f88459c
commit
d12fe799eb
1 changed files with 24 additions and 8 deletions
|
|
@ -80,14 +80,19 @@ impl<'b> Decode<'b, ()> for Message {
|
|||
// find the specs
|
||||
4 => Ok(Message::AwaitAcquire),
|
||||
5 => Ok(Message::RequestNextTx),
|
||||
6 => match d.datatype()? {
|
||||
pallas_codec::minicbor::data::Type::Array
|
||||
| pallas_codec::minicbor::data::Type::ArrayIndef => {
|
||||
let tx = d.decode()?;
|
||||
Ok(Message::ResponseNextTx(Some(tx)))
|
||||
}
|
||||
_ => Ok(Message::ResponseNextTx(None)),
|
||||
},
|
||||
6 => match d.datatype() {
|
||||
Ok(datatype) => {
|
||||
match datatype {
|
||||
pallas_codec::minicbor::data::Type::Array
|
||||
| pallas_codec::minicbor::data::Type::ArrayIndef => {
|
||||
let tx = d.decode()?;
|
||||
Ok(Message::ResponseNextTx(Some(tx)))
|
||||
}
|
||||
_ => Ok(Message::ResponseNextTx(None))
|
||||
}
|
||||
},
|
||||
Err(_) => Ok(Message::ResponseNextTx(None))
|
||||
}
|
||||
7 => {
|
||||
let id = d.decode()?;
|
||||
Ok(Message::RequestHasTx(id))
|
||||
|
|
@ -130,4 +135,15 @@ pub mod tests {
|
|||
unreachable!();
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn test_empty_next_tx_response() {
|
||||
let bytes = vec![129, 6];
|
||||
let msg: super::Message = pallas_codec::minicbor::decode(&bytes).unwrap();
|
||||
|
||||
if let super::Message::ResponseNextTx(None) = msg {
|
||||
assert_eq!(0u64, 0u64);
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue