
____ __ ______ _____ ____ __ ___ _ _____ _____ ____ __ __
/ __ / / / / __ / ___ // __ / / / | / | / / | / ___// __ / //_/
/ / _ / / / _ / / / _ / / __ / / / / / / / | | / | / / / | | __ / / / / ,<
/ ____ / __ / ____ / ___ / / / _ / / / ___ / ___ | / / | / ___ | ___ / / / _ / / / | |
/ _ / / _ / / _ / _ / / ____ / _ ___ / _____ / _ / | _ / _ / | _ / _ / | _ | / ____ / _____ / _ / | _ | 从verze仓库分叉:verze-app/solana-php-sdk
您可以通过作曲家安装软件包:
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 .然后
docker run -it solana-php-sdk /bin/bash您可以使用Connection类以方便地访问API方法。有些在代码中定义:
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 );有关所有可能的方法,请参见API文档。
Connection类只是RPC客户端顶部的轻便便利层。您可以,如果需要,可以直接使用客户端,这使您可以与完整的Response对象一起工作:
use Attestto SolanaPhpSdk SolanaRpcClient ;
$ client = new SolanaRpcClient (SolanaRpcClient:: MAINNET_ENDPOINT );
$ accountInfoResponse = $ client -> call ( ' getAccountInfo ' , [ ' 4fYNw3dojWmQ4dXtSGE9epjRGy9pFSx62YypT7avPYvA ' ]);
$ accountInfoBody = $ accountInfoResponse -> json ();
$ accountInfoStatusCode = $ accountInfoResponse -> getStatusCode ();这是向Solana区块链发送传输指令的工作示例,您可以使用自定义RPC端点的端点超越端点。
$ 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 );为了使Borsh序列化/值得起作用,必须传递或定义基于程序IDL的程序结构的类::架构对象。例如
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 );
}
}为了更好地了解实施和用法,请参阅以下参考文献:
示例用法(这将得到改善,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序列化并进行序列化。完成 - 测试 - 覆盖范围
改进的文档。 WIP-此文档 +文档索引(https://github.com/attestto-com/solana-php-sdk/tree/master/docs)
构建更多的连接,消息,系统程序,TokenProgram,Metaplex Program类。 WIP-测试 - 覆盖范围4。 ] Spl -Token程序10。[] getorCreateAssciedInAccount()11。[] GetAssivicatiedTokenAddressync()12。
改善围绕使用二进制数据的抽象。完毕? - 测试 - 覆盖范围
优化:
$recentBlockhash 。建议?打开问题或拉请请求:D
WIP-致力于覆盖范围和贬值。请参阅覆盖报告。
"scripts" : {
"test" : " vendor/bin/phpunit tests --coverage-clover=coverage.xml --coverage-filter src/ " ,
"format" : " vendor/bin/php-cs-fixer fix --allow-risk=yes "
},
composer test或者
/verdor/bin/phpunit tests [options]如果发现任何与安全有关的问题,请通过电子邮件发送维护者(请参阅Composer.json),而不是使用问题跟踪器。
麻省理工学院许可证(麻省理工学院)。请参阅许可证文件以获取更多信息。