catchain / ton-address
处理 TON 区块链地址的实用函数
1.0.0
2022-12-26 16:47 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-09-26 20:58:59 UTC
README
此包包含一些用于处理 TON 区块链地址的 PHP 实用函数。
安装
composer require catchain/ton-address
使用
检查地址有效性
use Catchain\Ton\Address\Address; Address::isValid('EQB/tWkYGPdyPxqz8TXjVaSTKfr1gOOPqOez4d07vHFqUMuk'); // >>> true Address::isValid('this-is-definitely-not-an-address'); // >>> false
创建地址对象
$address = Address::parse('-1:811ced271f8f449cb51eb5920090b92cb200b20f07170676e9db6fbe9da516cf'); // or in any other format: $address = Address::parse('Uf+BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22++naUWz5id');
对象结构
Catchain\Ton\Address\Address {
+wc: -1,
+hashPart: b"ü\x1CÝ'\x1FÅD£Á\x1EÁÆ\0É╣,▓\0▓\x0F\x07\x17\x06vÚ█o¥ØÑ\x16¤",
+isTestOnly: true,
+isBounceable: true,
+isUserFriendly: true,
+isUrlSafe: true,
}
序列化为字符串(参数含义自明)
$address->toString( userFriendly: true, urlSafe: true, bounceable: true, testOnly: false, ); // >>> Ef-BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22--naUWz8VY
序列化为长格式
$address->toString(userFriendly: false); // >>> -1:811ced271f8f449cb51eb5920090b92cb200b20f07170676e9db6fbe9da516cf
默认情况下,对象序列化为创建时相同的格式
Address::parse('Uf+BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22++naUWz5id')->toString(); // >>> Uf+BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22++naUWz5id Address::parse('kf-BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22--naUWz37S')->toString(); // >>> kf-BHO0nH49EnLUetZIAkLkssgCyDwcXBnbp22--naUWz37S