ton-kotlin
ton-kotlin copied to clipboard
`org.ton.block.VarUInteger` addition always throws an exception
On almost any addition (say VarUInteger(1)+VarUInteger(1)
) an exception is thrown from plus
in line 45
https://github.com/andreypfau/ton-kotlin/blob/b1edc4b134e89ccf252149f27c85fd530377cebe/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/VarUInteger.kt#L41-L47
This happens, because VarUInteger
, when constructed, holds number's length in bytes:
https://github.com/andreypfau/ton-kotlin/blob/b1edc4b134e89ccf252149f27c85fd530377cebe/ton-kotlin-block/src/commonMain/kotlin/org/ton/block/VarUInteger.kt#L26-L31
Therefore, in line 45
, maxLen
contains number of bytes, but actualLen
is clearly number of bits, and very often number of bits is larger, causing this exception. It is also related to other mathematical operators with VarUInteger
Moreover, to me it seems that bit length anyway can increase when adding two numbers of the same bit length
arithmetic operators will be removed in the next release due separation of serialization objects
and actual arithmetics, use BigInt
instead.