Skip to content

Commit 09e717c

Browse files
committed
fix(tlb): serialize exotic flag
1 parent df96b88 commit 09e717c

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

crates/tlb/src/cell.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,25 @@ mod tests {
336336
hex!("f345277cc6cfa747f001367e1e873dcfa8a936b8492431248b7a3eeafa8030e7")
337337
);
338338
}
339+
340+
#[test]
341+
fn cell_exotic_serde() {
342+
let expected = Cell {
343+
is_exotic: true,
344+
data: BitVec::from_slice(&[0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
345+
references: vec![Arc::new(Cell {
346+
is_exotic: false,
347+
data: BitVec::from_slice(&[0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
348+
references: vec![],
349+
})],
350+
};
351+
352+
let actual = expected
353+
.to_cell(())
354+
.unwrap()
355+
.parse_fully::<Cell>(NoArgs::EMPTY)
356+
.unwrap();
357+
358+
assert_eq!(actual, expected);
359+
}
339360
}

crates/tlb/src/ser/builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl CellBuilder {
5050
"cannot mark exotic cell with non-empty data: {} bits, {} references",
5151
self.data.len(),
5252
self.references.len(),
53-
)))
53+
)));
5454
}
5555

5656
self.is_exotic = true;
@@ -192,6 +192,9 @@ impl CellSerialize for CellBuilder {
192192
type Args = ();
193193

194194
fn store(&self, builder: &mut CellBuilder, _: Self::Args) -> Result<(), CellBuilderError> {
195+
if self.is_exotic {
196+
builder.exotic()?;
197+
}
195198
builder.write_bitslice(&self.data)?;
196199
builder.store_many_as::<_, Ref>(&self.references, ())?;
197200
Ok(())

crates/tlb/src/ser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ impl CellSerialize for Cell {
132132

133133
#[inline]
134134
fn store(&self, builder: &mut CellBuilder, _: Self::Args) -> Result<(), CellBuilderError> {
135+
if self.is_exotic {
136+
builder.exotic()?;
137+
}
135138
builder.write_bitslice(&self.data)?;
136139
builder.store_many_as::<_, Ref>(&self.references, ())?;
137140

0 commit comments

Comments
 (0)