Skip to content

Commit 84072f1

Browse files
Fix Cell.cs
Fix: Added empty refs collection check in Cell constructor Before computing the maximum level from the refs collection, a check is now performed to ensure that the collection is not empty. If the collection is empty, the level is set to 0 (explicitly cast to byte), preventing the "Sequence contains no elements" exception during cell construction.
1 parent d68f608 commit 84072f1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

TonLibDotNet/Cells/Cell.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class Cell
99
public const int MaxBitsCount = 1023;
1010
public const int MaxRefs = 4;
1111

12-
public Cell(ReadOnlySpan<byte> content, bool isAugmented, ICollection<Cell>? refs = null)
13-
: this(false, refs?.Max(x => x.Level) ?? 0, content, isAugmented, refs)
12+
public Cell(ReadOnlySpan<byte> content, bool isAugmented, ICollection<Cell>? refs = null)
13+
: this(false, refs != null && refs.Any() ? refs.Max(x => x.Level) : (byte)0, content, isAugmented, refs)
1414
{
15-
// Nothing.
15+
// Nothing.
1616
}
1717

1818
public Cell(bool isExotic, byte level, ReadOnlySpan<byte> content, bool isAugmented, ICollection<Cell>? refs = null)
@@ -150,4 +150,4 @@ public byte[] Hash()
150150
return hashValue;
151151
}
152152
}
153-
}
153+
}

0 commit comments

Comments
 (0)