
____ __ ______ _____ ____ __ ___ _ _____ _____ ____ __ __
/ __ / / / / __ / ___ // __ / / / | / | / / | / ___// __ / //_/
/ / _ / / / _ / / / _ / / __ / / / / / / / | | / | / / / | | __ / / / / ,<
/ ____ / __ / ____ / ___ / / / _ / / / ___ / ___ | / / | / ___ | ___ / / / _ / / / | |
/ _ / / _ / / _ / _ / / ____ / _ ___ / _____ / _ / | _ / _ / | _ / _ / | _ | / ____ / _____ / _ / | _ | Forked From The Verze Repo: Verze-App/Solana-PHP-SDK
Anda dapat menginstal paket melalui komposer:
composer require attestto/solana-php-sdkgit clone https://github.com/Attestto-com/solana-php-sdk.git
cd solana-php-sdk
composer install
docker build -t solana-php-sdk .Kemudian
docker run -it solana-php-sdk /bin/bash Anda dapat menggunakan kelas Connection untuk akses yang mudah ke metode API. Beberapa didefinisikan dalam kode:
use Attestto SolanaPhpSdk Connection ;
use Attestto SolanaPhpSdk SolanaRpcClient ;
// Using a defined method
$ sdk = new Connection ( new SolanaRpcClient (SolanaRpcClient:: MAINNET_ENDPOINT ));
$ accountInfo = $ sdk -> getAccountInfo ( ' 4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA ' );
var_dump ( $ accountInfo );Untuk semua metode yang mungkin, lihat dokumentasi API.
Kelas Connection hanyalah lapisan kenyamanan ringan di atas klien RPC. Anda dapat, jika Anda mau, menggunakan klien secara langsung, yang memungkinkan Anda untuk bekerja dengan objek Response penuh:
use Attestto SolanaPhpSdk SolanaRpcClient ;
$ client = new SolanaRpcClient (SolanaRpcClient:: MAINNET_ENDPOINT );
$ accountInfoResponse = $ client -> call ( ' getAccountInfo ' , [ ' 4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA ' ]);
$ accountInfoBody = $ accountInfoResponse -> json ();
$ accountInfoStatusCode = $ accountInfoResponse -> getStatusCode ();Berikut ini adalah contoh yang berfungsi untuk mengirim instruksi transfer ke blockchain Solana, Anda dapat menguasai titik akhir dengan titik akhir RPC khusus.:
$ client = new SolanaRpcClient (SolanaRpcClient:: DEVNET_ENDPOINT );
$ connection = new Connection ( $ client );
$ fromPublicKey = KeyPair:: fromSecretKey ([...]);
$ toPublicKey = new PublicKey ( ' J3dxNj7nDRRqRRXuEMynDG57DkZK4jYRuv3Garmb1i99 ' );
$ instruction = SystemProgram:: transfer (
$ fromPublicKey -> getPublicKey (),
$ toPublicKey ,
6
);
$ transaction = new Transaction ( null , null , $ fromPublicKey -> getPublicKey ());
$ transaction -> add ( $ instruction );
$ txHash = $ connection -> sendTransaction ( $ transaction , $ fromPublicKey );Agar serialisasi/deseralisasi borsh berfungsi, sebuah objek kelas :: skema yang mencerminkan struct program, berdasarkan program IDL harus dilewati atau ditentukan. misalnya
class DidData
{
use BorshObject; //trait
public $ keyData ;
public const SCHEMA = [
VerificationMethodStruct::class => VerificationMethodStruct:: SCHEMA [VerificationMethodStruct::class],
ServiceStruct::class => ServiceStruct:: SCHEMA [ServiceStruct::class],
self ::class => [
' kind ' => ' struct ' ,
' fields ' => [
[ ' offset ' , ' u64 ' ],
[ ' version ' , ' u8 ' ],
[ ' bump ' , ' u8 ' ],
[ ' nonce ' , ' u64 ' ],
[ ' initialVerificationMethod ' , ' string ' ],
[ ' flags ' , ' u16 ' ],
[ ' methodType ' , ' u8 ' ],
[ ' keyData ' , [ ' u8 ' ]],
[ ' verificationMethods ' , [VerificationMethodStruct::class]],
[ ' services ' , [ServiceStruct::class]],
[ ' nativeControllers ' , [ ' pubKey ' ]],
[ ' otherControllers ' , [ ' string ' ]],
],
],
];
public static function fromBuffer ( array $ buffer ): self
{
return Borsh:: deserialize ( self :: SCHEMA , self ::class, $ buffer );
}
}Untuk mendapatkan pemahaman yang lebih baik tentang implementasi dan penggunaan, silakan merujuk ke referensi berikut:
Contoh penggunaan (ini akan ditingkatkan, WIP) :
/**
* deserializeDidData
*
* @param string $dataBase64 The base64 encoded data of the DID data account
* @return DidData The deserialized DID data object
* @example DidSolProgram::deserializeDidData('TVjvjfsd7fMA/gAAAA...');
*/
static function deserializeDidData ( $ dataBase64 )
{
$ base64String = base64_decode ( $ dataBase64 );
$ uint8Array = array_values ( unpack ( ' C* ' , $ base64String ));
$ didData = DidData:: fromBuffer ( $ uint8Array ); // See above code block
$ keyData = $ didData -> keyData ;
$ binaryString = pack ( ' C* ' , ... $ keyData );
$ b58 = new Base58 ();
$ base58String = $ b58 -> encode ( $ binaryString );
$ didData -> keyData = $ base58String ;
return $ didData ;
}$instruction = SystemProgram::abc()Borsh Serialize dan Deserialize. Selesai - Uji - Cakupan
Dokumentasi yang ditingkatkan. WIP-Dokumen ini + Indeks Dokumentasi (https://github.com/attestto-com/solana-php-sdk/tree/master/docs)
Bangun lebih banyak koneksi, pesan, SystemProgram, TokenProgram, kelas MetaplexProgram. WIP - Tes - Cakupan 4. [] Koneksi :: Kelas 5. [x] getLatestBlokchash :: kelas [sumber] - [tes] - [cakupan] 6. [] getMinimumbalanceForRentExemption () 7. [] getTokenAccountBalance () 6. [] TransactionMessage :: Class 7. [] [GetTokenAccountbalance () 6. [] TransactionMessage :: Class 7. [] [) CompoLEtOcbalance () 6. [] TransactionMessage :: Class 7. [] [) CompoLEtOncal () 6. [] TransactionMessage :: Class 7. [] [) COMPILETOV () 6. [] TransactionMessage :: Class 7. [] Program spl -token 10. [] getorcreateassociatiedtokenAccount () 11. [] getAssociatiedTokenAddresssync () 12. [] createassociedtokenAccountInstruction () 11. [] createCncnativeInstruction () - [tes] [Cakupan]
Tingkatkan abstraksi di sekitar bekerja dengan data biner. Selesai? - Tes - Cakupan
Optimalisasi:
$recentBlockhash saat mengirim transaksi.Saran? Buka permintaan atau permintaan tarik: D
WIP - Bekerja pada cakupan dan depresi. Lihat Laporan Cakupan.
"scripts" : {
"test" : " vendor/bin/phpunit tests --coverage-clover=coverage.xml --coverage-filter src/ " ,
"format" : " vendor/bin/php-cs-fixer fix --allow-risk=yes "
},
composer testATAU
/verdor/bin/phpunit tests [options]Jika Anda menemukan masalah terkait keamanan, silakan kirim email ke pengelola (lihat composer.json) alih -alih menggunakan pelacak masalah.
Lisensi MIT (MIT). Silakan lihat file lisensi untuk informasi lebih lanjut.