PHP code example of olifanton / boc

1. Go to this page and download the library: Download olifanton/boc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

olifanton / boc example snippets


 declare(strict_types=1);

se Olifanton\Boc\Cell;

// Now you can use BoC classes


/**
 * @param int $length
 */
public function __construct(int $length)

/**
 * @param int $n Position
 */
public function get(int $n): bool

/**
 * @param int $n Position
 */
public function on(int $n): void

/**
 * @param int $n Position
 */
public function off(int $n): void

/**
 * @param int $n Position
 */
public function toggle(int $n): void

 declare(strict_types=1);

use Olifanton\Boc\BitString;

$bs = new BitString(4);
$bs->writeBit(1);
$bs->writeBit(0);
$bs->writeBit(1);
$bs->writeBit(1);

foreach ($bs->iterate() as $b) {
    echo (int)$b;
}
// Prints "1011"

/**
 * @param int|bool $b
 */
public function writeBit(int | bool $b): void

/**
 * @param array<int | bool> $ba Array of bits
 */
public function writeBitArray(array $ba): void

 declare(strict_types=1);

use Olifanton\Boc\BitString;

$bs = new BitString(4);
$bs->writeBitArray([1, false, 0, true]);

foreach ($bs->iterate() as $b) {
    echo (int)$b;
}
// Prints "1001"

/**
 * @param int|\Brick\Math\BigInteger $number Unsigned integer
 * @param int $bitLength Integer size (8, 16, 32, ...)
 */
public function writeUint(int | BigInteger $number, int $bitLength): void

/**
 * @param int|\Brick\Math\BigInteger $number Signed integer
 * @param int $bitLength Integer size (8, 16, 32, ...)
 */
public function writeInt(int | BigInteger $number, int $bitLength): void

/**
 * @param \ajf\TypedArrays\Uint8Array $ui8 Byte array
 */
public function writeBytes(Uint8Array $ui8): void

/**
 * @param string $value
 */
public function writeString(string $value): void

/**
 * @param int|\Brick\Math\BigInteger $amount
 */
public function writeCoins(int | BigInteger $amount): void;

/**
 * @param \Olifanton\Utils\Address|null $address TON Address
 */
public function writeAddress(?Address $address): void

/**
 * @param \Olifanton\Boc\BitString $anotherBitString BitString instance
 */
public function writeBitString(BitString $anotherBitString): void

/**
 * @param string|Uint8Array $serializedBoc Serialized BoC
 * @return Cell[]
 */
public static function fromBoc(string|Uint8Array $serializedBoc): array

/**
 * @param string|Uint8Array $serializedBoc Serialized BoC
 * @param bool $isBase64 Base64-serialized flag, default false
 */
public static function oneFromBoc(string|Uint8Array $serializedBoc, bool $isBase64 = false): Cell

/**
 * @param Cell $anotherCell Another cell
 * @return Cell This Cell
 */
public function writeCell(Cell $anotherCell): self

/**
 * @param bool $has_idx Default _true_
 * @param bool $hash_crc32 Default _true_
 * @param bool $has_cache_bits Default _false_
 * @param int $flags Default _0_
 */
public function toBoc(bool $has_idx = true,
                      bool $hash_crc32 = true,
                      bool $has_cache_bits = false,
                      int  $flags = 0): Uint8Array

/**
 * @param \ajf\TypedArrays\Uint8Array $array
 * @param int $length
 * @param \Olifanton\Boc\Slice[] $refs
 */
public function __construct(Uint8Array $array, int $length, array $refs)

/**
 * @param int $n
 */
public function get(int $n): bool

/**
 * @param int $bitLength
 */
public function loadBits(int $bitLength): Uint8Array

/**
 * @param int $bitLength
 */
public function loadUint(int $bitLength): BigInteger

/**
 * @param int $bitLength
 */
public function loadInt(int $bitLength): BigInteger

/**
 * @param int $bitLength
 */
public function loadVarUint(int $bitLength): BigInteger