coreto / coreto-drt-sdk
用于与Coreto DRS交互的Laravel SDK
dev-master
2022-12-06 08:47 UTC
This package is auto-updated.
Last update: 2024-09-14 14:55:42 UTC
README
用于与Coreto DRS交互的Laravel SDK
依赖关系
- PHP >=7.4
通过Composer安装
要安装,只需运行
composer require coreto/coreto-drt-sdk
或手动将其添加到composer.json
{
"require": {
"coreto/coreto-drt-sdk": "~1"
}
}
直接使用
use Coreto\CoretoDRTSDK\Client; $client = new Client( $apiUrl, // The base URL of the API $callerAccountId, // The account ID of the caller (must be a registered source) $callerPrivateKey // The private key of the caller );
保存操作批处理
$response = $client->saveActionsBatch([ 'batch' => [[ 'account_did' => 'did:example:example1', 'action_date' => 1669121362000, 'action_type' => 'react', 'trust' => 1, 'performance' => 0.3, 'identifier' => 123 ], [ 'account_did' => 'did:example:example2', 'action_date' => 1669121369000, 'action_type' => 'comment', 'trust' => 0.7, 'performance' => 1, 'identifier' => 124 ]] ]); // [ // 'hash' => '8cAXpSnCyoUTmtE32wrzVuldgC9ro3EHLNy4EzRXQUkg' // ] // on error returns null // on error returns null
保存操作
$response = $client->saveAction([ 'account_did' => 'did:example:example', 'action_date' => 1669121362000, 'action_type' => 'react', 'trust' => 1, 'performance' => 1, 'identifier' => 123 ]); // [ // 'hash' => '8cAXpSnCyoUTmtE32wrzVuldgC9ro3EHLNy4EzRXQUkg' // ] // on error returns null
获取用户操作
$response = $client->getUserActions([ 'source_label' => 'example', 'account_did' => 'did:example:example', ]); // [{ // 'account_did' => 'did:example:example1', // 'action_date' => 1669121362000, // 'action_type' => 'react', // 'trust' => 1, // 'performance' => 0.3, // 'identifier' => 123 // }, { // 'account_did' => 'did:example:example2', // 'action_date' => 1669121369000, // 'action_type' => 'comment', // 'trust' => 0.7, // 'performance' => 1, // 'identifier' => 124 // }]
获取用户信任操作
$response = $client->getUserTrustActions([ 'source_label' => 'example', 'account_did' => 'did:example:example', ]); // [{ // 'account_did' => 'did:example:example1', // 'action_date' => 1669121362000, // 'action_type' => 'react', // 'trust' => 1, // 'performance' => 0, // 'identifier' => 123 // }, { // 'account_did' => 'did:example:example2', // 'action_date' => 1669121369000, // 'action_type' => 'comment', // 'trust' => 0.7, // 'performance' => 0, // 'identifier' => 124 // }]
获取用户性能操作
$response = $client->getUserPerformanceActions([ 'source_label' => 'example', 'account_did' => 'did:example:example', ]); // [{ // 'account_did' => 'did:example:example1', // 'action_date' => 1669121362000, // 'action_type' => 'react', // 'trust' => 0, // 'performance' => 0.9, // 'identifier' => 123 // }, { // 'account_did' => 'did:example:example2', // 'action_date' => 1669121369000, // 'action_type' => 'comment', // 'trust' => 0, // 'performance' => 0.2, // 'identifier' => 124 // }]
获取源操作类型
$response = $client->getSourceActionTypes([ 'source' => 'source.near' ]); // ['react', 'comment', 'opinion']
创建DID
$response = $client->createDID(); // [ // 'did' => 'did:example:example', // 'seed' => 'seed_example' // ] // on error returns null
放置DID
$response = $client->putDID([ 'account_id' => 'example.near', 'did' => 'did:example:example' ]); // [ // 'hash' => '8cAXpSnCyoUTmtE32wrzVuldgC9ro3EHLNy4EzRXQUkg' // ] // on error returns null
获取DID
$response = $client->getDID([ 'account_id' => 'example.near' ]); // did:example:example // on error returns null
有DID
$response = $client->hasDID([ 'account_id' => 'example.near' ]); // true // on error returns null
转移DID
$response = $client->transferDID([ 'old_account_id' => 'old_example.near', 'new_account_id' => 'new_example.near', ]); // [ // 'hash' => '8cAXpSnCyoUTmtE32wrzVuldgC9ro3EHLNy4EzRXQUkg' // ] // on error returns null
获取当前区块高度
$response = $client->getCurrentBlockHeight(); // 105783543 // on error returns -1
获取账户余额
$response = $client->getBalance('example.near'); // 25 // on error returns null
错误
// Smart contract error [ 'error' => 'The error resulted from the smart contract', 'type' => 'The error type resulted from the smart contract' ] // Internal server error [ 'error' => 'The error resulted from the server', 'statusCode' => 'The error status code resulted from the server', 'message' => 'The error message resulted from the server' ]
待办事项
- 添加单元和集成测试
- 更新文档