olifanton/interop แทน พอร์ต PHP ของ tonweb-boc JS Library
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 เป็นหัวใจสำคัญของการเป็นตัวแทน PHP ของเซลล์ TVM BitString เป็นหน่วยความจำที่ได้รับการปรับให้เหมาะสมสำหรับการจัดเก็บข้อมูลไบนารี ภายใน Bitstring ใช้การใช้งานของ Uint8Array ที่จัดทำโดยแพ็คเกจ ajf/typed-arrays และใช้เป็นประเภทพื้นฐานสำหรับการถ่ายโอนข้อมูลไบนารีระหว่างส่วนหนึ่งของไลบรารี Olifanton
อินสแตนซ์ Bitstring ถูกสร้างขึ้นด้วยความยาวคงที่อย่างเคร่งครัด write% (writebit, writeuint, ... ) วิธีการย้ายเคอร์เซอร์ภายใน หากคุณพยายามเขียนค่าที่เกินความยาวของบิตฟรีข้อยกเว้น BitStringException จะถูกโยนลงไป
/**
* @param int $length
*/
public function __construct( int $ length )พารามิเตอร์:
$length - ความยาวของ UINT8ARRAY ค่าเริ่มต้นสำหรับ TVM Cell: 1023 (เอกสาร) ส่งคืนความยาวบิตที่ไม่ได้ใช้งานบิต
ผลตอบแทนความยาวบิตที่ใช้แล้ว
ผลตอบแทนที่ใช้ความยาวไบต์ของบิต
/**
* @param int $n Position
*/
public function get( int $ n ): bool ส่งคืนค่าบิตที่ตำแหน่ง $n
/**
* @param int $n Position
*/
public function on( int $ n ): void ตั้งค่าบิตเป็น 1 ที่ตำแหน่ง $n
/**
* @param int $n Position
*/
public function off( int $ n ): void ตั้งค่าบิตเป็น 0 ที่ตำแหน่ง $n
/**
* @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 integer ที่ไม่ได้ลงชื่อ
/**
* @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 Integer
นามแฝงของวิธี writeUint() ที่มีค่าพารามิเตอร์ $ bitlength ที่กำหนดไว้ล่วงหน้า
/**
* @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 ;เขียนเหรียญใน nanotoncoins 1 ตัน === 1000000000 (10^9) nanotonCoins
/**
* @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เขียนบิตอีกครั้งกับบิตนี้
โคลนนิ่งบิตนี้และส่งคืนอินสแตนซ์บิตใหม่
ส่งคืนสตริง HEX ของ Bitstring
ส่งคืนสำเนา Uint8Array ภายในที่ไม่เปลี่ยนรูป
ส่งคืนขนาดของบิตในบิต
OlifantonBocCell Cell เป็นคลาสที่ใช้แนวคิดของเซลล์ TVM ใน PHP ในการสร้างข้อความใหม่และกระบวนการที่ได้รับจาก blockchain คุณจะทำงานกับอินสแตนซ์ของคลาสเซลล์
ไม่มีพารามิเตอร์
/**
* @param string|Uint8Array $serializedBoc Serialized BoC
* @return Cell[]
*/
public static function fromBoc( string | Uint8Array $ serializedBoc ): arrayสร้างอาร์เรย์ของเซลล์จากอาร์เรย์ไบต์หรือสตริง hex
/**
* @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ดึงหนึ่งเซลล์รูทจากอาร์เรย์ไบต์หรือสตริง hex
/**
* @param Cell $anotherCell Another cell
* @return Cell This Cell
*/
public function writeCell( Cell $ anotherCell ): selfเขียนเซลล์อื่นไปยังเซลล์นี้และส่งคืนเซลล์นี้ วิธีที่ไม่แน่นอน
ส่งคืนความลึกสูงสุดของเซลล์เด็ก
ส่งคืนอินสแตนซ์ bitstring ภายในสำหรับการเขียนและการอ่าน
ส่งคืนวัตถุคล้ายอาเรย์ของเซลล์เด็ก
ส่งคืนแฮช 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 BYTE
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 อ่านจำนวนมากใน nanotoncoins
อ่านที่อยู่
อ่านเซลล์ลูกชิ้น
composer run testมิกซ์