coreto / coreto-rcs-sdk
一个用于收集和验证Coreto DRS中使用的KPIs的SDK
dev-master
2022-12-14 11:00 UTC
This package is auto-updated.
Last update: 2024-09-14 14:40:04 UTC
README
一个用于收集和验证Coreto DRS中使用的KPIs的SDK
依赖
- PHP >=7.4
通过Composer安装
要安装,只需运行
composer require coreto/coreto-rcs-sdk
或将它手动添加到composer.json
{
"require": {
"coreto/coreto-rcs-sdk": "~1"
}
}
直接使用
use Coreto\CoretoRCSSDK\Client; $reputationCollectionClient = new Client( [ 'react' => null, // Key-value pairs of allowed action and allowed fluctuation for that action 'comment' => 2, 'opinion' => 4 ] ); $reputationCollectionClient->validate([ 'account_did' => 'did:example:example1', // The account DID 'action_date' => 1669121362000, // The unix timestamp in ms of the action 'action_type' => 'react', // The action type (must be one of the allowed types) 'trust' => 1, // The trust value (must be less than the score fluctuation if one is set) 'performance' => 0.3, // The performance value (must be less than the score fluctuation if one is set) 'identifier' => 123 // The identifier of the action (can be used if actions are first cached and then sent to the ledger in order to validate the sync) ]);
错误
// Initialization exception try { $reputationCollectionClient = new Client( [] ); } catch (Exception $e) { // Action whitelist cannot be empty } // Score fluctuation error $reputationCollectionClient = new Client( [ 'react' => 1 ] ); try { $reputationCollectionClient->validate([ 'account_did' => 'did:example:example1', 'action_date' => 1669121362000, 'action_type' => 'react', 'trust' => 5, 'performance' => 0.3, 'identifier' => 123 ]); } catch (Coreto\Coreto\CoretoReputationCollectionSDK\InvalidScoreChangeException $e) { // Scores cannot fluctuate more than the amount set on initialization } // Invalid action type error $reputationCollectionClient = new Client( [ 'react' => null, 'comment' => 2, 'opinion' => 4 ] ); try { $reputationCollectionClient->validate([ 'account_did' => 'did:example:example1', 'action_date' => 1669121362000, 'action_type' => 'create', 'trust' => 0, 'performance' => 0.3, 'identifier' => 123 ]); } catch (Coreto\Coreto\CoretoReputationCollectionSDK\InvalidActionException $e) { // Action type is not in the whitelist } // Invalid action schema error try { $reputationCollectionClient->validate([ // 'account_did' => 'did:example:example1', 'action_date' => 1669121362000, 'action_type' => 'react', 'trust' => 0, 'performance' => 0.3, 'identifier' => 123 ]); } catch (Coreto\Coreto\CoretoReputationCollectionSDK\InvalidActionSchemaException $e) { // Action type is not in the whitelist }
待办事项
- 添加单元和集成测试
- 更新文档