mercator / dcorephp-sdk
DCore PHP SDK 库
2.5.0
2019-07-29 12:44 UTC
Requires
- php: >=7.1
- ext-bcmath: *
- ext-curl: *
- ext-gmp: *
- ext-json: *
- ext-openssl: *
- bitcoin-php/bitcoin-ecdsa: 1.3.4
- codacy/coverage: ^1.4
- doctrine/annotations: 1.6.1
- kornrunner/secp256k1: ^0.1.1
- stephenhill/base58: 1.1.4
- symfony/process: ^4.2
- symfony/property-access: ^3.4
- symfony/property-info: ^4.3
- symfony/serializer: ^4.3
- symfony/validator: ^4.2
- textalk/websocket: 1.2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: 3.0.x-dev
- phpmd/phpmd: 2.6.0
- phpunit/phpunit: ^7
- squizlabs/php_codesniffer: 3.4.0
- symfony/var-dumper: ^3.4
This package is auto-updated.
Last update: 2024-09-29 05:57:10 UTC
README
访问 DCore 区块链的 API 集合。
如果您正在寻找其他平台,您可以在以下位置找到信息:此处。
要求
- composer
- php ~7.1
- php json
- php bcmath
- php gmp
- php openssl
- symfony PropertyAccess 组件
- websocket-php - websocket 库
- stephen-hill/base58php - base58 转换库
- kornrunner/php-secp256k1 - secp256k1 库
- BitcoinPHP/BitcoinECDSA.php - ecdsa 库
安装
composer.json
{ "repositories": [ { "type": "vcs", "url": "https://github.com/decentfoundation/dcorephp-sdk" } ], "require": { "decentfoundation/dcorephp-sdk": "dev-master" } }
composer require decentfoundation/dcorephp-sdk
用法
您可以在这里找到包含 SDK 用法的示例项目。
您可以在这里找到最新版本的开发者文档。
DCore API 初始化
$dcoreApi = new \DCorePHP\DCoreApi( 'https://testnet.dcore.io/', 'wss://testnet-socket.dcore.io' );
查看 ./src/DCoreApi.php 和 ./src/Sdk/*Interface.php,以了解所有可用方法和它们的返回值。
获取账户
$account = $dcoreApi->getAccountApi()->get(new ChainObject('1.2.34')); $account = $dcoreApi->getAccountApi()->getByName('Your test account name');
创建账户
在 DCore 网络中创建账户有两种方式:$dcoreApi->getAccountApi()->registerAccount()
和 $dcoreApi->getAccountApi()->createAccountWithBrainKey()
。建议使用 $dcoreApi->getAccountApi()->registerAccount()
方法创建账户,因为它可以指定密钥。您也可以使用 $dcoreApi->getAccountApi()->createAccountWithBrainKey()
,但从 $brainkey
生成的 $publicOwnerKeyWif
、$publicActiveKeyWif
和 $publicMemoKeyWif
密钥将相同,出于安全考虑不推荐。
$dcoreApi->getAccountApi()->registerAccount( 'Your test account name', 'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz', 'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz', 'DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz', new ChainObject('1.2.34'), '5Jd7zdvxXYNdUfnEXt5XokrE3zwJSs734yQ36a1YaqioRTGGLtn' );
创建转账
$dcoreApi->getAccountApi()->transfer( new Credentials(new ChainObject('1.2.34'), '5Jd7zdvxXYNdUfnEXt5XokrE3zwJSs734yQ36a1YaqioRTGGLtn'), '1.2.35', (new AssetAmount())->setAmount(1500000), 'your secret message', false );
创建内容
$content = new SubmitContent(); $content ->setUri($randomUri) ->setCoauthors([]) ->setCustodyData(null) ->setHash('2222222222222222222222222222222222222222') ->setKeyParts([]) ->setSeeders([]) ->setQuorum(0) ->setSize(10000) ->setSynopsis(json_encode([ 'title' => 'Your content title', 'description' => 'Your content description', 'content_type_id' => '1.2.3' ])) ->setExpiration('2019-05-28T13:32:34+00:00') ->setPrice([(new RegionalPrice)->setPrice((new AssetAmount())->setAmount(1000))->setRegion(1)]); $credentials = new Credentials( new ChainObject('1.2.34'), ECKeyPair::fromBase58(DCoreSDKTest::PRIVATE_KEY_1) ); $dcoreApi->getContentApi()->create( $content, $credentials, (new AssetAmount())->setAmount(1000)->setAssetId('1.3.0'), (new AssetAmount())->setAmount(1000)->setAssetId('1.3.0') );
搜索内容
$contents = $dcoreApi->getContentApi()->findAll( 'search term', '-rating' );
NFT
NftModels 需要 @Type("type")
注解才能正常工作。当与整数一起工作时,也需要 必须 使用 GMP 库。
NftModel
class NftApple extends NftModel { /** * @Type("integer") */ public $size; /** * @Type("string") * @Unique */ public $color; /** * @Type("boolean") * @Modifiable("both") */ public $eaten; public function __construct($size, $color, $eaten) { $this->size = gmp_init($size); $this->color = $color; $this->eaten = $eaten; } }
创建 NFT
$credentials = new Credentials(new ChainObject('1.2.27'), ECKeyPair::fromBase58('DCT6MA5TQQ6UbMyMaLPmPXE2Syh5G3ZVhv5SbFedqLPqdFChSeqTz')); $dcoreApi->getNftApi()->create($credentials, 'APPLE', 100, false, 'an apple', NftApple::class, true);
更多示例可以在 ./tests/Sdk/NftApiTest.php 中找到。
开发要求和建议
- docker
- docker-compose
- phpunit
- symfony VarDumper 组件
- php code sniffer
- php code sniffer fixer
- php mess detector
PHPStorm 配置
- https://www.jetbrains.com/help/phpstorm/using-php-code-sniffer.html
- https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html
- https://www.jetbrains.com/help/phpstorm/using-php-mess-detector.html
开发和测试
git clone git@github.com:decentfoundation/dcorephp-sdk.git cd dcorephp-sdk docker-compose up -d docker-compose exec php composer install --dev --prefer-dist --optimize-autoloader docker-compose exec php ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests