Download the PHP package olifanton/boc without Composer
On this page you can find all versions of the php package olifanton/boc. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download olifanton/boc
More information about olifanton/boc
Files in olifanton/boc
Package boc
Short Description BOC (Bag of Cells) PHP serialization library
License MIT
Homepage https://github.com/olifanton/boc
Informations about the package boc
⚠️⚠️⚠️ This package is outdated and will not be updated! Use olifanton/interop
instead.
BOC (Bag of Cells) PHP serialization library
PHP port of tonweb-boc
JS library
Installation
Documentation
Getting started
Install olifanton/boc
package via Composer and include autoload script:
Library classes
Olifanton\Boc\BitString
BitString
is a class that allows you to manipulate binary data. BitString
is at the heart of the PHP representation of TVM Cells. BitString
is memory optimized for storing binary data.
Internally, BitString uses implementation of Uint8Array
provided by ajf/typed-arrays
package and is used as the base type for transferring binary data between parts of the Olifanton libraries.
The BitString instance is created with a strictly fixed length. write%
(writeBit, writeUint, ...) methods move the internal cursor. If you try to write a value that exceeds the length of the free bits, BitStringException
exception will be thrown.
BitString constructor
Parameters:
$length
— length of Uint8Array. Default value for TVM Cell: 1023 (Documentation)
BitString methods
getFreeBits(): int
Returns unused bits length of BitString.
getUsedBits(): int
Returns used bits length of BitString.
getUsedBytes(): int
Returns used bytes length of BitString.
get(): bool
Returns a bit value at $n
position.
on(): void
Sets a bit value to 1 at position $n
.
off(): void
Sets a bit value to 0 at position $n
.
toggle(): void
Toggle (inverse) bit value at position $n
.
iterate(): \Generator
Returns Generator of used bits.
Example:
writeBit(): void
Writes bit and increase BitString internal cursor.
writeBitArray(): void
Writes array of bits.
Example:
writeUint(): void
Writes $bitLength-bit unsigned integer.
writeInt(): void
Writes $bitLength-bit signed integer.
writeUint8(): void
Alias of writeUint()
method with predefined $bitLength parameter value.
writeBytes(): void
Write array of unsigned 8-bit integers.
writeString(): void
Writes UTF-8 string.
writeCoins(): void
Writes coins in nanotoncoins. 1 TON === 1000000000 (10^9) nanotoncoins.
writeAddress(): void
Writes TON address. See Address implementation in olifanton/utils package.
writeBitString(): void
Writes another BitString to this BitString.
clone(): BitString
Clones this BitString and returns new BitString instance.
toHex(): string
Returns hex string representation of BitString.
getImmutableArray(): Uint8Array
Returns immutable copy of internal Uint8Array.
getLength(): int
Returns size of BitString in bits.
Olifanton\Boc\Cell
Cell
is a class that implements the concept of TVM Cells in PHP. To create new and process received messages from the blockchain, you will work with instances of the Cell class.
Cell constructor
Without parameters.
Cell methods
fromBoc(): Array\<Cell>
Creates array of Cell's from byte array or hex string.
oneFromBoc(): Cell
Fetch one root Cell from byte array or hex string.
writeCell(): void
Writes another Cell to this cell and returns this cell. Mutable method.
getMaxDepth(): int
Returns max depth of child cells.
getBits(): BitString
Returns internal BitString instance for writing and reading.
getRefs(): ArrayObject\<Cell>
Returns Array-like object of children cells.
hash(): Uint8Array
Returns SHA-256 hash of this Cell.
print(): string
Recursively prints cell's content like Fift.
toBoc(): Uint8Array
Creates BoC Byte array.
Olifanton\Boc\Slice
Slice
is the type of cell slices. A cell can be transformed into a slice, and then the data bits and references to other cells from the cell can be obtained by loading them from the slice.
load%
(loadBit, loadUint, ...) methods move the Slice internal cursor. If you try to read a value that exceeds the length of the free bits, SliceException
exception will be thrown.
Slice constructor
Parameters:
$array
— Uint8Array from BitString representation of Cell$length
— BitString length$refs
— Children Cells slices
Slice methods
getFreeBits(): int
Returns the unread bits according to the internal cursor.
get(): bool
Returns a bit value at position $n
.
loadBit(): bool
Reads a bit and moves the cursor.
loadBits(): Uint8Array
Reads bit array.
loadUint(): BigInteger
Reads unsigned integer.
loadInt(): BigInteger
Reads signed integer.
loadVarUint(): BigInteger
loadCoins(): BigInteger
Reads TON amount in nanotoncoins.
loadAddress(): ?Address
Reads Address.
loadRef(): Slice
Reads Slice of children Cell.
Tests
License
MIT