olifanton/interop 。 PHP港口tonweb-boc JS庫
composer require olifanton/boc通過作曲家安裝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庫之間傳輸二進制數據的基本類型。
Bottring實例是用嚴格固定的長度創建的。 write% (writebit,writeUint,...)方法移動內部光標。如果您嘗試編寫超過自由位長度的值,則將拋出BitStringException異常。
/**
* @param int $length
*/
public function __construct( int $ length )參數:
$length - uint8array的長度。 TVM單元格的默認值: 1023 (文檔) 返回未使用的位長度長度。
返回使用的位長度長度。
返回使用Bytes的bittring長度。
/**
* @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簽名的整數。
具有預定義$位長參數值的writeUint()方法的別名。
/**
* @param ajfTypedArraysUint8Array $ui8 Byte array
*/
public function writeBytes( Uint8Array $ ui8 ): void編寫未簽名的8位整數的數組。
/**
* @param string $value
*/
public function writeString( string $ value ): void寫UTF-8字符串。
/**
* @param int|BrickMathBigInteger $amount
*/
public function writeCoins( int | BigInteger $ amount ): void ;在納米膠蛋白中寫硬幣。 1噸=== 1000000000(10^9)納米膠質。
/**
* @param OlifantonUtilsAddress|null $address TON Address
*/
public function writeAddress(? Address $ address ): void寫噸地址。請參閱Olifanton/Utils軟件包中的地址實現。
/**
* @param OlifantonBocBitString $anotherBitString BitString instance
*/
public function writeBitString( BitString $ anotherBitString ): void將另一個bittrtring寫成這個bottring。
克隆這個bottring並返回新的bittring實例。
返回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將另一個單元格寫給該單元格,然後返回該單元格。可變方法。
返回兒童細胞的最大深度。
返回內部bittring實例進行寫作和閱讀。
返回兒童細胞類似陣列的對象。
返回該單元的SHA-256哈希。
遞歸地打印單元的內容,例如Fift。
/**
* @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創建BOC字節數組。
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 - 來自單元格的bitstring代表的uint8array$length - bottring長度$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 test麻省理工學院