olifanton/interop 사용하십시오. tonweb-boc JS 라이브러리의 PHP 포트
composer require olifanton/boc Composer를 통해 olifanton/boc 패키지를 설치하고 자동로드 스크립트를 포함하십시오.
<?php declare (strict_types= 1 );
require __DIR__ . " /vendor/autoload.php " ;
use Olifanton Boc BitString ;
use Olifanton Boc Cell ;
// Now you can use BoC classesOlifantonBocBitString BitString 이진 데이터를 조작 할 수있는 클래스입니다. BitString TVM 세포의 PHP 표현의 핵심입니다. BitString 이진 데이터를 저장하는 데 최적화 된 메모리입니다. 내부적으로 Bitstring은 ajf/typed-arrays 패키지에서 제공하는 Uint8Array 의 구현을 사용하며 Olifanton 라이브러리의 일부 사이에 이진 데이터를 전송하기위한 기본 유형으로 사용됩니다.
비트 스트링 인스턴스는 엄격하게 고정 된 길이로 생성됩니다. write% (WriteBit, WriteUint, ...) 메소드 내부 커서를 움직입니다. 무료 비트의 길이를 초과하는 값을 쓰려고하면 BitStringException 예외가 발생합니다.
/**
* @param int $length
*/
public function __construct( int $ length )매개 변수 :
$length - uint8array의 길이. TVM 셀의 기본값 : 1023 (문서) 비트 스트링의 미사용 비트 길이를 반환합니다.
중고 비트의 비트 스트링 길이를 반환합니다.
Bitstring의 바이트 길이를 반환합니다.
/**
* @param int $n Position
*/
public function get( int $ n ): bool $n 위치에서 비트 값을 반환합니다.
/**
* @param int $n Position
*/
public function on( int $ n ): void 위치 $n 에서 비트 값을 1로 설정합니다.
/**
* @param int $n Position
*/
public function off( int $ n ): void 위치 $n 에서 비트 값을 0으로 설정합니다.
/**
* @param int $n Position
*/
public function toggle( int $ n ): void 위치 $n 의 토글 (인비비) 비트 값.
중고 비트의 생성기를 반환합니다.
예:
<?php 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비트 배열을 씁니다.
예:
<?php 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|BrickMathBigInteger $number Unsigned integer
* @param int $bitLength Integer size (8, 16, 32, ...)
*/
public function writeUint( int | BigInteger $ number , int $ bitLength ): void$ bitlength-bit 부호없는 정수를 씁니다.
/**
* @param int|BrickMathBigInteger $number Signed integer
* @param int $bitLength Integer size (8, 16, 32, ...)
*/
public function writeInt( int | BigInteger $ number , int $ bitLength ): void$ bitlength bit 서명 정수를 씁니다.
사전 정의 된 $ bitlength 매개 변수 값이있는 writeUint() 메소드의 별칭.
/**
* @param ajfTypedArraysUint8Array $ui8 Byte array
*/
public function writeBytes( Uint8Array $ ui8 ): void서명되지 않은 8 비트 정수의 배열을 작성하십시오.
/**
* @param string $value
*/
public function writeString( string $ value ): voidUTF-8 문자열을 씁니다.
/**
* @param int|BrickMathBigInteger $amount
*/
public function writeCoins( int | BigInteger $ amount ): void ;나노 톤 코인에 동전을 씁니다. 1 톤 === 10000000000 (10^9) 나노 톤 코인.
/**
* @param OlifantonUtilsAddress|null $address TON Address
*/
public function writeAddress(? Address $ address ): voidTON 주소를 작성합니다. Olifanton/Utils 패키지의 주소 구현을 참조하십시오.
/**
* @param OlifantonBocBitString $anotherBitString BitString instance
*/
public function writeBitString( BitString $ anotherBitString ): void이 비트 스트링에 또 다른 비트 스트링을 씁니다.
이 비트 스트링을 복제하고 새로운 비트 스트링 인스턴스를 반환합니다.
Bitstring의 육각 문자열 표현을 반환합니다.
내부 UINT8ARRAY의 불변의 사본을 반환합니다.
비트 스트링의 크기를 비트로 반환합니다.
OlifantonBocCell Cell PHP에서 TVM 세포의 개념을 구현하는 클래스입니다. 블록 체인에서 새롭고 프로세스 수신 메시지를 만들려면 셀 클래스의 인스턴스와 함께 작동합니다.
매개 변수없이.
/**
* @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이 셀에 다른 셀을 쓰고이 셀을 반환합니다. 돌연변이 가능한 방법.
어린이 세포의 최대 깊이를 반환합니다.
쓰기 및 읽기를 위해 내부 비트 스트링 인스턴스를 반환합니다.
어린이 세포의 배열과 같은 물체를 반환합니다.
이 셀의 SHA-256 해시를 반환합니다.
셀의 내용을 재귀 적으로 인쇄합니다.
/**
* @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 ): Uint8ArrayBOC 바이트 배열을 만듭니다.
OlifantonBocSlice Slice 는 셀 슬라이스의 유형입니다. 셀을 슬라이스로 변환 할 수있는 다음, 데이터 비트 및 셀의 다른 셀에 대한 참조는 슬라이스에서로드하여 얻을 수 있습니다.
load% (loadbit, loaduint, ...) 메소드 슬라이스 내부 커서를 움직입니다. 자유 비트의 길이를 초과하는 값을 읽으려고하면 SliceException 예외가 발생합니다.
/**
* @param ajfTypedArraysUint8Array $array
* @param int $length
* @param OlifantonBocSlice[] $refs
*/
public function __construct( Uint8Array $ array , int $ length , array $ refs )매개 변수 :
$array - 셀의 비트 스트링 표현에서 uint8array$length - 비트 스트링 길이$refs - 어린이 세포 슬라이스 내부 커서에 따라 읽지 않은 비트를 반환합니다.
/**
* @param int $n
*/
public function get( int $ n ): bool 위치 $n 에서 비트 값을 반환합니다.
조금 읽고 커서를 움직입니다.
/**
* @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 나노 톤 코인에서 톤량을 읽습니다.
주소를 읽습니다.
어린이 조각을 읽습니다.
composer run testMIT