tonpy.types package

Subpackages

Submodules

tonpy.types.cell module

class tonpy.types.cell.Cell(pc: PyCell | str | None = None)

Bases: object

begin_parse(allow_special=True) CellSlice

Convert cell to CellSlice

copy() PyCell

Copy current Cell

dump()

Recursively dump all cells as hex

dump_as_tlb(tlb: str) str

Dump as C++ PrettyPrint parsed by TLB type

get_hash() str

Get cell hash

is_null() bool

Some cells are nulls, you can’t operate with such ones

to_boc() str

Convert cell to BOC string

tonpy.types.cellbuilder module

class tonpy.types.cellbuilder.CellBuilder(builder=None)

Bases: object

begin_parse() CellSlice

Convert CellBuilder to CellSlice

property bits: int

Bits num that been used in cell

dump() str

Recursively dump all cells as hex

dump_as_tlb(tlb: str) str

Dump as C++ PrettyPrint parsed by TLB type

end_cell(special=False) Cell

Convert CellBuilder to Cell, if special is True - convert cell to special

get_hash() str

Get hash of cell

property refs: int

Refs num that been used in cell

property remaining_bits: int

Remaining bits in cell

property remaining_refs: int

Refs num that been used in cell

store_address(address: str | Address) CellBuilder

Parse smart-contract address from string and store as MsgAddress TLB structure |br|

Parameters:

address – Smart-contract address in any format

Returns:

Current CellBuilder

store_bitstring(bitstring: str | BitArray) CellBuilder

Store bits from bitstring string |br|

Parameters:

bitstring – Bits to store to cell (ex. ‘11001’)

Returns:

Current CellBuilder

store_bitstring_chk(bitstring: str | BitArray, size)
store_bool(bool_: bool) CellBuilder

Store bool bool_ as 1 bit to current CellBuilder and return modified self

store_builder(b: CellBuilder) CellBuilder

Append CellBuilder (bits & refs) b to current builder |br|

Parameters:

b – CellBuilder that will be appended to this builder

Returns:

Current CellBuilder

store_grams(grams: int) CellBuilder

Same as store .store_var_uint(grams, 16), grams is nanoTON value |br|

Parameters:

grams – nano TON value to store

Returns:

Current CellBuilder

store_int(int_: int, int_bits: int) CellBuilder

Stores int_ integer with int_bits size (up to 257) to current cell |br|

Parameters:
  • int – Integer to be stored into cell

  • int_bits – Bits num that will be used to store integer to cell

Returns:

Current CellBuilder

store_libref(hash_: str | int)

Create and store special library cell with hash of library cell

store_ones(n: int) CellBuilder

Store n 1 bits to current CellBuilder |br|

Parameters:

n – Num of 1 bits to be stored

Returns:

Current CellBuilder

store_ref(cell: Cell) CellBuilder

Take cell and store it to next reference in current builder |br|

Parameters:

cell – Cell to be stored as reference to current builder

Returns:

Updated (self) builder with new reference to cell

store_ref_or_tlb(cell: Cell | TLB.Record)
store_slice(cs: CellSlice) CellBuilder

Append CellSlice b (bits & refs) to current CellBuilder |br|

Parameters:

cs – CellSlice that will be appended to this builder

Returns:

Current CellBuilder

store_slice_or_tlb(cs: CellSlice | TLB.Record)

Allow to append cell slice or TLB field

store_slice_or_tlb_ext(cs: CellSlice | TLB.Record, ext)
store_string(string_to_store: str) CellBuilder

Convert string string_to_store to bitstring and store it in chain of cells |br|

Parameters:

string_to_store – string to be stored

Returns:

current CellBuilder

store_uint(uint_: int, uint_bits: int) CellBuilder

Stores uint_ unsigned integer with uint_bits size (up to 256) to current cell |br|

Parameters:
  • uint – Unsigned integer to be stored into cell

  • uint_bits – Bits num that will be used to store integer to cell

Returns:

Current CellBuilder

store_uint_big(a, b)
store_uint_leq(upper_bound: int, value: int) CellBuilder

