Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Latest commit

 

History

History
958 lines (565 loc) · 14.6 KB

Slice.md

File metadata and controls

958 lines (565 loc) · 14.6 KB

ton3-core / Slice

Class: Slice

Cell Slice

Table of contents

Accessors

Methods

Accessors

bits

get bits(): Bit[]

Returns

Bit[]


refs

get refs(): Cell[]

Returns

Cell[]

Methods

skip

skip(size): Slice

Alias for .skipBits()

Parameters

Name Type
size number

Returns

Slice


skipBits

skipBits(size): Slice

Skip bits from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeBits([ 0, 1, 1, 0 ])

const slice = builder.cell().slice()

console.log(slice.skipBits(2).loadBits(2)) // [ 1, 0 ]

Parameters

Name Type Description
size number Total bits should be skipped

Returns

Slice


skipRefs

skipRefs(size): Slice

Skip refs from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()
const cell1 = new Builder().cell()
const cell2 = new Builder().cell()

builder.storeRefs([ cell1, cell2 ])

const slice = builder.cell().slice()

console.log(slice.skipRefs(1).loadRef()) // cell2

Parameters

Name Type Description
size number Total refs should be skipped

Returns

Slice


skipDict

skipDict(): Slice

Skip dict from Slice

Returns

Slice


loadRef

loadRef(): Cell

Read ref from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()
const ref = new Builder()

builder.storeRef(ref.cell())

const slice = builder.cell().slice()

console.log(slice.loadRef()) // Cell

Returns

Cell


preloadRef

preloadRef(): Cell

Same as .loadRef() but will not mutate Slice

Returns

Cell


loadMaybeRef

loadMaybeRef(): Cell

Read maybe ref from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder1 = new Builder()
const builder2 = new Builder()
const ref = new Builder()

builder1.storeBit(0)

builder2
 .storeBit(1)
 .storeRef(ref.cell())

const slice1 = builder1.cell().slice()
const slice2 = builder2.cell().slice()

console.log(slice1.loadMaybeRef()) // null
console.log(slice2.loadMaybeRef()) // Cell

Returns

Cell


preloadMaybeRef

preloadMaybeRef(): Cell

Same as .loadMaybeRef() but will not mutate Slice

Returns

Cell


loadBit

loadBit(): Bit

Read bit from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeBit(1)

const slice = builder.cell().slice()

console.log(slice.loadBit()) // 1

Returns

Bit


preloadBit

preloadBit(): Bit

Same as .loadBit() but will not mutate Slice

Returns

Bit


loadBits

loadBits(size): Bit[]

Read bits from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeBits([ 0, 1 ])

const slice = builder.cell().slice()

console.log(slice.loadBits(2)) // [ 0, 1 ]

Parameters

Name Type Description
size number Total bits should be readed to represent requested value

Returns

Bit[]


preloadBits

preloadBits(size): Bit[]

Same as .loadBits() but will not mutate Slice

Parameters

Name Type
size number

Returns

Bit[]


loadInt

loadInt(size): number

Read int from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeInt(-14, 15)

const slice = builder.cell().slice()

console.log(slice.loadInt(15)) // -14

Parameters

Name Type Description
size number Total bits should be readed to represent requested value

Returns

number


preloadInt

preloadInt(size): number

Same as .loadInt() but will not mutate Slice

Parameters

Name Type
size number

Returns

number


loadBigInt

loadBigInt(size): bigint

Same as .loadInt() but will return {@link BigInt}

Parameters

Name Type
size number

Returns

bigint


preloadBigInt

preloadBigInt(size): bigint

Same as .preloadInt() but will return {@link BigInt}

Parameters

Name Type
size number

Returns

bigint


loadUint

loadUint(size): number

Read uint from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeUint(14, 9)

const slice = builder.cell().slice()

console.log(slice.loadUint(9)) // 14

Parameters

Name Type Description
size number Total bits should be readed to represent requested value

Returns

number


preloadUint

preloadUint(size): number

Same as .loadUint() but will not mutate Slice

Parameters

Name Type
size number

Returns

number


loadBigUint

loadBigUint(size): bigint

Same as .loadUint() but will return {@link BigInt}

Parameters

Name Type
size number

Returns

bigint


preloadBigUint

preloadBigUint(size): bigint

Same as .preloadUint() but will return {@link BigInt}

Parameters

Name Type
size number

Returns

bigint


loadVarInt

loadVarInt(length): number

Read variable int from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeVarInt(-101101, 16)

const slice = builder.cell().slice()

