Skip to content

Commit

Permalink
feat(builder): add slice support
Browse files Browse the repository at this point in the history
  • Loading branch information
gtors committed May 14, 2024
1 parent c12e4b4 commit 34de0e1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tonsdk_ng/types/_builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ._address import Address
from ._bit_string import BitString
from ._cell import Cell
from ._slice import Slice


class Builder:
Expand Down Expand Up @@ -30,6 +31,22 @@ def store_maybe_ref(self, src: Cell | None) -> "Builder":

return self

def store_slice(self, src: Slice) -> "Builder":
if len(self.refs) + len(src.refs) > 4:
raise ValueError("refs overflow")
self.bits.write_bit_array(src.bits)
for i in range(src.ref_offset, len(src.refs)):
self.store_ref(src.refs[i])
return self

def store_maybe_slice(self, src: Slice | None) -> "Builder":
if src is not None:
self.bits.write_bit(1)
self.store_slice(src)
else:
self.bits.write_bit(0)
return self

def store_bit(self, value: int) -> "Builder":
self.bits.write_bit(value)
return self
Expand Down

0 comments on commit 34de0e1

Please sign in to comment.