Store value less or equal than upper_bound unsigned integer stored as bitCount(upper_bound) bits |br|

Parameters:
  • upper_bound – Max unsigned integer that can be stored

  • value – Value to store

Returns:

Current CellBuilder

store_uint_less(upper_bound: int, value: int) CellBuilder

Store value less than upper_bound unsigned integer stored as bitCount(upper_bound - 1) bits |br|

Parameters:
  • upper_bound – Max unsigned integer that can be stored

  • value – Value to store

Returns:

Current CellBuilder

store_var_int(int_: int, bits: int) CellBuilder

Same as store_var_uint but work with integers |br|

TLB Scheme: |br|

var_int$_ {n:#} len:(#< n) value:(int (len * 8))
  = VarInteger n;
Parameters:
  • int – Signed integer to be stored

  • bits – Num of bits for VarInteger

Returns:

Current CellBuilder

store_var_uint(uint_: int, bits: int) CellBuilder

Store VarUInteger bits to CellSlice |br|

The main idea that we store size of our integer in first up to bits in Cell |br| So we can use less space when storing large integers |br|

TLB scheme: |br|

var_uint$_ {n:#} len:(#< n) value:(uint (len * 8))
  = VarUInteger n;
Parameters:
  • uint – Unsigned integer to be stored

  • bits – Num of bits for VarUInteger

Returns:

Current CellBuilder

store_zeroes(n: int) CellBuilder

Store n 0 bits to current CellBuilder |br|

Parameters:

n – Num of 0 bits to be stored

Returns:

Current CellBuilder

to_boc() str

Convert CellBuilder to BOC string

tonpy.types.cellslice module

class tonpy.types.cellslice.CellSlice(cs: PyCellSlice | str, allow_special: bool = False)

Bases: object

class SpecialType(value)

Bases: Enum

An enumeration.

Library = 2
MerkleProof = 3
MerkleUpdate = 4
Ordinary = 0
PrunnedBranch = 1
advance(bits: int) bool

Try to skip bits, return False if bits >= self.bits |br|

Parameters:

bits – Num of bits to try to skip

Returns:

Is skip was success

advance_bits_refs(bits: int, refs: int) bool

Try to skip bits and refs, return False if (refs > self.refs) or (bits > self.bits) |br|

Parameters:
  • bits – Num bits of try to skip

  • refs – Num refs of try to skip

Returns:

Is operation success

advance_ext(bits_refs: int) True

Try to skip bits and refs, return False if (refs > self.refs) or (bits > self.bits) |br|

Parameters:

bits_refsnum_bits * (2**16) + num_refs

Returns:

Is operation is success

advance_refs(refs: int) bool

Try to skip refs, return False if refs >= self.refs |br|

Parameters:

refs – Num of refs to try to skip

Returns:

Is skip was success

bit_at(position: int) int
Parameters:

position – Bit position to fetch from

Returns:

Bit at position position of current CellSlice

property bits: int

Bits num that been used in cell

bselect(bits: int, mask: int) int

Unsigned integer bits: 0b111 |br| Mask: 0b11111111 (up to 8 variants) |br| Result: 7 |br|

Parameters:
  • bits – Num bits (up to 6) to load unsigned integer (X)

  • mask – Mask that will be applied to ones bitstring length of X+1

Returns:

Count of ones after mask is applied or -1 if not enough bits or bits > 6

bselect_ext(bits: int, mask: int) int

Same as bselect, but allow to < then bits (they will be padded) |br|

Parameters:
  • bits – Num bits (up to 6) to load unsigned integer (X)

  • mask – Mask that will be applied to ones bitstring length of X+1

Returns:

Count of ones after mask is applied or -1 if not enough bits or bits > 6

copy() CellSlice

Make independent copy of current CellSlice

cut_tail(cs: CellSlice) bool

Skip bits & refs of cs from current CellSlice

dump() str

Recursively dump all cells as hex

dump_as_tlb(tlb: str) str

Dump as C++ PrettyPrint parsed by TLB type

empty_ext() bool

Is current CellSlice is empty (no bits, no refs)

get_hash() str

Get hash of cell

is_special() bool

Is current cell in special

load_address() Address

Parse address by MsgAddress TLB structure |br|

Returns:

Loaded address dumped as string

load_bitstring(size: int) str

Load bitstring of size bits and move cursor

load_bool() bool

Load 1 bit from current CellSlice and return it as bool

load_int(n: int) int

Load signed integer in n bits (up to 256) and move cursor to n bits |br|

Parameters:

n – Num of bits to load from CellSlice

Returns:

Integer which was stored in n bits

load_ref(offset: int = 0, as_cs: bool = False) Cell | CellSlice

Fetches cell on next reference and return it, move refs cursor position by 1 |br|

Parameters:
  • offset – Skip first offset refs

  • as_cs – If True will convert loaded Cell to CellSlice

Returns:

New CellSlice from cell stored in next ref

load_string(bit_size: int = 0, cell_chain: bool = True, strict: bool = True) str

Concatenate all refs to one bit bitstring and load it as string |br|

Warning: this will change current cell to last cell in CellChain if cell_chain is True |br|

:param strict If strict will fail if all_bits % 8 != 0 at the end :param bit_size: Size of string (in bits) to be loaded (by default all bits in cell) :param cell_chain: If False will load only current cell, if True will load all cells by 1 ref in each cell (CellChain) :return: String that was loaded

load_subslice(bits: int, refs: int = 0) CellSlice

Load bits and refs to separate CellSlice and move cursor

load_subslice_ext(bits_refs: int) CellSlice

Same as load_subslice but in ext size format

refs = bits_refs // (2 ** 16)
bits = bits_refs % (2 ** 16)
load_tlb(tlb_structure: str) CellSlice

Load as C++ defined tlb structure from block.tlb, store to new CellSlice, move pointer |br|

Parameters:

tlb_structure – Class name of TLB to load

Returns:

New cell slice contains TLB structure

load_uint(n: int) int

Load unsigned integer in n bits (up to 256) and move cursor to n bits |br|

Parameters:

n – Num of bits to load from CellSlice

Returns:

Unsigned integer which was stored in n bits

load_uint_leq(upper_bound: int) int

Load value less or equal than upper_bound unsigned integer stored as bitCount(upper_bound) bits

load_uint_less(upper_bound: int) int

Load value less than upper_bound unsigned integer stored as bitCount(upper_bound - 1) bits

load_var_int(bits: int) int

Same as load_var_uint, but signed |br|

Parameters:

bits – Up to what bitsize integer will be loaded

Returns:

Load integer stored in VarInteger bits

load_var_uint(bits: int) int

Load VarUInteger bits, more information can be found in CellBuilder load_ver_uint method |br|

Parameters:

bits – Up to what bitsize unsigned integer will be loaded

Returns:

Load integer stored in VarUInteger bits

preload_bitstring(size: int) str

Load bitstring of size bits

preload_bool() bool

Preload 1 bit from current CellSlice and return it as bool

preload_int(n: int) int

Load signed integer in n bits (up to 256) and don’t change cursor position |br|

Parameters:

n – Num of bits to load from CellSlice

Returns:

Integer which was stored in n bits

preload_ref(offset: int = 0, as_cs: bool = False) Cell | CellSlice

Fetches cell on next reference and return it, don’t change refs cursor position |br|

Parameters:
  • offset – Skip first offset refs (but don’t move pointer position)

  • as_cs – If True will convert loaded Cell to CellSlice

Returns:

New CellSlice from cell stored in next ref

preload_subslice(bits: int, refs: int = 0) CellSlice

Load bits and refs to separate CellSlice

preload_subslice_ext(bits_refs: int) CellSlice

Same as preload_subslice but in ext size format

refs = bits_refs // (2 ** 16)
bits = bits_refs % (2 ** 16)
preload_uint(n: int) int

Preload unsigned integer in n bits (up to 256) and don’t change cursor position |br|

Parameters:

n – Num of bits to load from CellSlice

Returns:

Unsigned integer which was stored in n bits

property refs: int

Refs num that been used in cell

size_ext()

Get size in ext format: |br|

refs = bits_refs // (2 ** 16)
bits = bits_refs % (2 ** 16)
skip_bits(bits: int, last: bool = False) True

Move bits cursor position at bits bits. |br|

Parameters:
  • bits – How many bits to move cursor to

  • last – If true will reduce the right boundary

Returns:

True

skip_refs(refs: int, last: bool = False) bool

Move refs cursor position at refs count. |br|

Parameters:
  • refs – How many refs to move cursor to

  • last – If true will reduce the right boundary

Returns:

True

special_type() SpecialType
to_bitstring() str

Dump current CellSlice to bitstring (ex. 11100011) |br|

Returns:

Bitstring which is contains in CellSlice

to_boc() str

Dump current CellSlice as BOC string |br|

Returns:

Bag of cells string

to_cell() Cell

tonpy.types.stack module

class tonpy.types.stack.Continuation(cont: CellSlice | PyContinuation)

Bases: object

serialize() Cell
type() str
class tonpy.types.stack.Stack(values_list: Iterable | None = None, prev_stack: PyStack | None = None)

Bases: object

append(value: None | Cell | CellSlice | int | StackEntry | CellBuilder)
static deserialize(value: CellSlice) Stack
pop() StackEntry
serialize(eoln=False, lisp_stype=False, serialized_bocs=False) Cell
unpack_rec()
class tonpy.types.stack.StackEntry(value: None | Cell | CellSlice | int | CellBuilder | list | Continuation = None, entry=None)

Bases: object

class Type(value)

Bases: Enum

Possible types of StackEntry

t_atom = 12
t_bitstring = 10
t_box = 11
t_builder = 3
t_bytes = 9
t_cell = 2
t_int = 1
t_null = 0
t_object = 13
t_slice = 4
t_stack = 7
t_string = 8
t_tuple = 6
t_vmcont = 5
as_cell()
as_cell_builder()
as_cell_slice()
as_cont()
as_int()
as_str()
as_tuple() List[StackEntry]
static create_tuple(items: Iterable) PyStackEntry
static deserialize(value: CellSlice) StackEntry
get()

Convert stack entry to type

get_type()

Get type of stack entry

static rec_get(value)
serialize(short_ints=True, continuations=True) Cell

tonpy.types.tlb module

class tonpy.types.tlb.RecordBase

Bases: object

Each TLB type have Record subclass means instance of TLB type |br| If you have multiple constructors name of Record class will be change to Record_{{constructor_name}} |br| Each record have __init__ function witch contains all fields of TLB type |br| Check out test_tlb.py test_records function

add_r1(val: str, y: int, z: int) bool
cell_pack() Cell
cell_unpack(cell_ref: Cell, rec_unpack: bool = False, strict: bool = True) bool

Unpack current Cell as TLB.Record to fields, if success return True |br| All field values store in class object. If rec_unpack is True - unpack all types with recursion |br| Note: simple types that contains only from tags don’t need rec_unpack, they will be fetched immediately |br| If after unpack Cell contains some data - return False |br|

Parameters:
  • cell_ref – Cell to be fetched as TLB.Record

  • rec_unpack – Need to unpack all types with recursion

  • strict – If False some failed to parse subtypes can be None

Returns:

Is unpack was success

dump()

Recursively convert TLB to dict

get_tag()

Get current TLB.Record constructor tag

get_tag_enum()

Get current TLB.Record constructor tag in Enum type of TLB.Tag

get_tag_len()

Get length of bits for current TLB.Record constructor tag

get_type_class()

Get TLB type of current record

mul_r1(val: str, y: int, z: int) bool
pack(cb: CellBuilder) None
store_from(cb, value)

Recursively pack TLB type to CellBuilder

to_dict(rec_unpack=False, convert_cells_to_bocs=False)
unpack(cs: CellSlice, rec_unpack: bool = False, strict: bool = True) bool

Unpack current CellSlice as TLB.Record to fields, if success return True |br| All field values store in class object. If rec_unpack is True - unpack all types with recursion |br| Note: simple types that contains only from tags don’t need rec_unpack, they will be fetched immediately |br|

Parameters:
  • cs – CellSlice to be fetched as TLB.Record

  • rec_unpack – Need to unpack all types with recursion

  • strict – If False some failed to parse subtypes can be None

Returns:

Is unpack was success

class tonpy.types.tlb.TLB

Bases: object

class Record

Bases: RecordBase

class Tag(value)

Bases: Enum

Contractor tags enums stored as lexicographic order |br|

a$0 = A;
b$10 = A;
c$1 = A;

Means: |br|

class Tag(Enum):
   a = 0
   b = 1
   c = 2

cons_len = [1, 2, 1]
cons_tag = [0, 2, 1]
always_special() bool

Is current type marked as special cell or not

cell_unpack(cell_ref: Cell, rec_unpack: bool = False, strict: bool = True) RecordBase | None

Same as unpack but

Parameters:
  • cell_ref

  • rec_unpack – pass to RecordBase rec_unpack

  • strict – pass to RecordBase strict

Returns:

cons_len: List[int] | int = None
cons_tag: List[int] = None
fetch(cell_or_slice: Cell | CellSlice, rec_unpack: bool = False, strict: bool = True, **kwargs) Record | Cell | CellSlice | None
Parameters:
  • cell_or_slice

  • rec_unpack – pass to RecordBase rec_unpack

  • strict – pass to RecordBase strict

Returns:

Will return cell/cellslice if cell is special, else will return record on success, else None

fetch_enum(cs: CellSlice) int

Fetch enum tag value from CellSlice of type TLB |br|

Parameters:

cs – CellSlice to fetch enum tag value from

Returns:

Enum tag value of type TLB store in cs: CellSlice

fetch_to(to_obj: object, cell_or_slice: Cell | CellSlice, unpack_names: List[str], rec_unpack: bool = False, strict: bool = True)

Same as fetch, but copy negate params to to_obj with names from unpack_names

Parameters:
  • to_obj

  • cell_or_slice

  • unpack_names

  • rec_unpack

  • strict

Returns:

get_param_record(item: str) Callable

Copy params from TLB to Record

get_tag(cs: CellSlice) Tag | None

Fetch tag from CellSlice cs and return TLB.Tag enum |br| :param cs: CellSlice to fetch tag from :return: TLB.Tag enum

has_params = False
nat_abs(x: int)
original_cell: Cell | None = None
original_cell_slice: CellSlice | None = None
params_attrs = ['X_', 'm_', 'm_', 'm_', 'X_', 'X_', 'X_', 'm_', 'X_', 'X_', 'X_', 'Y_', 'X_', 'X_', 'Y_', 'X_', 'm_', 'X_', 'Y_', 'm_', 'X_', 'Y_', 'm_', 'X_', 'Y_', 'm_', 'X_', 'm_', 'X_', 'm_', 'X_', 'm_', 'X_', 'Y_', 'X_', 'm_', 'X_', 'X_', 'm_', 'X_', 'Y_', 'm_', 'X_', 'Y_', 'm_', 'X_', 'X_', 'X_', 'X_', 'X_', 'X_', 'X_', 'X_', 'm_', 'X_', 'X_', 'X_', 'm_', 'X_', 'm_', 'X_', 'X_', 'X_', 'm_', 'X_', 'm_', 'X_', 'Y_', 'm_', 'X_', 'm_', 'X_', 'Y_', 'm_', 'X_', 'm_', 'X_', 'Y_', 'X_', 'm_', 'X_', 'X_', 'm_', 'X_', 'm_', 'X_', 'X_', 'm_', 'X_', 'X_', 'm_', 'X_', 'm_', 'X_', 'm_', 'X_', 'm_', 'X_', 'm_', 'X_', 'm_', 'X_', 'm_', 'X_', 'X_', 'm_', 'X_', 'X_', 'X_', 'm_', 'X_', 'm_', 'X_', 'm_', 'X_', 'X_', 'X_', 'X_', 'm_', 'X_', 'X_']
store_enum_from(cb: CellBuilder, value: int | None = None) bool

Store enum value from self.cons_tag to cb: CellBuilder |br| If self.const_tag is exact (tags are matched positions in lexicographic order) then will store value |br| If value is None and TLB.Tag is constant will store constant TLB.Tag else will raise an error |br|

Parameters:
  • cb – CellBuilder to store enum to

  • value – Value or enum position to store enum from

Returns:

True

store_from(cb, value)
store_ref_or_tlb(cb: CellBuilder, value)
tag_to_class = {}
unpack(cs: CellSlice, rec_unpack: bool = False, strict: bool = True) RecordBase | None

Unpack current TLB and return TLB.Record if success, else return None |br|

By default, rec_unpack is False because for large TLB structures it can be slow. |br| More simple way is to skip needed structures one by one and load to python objects only needed ones. |br|

Parameters:
  • cs – CellSlice to unpack TLB from

  • rec_unpack – pass to RecordBase rec_unpack

  • strict – pass to RecordBase strict

Returns:

TLB.Record instance or None

tonpy.types.tlb.rec_dump(item)

tonpy.types.vmdict module

class tonpy.types.vmdict.AugmentedData

Bases: object

eval_empty() -> (<class 'bool'>, typing.Optional[tonpy.types.cellslice.CellSlice])
eval_fork(left: ~tonpy.types.cellslice.CellSlice, right: ~tonpy.types.cellslice.CellSlice) -> (<class 'bool'>, typing.Optional[tonpy.types.cellslice.CellSlice])
eval_leaf(cs: ~tonpy.types.cellslice.CellSlice) -> (<class 'bool'>, typing.Optional[tonpy.types.cellslice.CellSlice])

Extract extra from leaf value cs

get_base_aug()
skip_extra(cs: ~tonpy.types.cellslice.CellSlice) -> (<class 'bool'>, typing.Optional[tonpy.types.cellslice.CellSlice])

Skip extra from leaf, return updated cs

class tonpy.types.vmdict.DataWithExtra(cs: CellSlice, aug: AugmentedData)

Bases: object

property data
property extra
class tonpy.types.vmdict.TypedAugmentedData(value_type: TLB, extra_type: TLB)

Bases: AugmentedData

skip_extra(cs: ~tonpy.types.cellslice.CellSlice) -> (<class 'bool'>, typing.Optional[tonpy.types.cellslice.CellSlice])

Skip extra from leaf, return updated cs

class tonpy.types.vmdict.TypedDataWithExtra(cs: CellSlice, aug: TypedAugmentedData, rec_unpack=False)

Bases: DataWithExtra

class tonpy.types.vmdict.TypedVmDict(tlb_type: Tuple[TLB, TLB] | TLB, key_len: int, signed: bool = False, cell_root: str | Cell | CellSlice | None = None, aug: TypedAugmentedData | None = None, rec_unpack: bool = False)

Bases: VmDict

get_minmax_key(fetch_max: bool = True, invert_first: bool = True, signed: bool | None = None) tuple[int, CellSlice | TypedDataWithExtra]

Fetch max / min key, value |br|

Parameters:
  • fetch_max – If True will fetch max key, else will fetch min key in dict

  • invert_first – If True will respect signed in operations

  • signed – Fetch keys as signed or not

Returns:

Key and CellSlice that stored in key

lookup(key: int, signed: bool | None = None) CellSlice | TypedDataWithExtra

Fetch CellSlice stored in key |br|

Parameters:
  • key – Integer to be loaded as self.key_len bit and used as key to search

  • signed – Signed

Returns:

CellSlice that stored by key

lookup_nearest_key(key: int, fetch_next: bool = True, allow_eq: bool = False, invert_first: bool = True, signed: bool | None = None) tuple[int, CellSlice | DataWithExtra]

Compute the nearest key to key |br|

Parameters:
  • keyself.key_len-bit integer key

  • fetch_next – If True will fetch next else will return prev

  • allow_eq – If True will return value with key if exist

  • invert_first – If True will respect signed in operations

  • signed – Fetch keys as signed or not

Returns:

Founded key and value

class tonpy.types.vmdict.VmDict(key_len: int, signed: bool = False, cell_root: str | Cell | CellSlice | None = None, aug: AugmentedData | None = None)

Bases: object

get_cell() Cell

Get root cell of dictionary

get_iter(direction=False) Iterable[tuple[int, CellSlice]]

Simple dict iterator

get_minmax_key(fetch_max: bool = True, invert_first: bool = True, signed: bool | None = None) tuple[int, CellSlice | DataWithExtra]

Fetch max / min key, value |br|

Parameters:
  • fetch_max – If True will fetch max key, else will fetch min key in dict

  • invert_first – If True will respect signed in operations

  • signed – Fetch keys as signed or not

Returns:

Key and CellSlice that stored in key

get_minmax_key_ref(fetch_max: bool = True, inver_first: bool = False, signed: bool | None = None) tuple[int, Cell]

Same as get_minmax, but fetch Cell by key (stored in ref) |br|

Parameters:
  • fetch_max – If True will fetch max key, else will fetch min key in dict

  • invert_first – If True will respect signed in operations

  • signed – Fetch keys as signed or not

Returns:

Key and Cell that stored in key

is_empty() bool

If dict contains no keys - it’s empty

lookup(key: int, signed: bool | None = None) CellSlice | DataWithExtra

Fetch CellSlice stored in key |br|

Parameters:
  • key – Integer to be loaded as self.key_len bit and used as key to search

  • signed – Signed

Returns:

CellSlice that stored by key

lookup_delete(key: int, signed: bool | None = None) CellSlice | DataWithExtra

Same as lookup, but delete (key, value) from VmDict |br|

Parameters:
  • key – Integer to be loaded as self.key_len bit and used as key to search

  • signed – Signed

Returns:

CellSlice that stored by key

lookup_delete_ref(key: int, signed: bool | None = None) Cell

Same as `lookup_delete but delete the ref stored by set_ref |br|

Parameters:
  • key – Integer to be loaded as self.key_len bit and used as key to search

  • signed – Signed

Returns:

Cell that stored by key

lookup_nearest_key(key: int, fetch_next: bool = True, allow_eq: bool = False, invert_first: bool = True, signed: bool | None = None) tuple[int, CellSlice | DataWithExtra]

Compute the nearest key to key |br|

Parameters:
  • keyself.key_len-bit integer key

  • fetch_next – If True will fetch next else will return prev

  • allow_eq – If True will return value with key if exist

  • invert_first – If True will respect signed in operations

  • signed – Fetch keys as signed or not

Returns:

Founded key and value

lookup_ref(key, signed: bool | None = None) Cell

Same as lookup, but fetch ref stored by set_ref |br|

Parameters:
  • key – Integer to be loaded as self.key_len bit and used as key to search

  • signed – Signed

Returns:

Cell that stored by key

map(f: Callable[[CellSlice, CellSlice], bool])

Map over all key & values of dictionary.

set(key: int, value: CellSlice, mode: str = 'set', signed: bool | None = None) VmDict

Add / Set / Replace key as key_len and signed bits to value value |br|

  • Set: sets the value associated with key_len-bit key key in VmDict to value value

  • Add: sets the value associated with key key to value, but only if key is not already present in VmDict

  • Replace: sets the value of key to value only if the key key was already present in VmDict

Parameters:
  • key – Integer to be stored as key

  • value – CellSlice to be stored

  • mode – “set” / “replace” / “add”

  • signed – Signed

Returns:

Updated self

set_builder(key: int, value: CellBuilder, mode: str = 'set', signed: bool | None = None) VmDict

Set cell builder stored to key, you can load it by lookup method |br|

Parameters:
  • key – Integer to be stored as key

  • value – CellSlice to be stored

  • mode – “set” / “replace” / “add”

  • signed – Signed

Returns:

Updated self

set_ref(key: int, value: Cell, mode: str = 'set', signed: bool | None = None) VmDict

Same as set, but store Cell to ref (by key) |br|

Parameters:
  • key – Integer to be stored as key

  • value – CellSlice to be stored

  • mode – “set” / “replace” / “add”

  • signed – Signed

Returns:

Updated self

Module contents

tonpy.types.begin_cell()