console.log(slice.loadVarInt(16)) // -101101

Parameters

Name Type Description
length number Maximum possible number of bits used to store value??

Returns

number


preloadVarInt

preloadVarInt(length): number

Same as .loadVarInt() but will not mutate Slice

Parameters

Name Type
length number

Returns

number


loadVarBigInt

loadVarBigInt(length): bigint

Same as .loadVarInt() but will return {@link BigInt}

Parameters

Name Type
length number

Returns

bigint


preloadVarBigInt

preloadVarBigInt(length): bigint

Same as .preloadVarInt() but will return {@link BigInt}

Parameters

Name Type
length number

Returns

bigint


loadVarUint

loadVarUint(length): number

Read variable uint from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeVarUint(101101, 16)

const slice = builder.cell().slice()

console.log(slice.loadVarUint(16)) // 101101

Parameters

Name Type Description
length number Maximum possible number of bits used to store value??

Returns

number


preloadVarUint

preloadVarUint(length): number

Same as .loadVarUint() but will not mutate Slice

Parameters

Name Type
length number

Returns

number


loadVarBigUint

loadVarBigUint(length): bigint

Same as .loadVarUint() but will return {@link BigInt}

Parameters

Name Type
length number

Returns

bigint


preloadVarBigUint

preloadVarBigUint(length): bigint

Same as .preloadVarUint() but will return {@link BigInt}

Parameters

Name Type
length number

Returns

bigint


loadBytes

loadBytes(size): Uint8Array

Read bytes from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeBytes(new Uint8Array([ 255, 255 ]))

const slice = builder.cell().slice()

console.log(slice.loadBytes(16)) // [ 255, 255 ]

Parameters

Name Type
size number

Returns

Uint8Array


preloadBytes

preloadBytes(size): Uint8Array

Same as .loadBytes() but will not mutate Slice

Parameters

Name Type
size number

Returns

Uint8Array


loadString

loadString(size?): string

Read string from Slice

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()

builder.storeString('Привет, мир!')

const slice = builder.cell().slice()

console.log(slice.loadString()) // 'Привет, мир!'

Parameters

Name Type Default value
size number null

Returns

string


preloadString

preloadString(size?): string

Same as .loadString() but will not mutate Slice

Parameters

Name Type Default value
size number null

Returns

string


loadAddress

loadAddress(): Address

Read Address from Slice

example

import { Builder, Address, Slice } from 'ton3-core'

const builder = new Builder()
const address = new Address('kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYIny')

builder.storeAddress(address)

const slice = builder.cell().slice()

console.log(slice.loadAddress().toString())
// 'kf_8uRo6OBbQ97jCx2EIuKm8Wmt6Vb15-KsQHFLbKSMiYIny'

Returns

Address


preloadAddress

preloadAddress(): Address

Same as .loadAddress() but will not mutate Slice

Returns

Address


loadCoins

loadCoins(decimals?): Coins

Read Coins from Slice

example

import { Builder, Coins, Slice } from 'ton3-core'

const builder = new Builder()
const coins = new Coins('100')

builder.storeCoins(coins)

const slice = builder.cell().slice()

console.log(slice.loadCoins().toString()) // '100'

Parameters

Name Type Default value
decimals number 9

Returns

Coins


preloadCoins

preloadCoins(decimals?): Coins

Same as .loadCoins() but will not mutate Slice

Parameters

Name Type Default value
decimals number 9

Returns

Coins


loadDict

loadDict<K, V>(keySize, options?): HashmapE<K, V>

Read HashmapE from Slice

example

import { Builder, Slice, HashmapE } from 'ton3-core'

const builder = new Builder()
const dict = new HashmapE(16)

builder.storeDict(dict)

const slice = builder.cell().slice()
const entries = [ ...slice.loadDict() ]

console.log(entries) // []

Type parameters

Name Type
K Bit[]
V Cell

Parameters

Name Type
keySize number
options? HashmapOptions<K, V>

Returns

HashmapE<K, V>


preloadDict

preloadDict<K, V>(keySize, options?): HashmapE<K, V>

Same as .loadDict() but will not mutate Slice

Type parameters

Name Type
K Bit[]
V Cell

Parameters

Name Type
keySize number
options? HashmapOptions<K, V>

Returns

HashmapE<K, V>


parse

Static parse(cell): Slice

Creates new Slice from Cell

example

import { Builder, Slice } from 'ton3-core'

const builder = new Builder()
const cell = builder.cell()
const slice = Slice.parse(cell)

Parameters

Name Type
cell Cell

Returns

Slice