From b03f34d347ed1df17e12e0b13adf1c61fc38a798 Mon Sep 17 00:00:00 2001 From: ling Date: Tue, 8 Aug 2023 15:58:47 +0800 Subject: [PATCH] fixed laravel bug --- src/ServiceProvider.php | 11 +- src/Services/Contract/ContractService.php | 187 +++++++++++----------- 2 files changed, 106 insertions(+), 92 deletions(-) diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 45d6897..152a7f6 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -8,6 +8,7 @@ use Yoruchiaki\WebaseFront\Interfaces\HttpRequestInterface; use Yoruchiaki\WebaseFront\Services\Contract\ContractService; use Yoruchiaki\WebaseFront\Services\PrivateKey\PrivateKeyService; +use Yoruchiaki\WebaseFront\Services\Tool\ToolService; use Yoruchiaki\WebaseFront\Services\Trans\TransService; class ServiceProvider extends \Illuminate\Support\ServiceProvider implements DeferrableProvider @@ -18,7 +19,7 @@ class ServiceProvider extends \Illuminate\Support\ServiceProvider implements Def public function boot(): void { $this->publishes([ - __DIR__.'/../config/webase-front.php' => config_path('webase-front.php'), + __DIR__ . '/../config/webase-front.php' => config_path('webase-front.php'), ], ['webase-front']); } @@ -26,7 +27,7 @@ public function boot(): void public function register() { $this->mergeConfigFrom( - __DIR__.'/../config/webase-front.php', 'webase-front' + __DIR__ . '/../config/webase-front.php', 'webase-front' ); $this->app->bind(HttpRequestInterface::class, function () { return new HttpRequest( @@ -44,12 +45,18 @@ public function register() return new TransService($app->make(HttpRequestInterface::class)); }); + $this->app->singleton(ToolService::class, function ($app) { + return new ToolService($app->make(HttpRequestInterface::class)); + }); + $this->app->singleton(PrivateKeyService::class, function ($app) { return new PrivateKeyService($app->make(HttpRequestInterface::class)); }); + $this->app->alias(ContractService::class, 'Contract'); $this->app->alias(TransService::class, 'Trans'); $this->app->alias(PrivateKeyService::class, 'Pk'); + $this->app->alias(ToolService::class, 'Tool'); } public function provides(): array diff --git a/src/Services/Contract/ContractService.php b/src/Services/Contract/ContractService.php index fd6a32f..ff84824 100644 --- a/src/Services/Contract/ContractService.php +++ b/src/Services/Contract/ContractService.php @@ -11,113 +11,118 @@ class ContractService extends BaseService implements ContractInterface { /** - * @param Solidity $solidity 合约对象 - * @param string $contractAddress 合约地址 + * @param Solidity $solidity 合约对象 + * @param string $contractAddress 合约地址 * * @return array * @throws GuzzleException */ public function abiInfo( Solidity $solidity, - string $contractAddress - ): array { + string $contractAddress + ): array + { return $this->http->request('POST', 'contract/abiInfo', [ - 'groupId' => $this->groupId, + 'groupId' => $this->groupId, 'contractName' => $solidity->getContractName(), - 'address' => $contractAddress, - 'contractBin' => $solidity->getSolidityBin(), - 'abiInfo' => $solidity->getSolidityAbi()->toArray() + 'address' => $contractAddress, + 'contractBin' => $solidity->getSolidityBin(), + 'abiInfo' => $solidity->getSolidityAbi()->toArray() ]); } /** - * @param string $signUserId - * @param Solidity $solidity - * @param string|null $version + * @param string $signUserId + * @param Solidity $solidity + * @param string|null $version * * @return array * @throws GuzzleException */ public function deployWithSign( - string $signUserId, + string $signUserId, Solidity $solidity, - string $version = null - ): array { + string $version = null + ): array + { return $this->http->request('POST', 'contract/deployWithSign', [ - 'groupId' => $this->groupId, - 'signUserId' => $signUserId, - 'abiInfo' => $solidity->getSolidityAbi()->toArray(), + 'groupId' => $this->groupId, + 'signUserId' => $signUserId, + 'abiInfo' => $solidity->getSolidityAbi()->toArray(), 'bytecodeBin' => $solidity->getSolidityBin()->toString(), - 'funcParam' => $solidity->getConstructParams() + 'funcParam' => $solidity->getConstructParams() ]); } /** - * @param string $user - * @param Solidity $solidity + * @param string $user + * @param Solidity $solidity * * @return array * @throws GuzzleException */ public function deploy( - string $user, + string $user, Solidity $solidity - ): array { + ): array + { return $this->http->request('POST', 'contract/deploy', [ - 'groupId' => $this->groupId, - 'user' => $user, + 'groupId' => $this->groupId, + 'user' => $user, 'contractName' => $solidity->getContractName(), - 'abiInfo' => $solidity->getSolidityAbi()->toArray(), - 'bytecodeBin' => $solidity->getSolidityBin() + 'abiInfo' => $solidity->getSolidityAbi()->toArray(), + 'bytecodeBin' => $solidity->getSolidityBin() ]); } /** - * @param Solidity $solidity - * @param string $packageName + * @param Solidity $solidity + * @param string $packageName * * @return array * @throws GuzzleException */ public function compileJava( Solidity $solidity, - string $packageName - ): array { + string $packageName + ): array + { return $this->http->request('POST', 'contract/compile-java', [ - 'contractBin' => $solidity->getSolidityBin()->toString(), + 'contractBin' => $solidity->getSolidityBin()->toString(), 'contractName' => $solidity->getContractName(), - 'abiInfo' => $solidity->getSolidityAbi()->toArray(), - 'packageName' => $packageName + 'abiInfo' => $solidity->getSolidityAbi()->toArray(), + 'packageName' => $packageName ] ); } /** - * @param Solidity $solidity - * @param string $contractPath + * @param Solidity $solidity + * @param string $contractPath * * @return array * @throws GuzzleException */ public function save( Solidity $solidity, - string $contractPath - ): array { + string $contractPath + ): array + { return $this->http->request('POST', 'contract/save', [ - 'groupId' => $this->groupId, - 'contractName' => $solidity->getContractName(), - 'contractBin' => $solidity->getSolidityBin()->toString(), - 'contractPath' => $contractPath, - 'contractAbi' => $solidity->getSolidityAbi()->toString(), + 'groupId' => $this->groupId, + 'contractName' => $solidity->getContractName(), + 'contractBin' => $solidity->getSolidityBin()->toString(), + 'contractPath' => $contractPath, + 'contractAbi' => $solidity->getSolidityAbi()->toString(), 'contractSource' => $solidity->getSoliditySol()->toString() ] ); } /** - * @param int $contractId + * @param int $contractId * * @return array * @throws GuzzleException @@ -128,39 +133,40 @@ public function deleteContract(int $contractId): array } /** - * @param int $pageNumber - * @param int $pageSize - * @param string|null $contractName - * @param int|null $contractStatus - * @param string|null $contractAddress - * @param string|null $contractPath + * @param int $pageNumber + * @param int $pageSize + * @param string|null $contractName + * @param int|null $contractStatus + * @param string|null $contractAddress + * @param string|null $contractPath * * @return array * @throws GuzzleException */ public function contractList( - int $pageNumber = 1, - int $pageSize = 10, + int $pageNumber = 1, + int $pageSize = 10, string $contractName = null, - int $contractStatus = null, + int $contractStatus = null, string $contractAddress = null, string $contractPath = null - ): array { + ): array + { return $this->http->request('POST', 'contract/contractList', [ - 'groupId' => $this->groupId, - 'pageNumber' => $pageNumber, - 'pageSize' => $pageSize, - 'contractName' => $contractName, - 'contractStatus' => $contractStatus, + 'groupId' => $this->groupId, + 'pageNumber' => $pageNumber, + 'pageSize' => $pageSize, + 'contractName' => $contractName, + 'contractStatus' => $contractStatus, 'contractAddress' => $contractAddress, - 'contractPath' => $contractPath + 'contractPath' => $contractPath ] ); } /** - * @param int $contractId + * @param int $contractId * * @return array * @throws GuzzleException @@ -171,8 +177,8 @@ public function ifChanged(int $contractId): array } /** - * @param string $contractName - * @param SoliditySol $soliditySource + * @param string $contractName + * @param SoliditySol $soliditySource * * @return array * @throws GuzzleException @@ -180,13 +186,13 @@ public function ifChanged(int $contractId): array public function contractCompile(string $contractName, SoliditySol $soliditySource): array { return $this->http->request('POST', "contract/contractCompile", [ - 'contractName' => $contractName, + 'contractName' => $contractName, 'solidityBase64' => $soliditySource->toString() ]); } /** - * @param string $contractZipBase64 + * @param string $contractZipBase64 * * @return array * @throws GuzzleException @@ -199,7 +205,7 @@ public function multiContractCompile(string $contractZipBase64): array } /** - * @param int $contractStatus + * @param int $contractStatus * * @return array * @throws GuzzleException @@ -209,14 +215,14 @@ public function contractListFull(int $contractStatus): array return $this->http->request('get', "contract/contractList/all/light", [ - 'groupId' => $this->groupId, + 'groupId' => $this->groupId, 'contractStatus' => $contractStatus ] ); } /** - * @param int $contractId + * @param int $contractId * * @return array * @throws GuzzleException @@ -236,7 +242,7 @@ public function findContractPathList(): array } /** - * @param string $contractPath + * @param string $contractPath * * @return array * @throws GuzzleException @@ -244,13 +250,13 @@ public function findContractPathList(): array public function addContractPath(string $contractPath): array { return $this->http->request('POST', "contract/addContractPath", [ - 'groupId' => $this->groupId, + 'groupId' => $this->groupId, 'contractPath' => $contractPath ]); } /** - * @param string $contractPath + * @param string $contractPath * * @return array * @throws GuzzleException @@ -261,7 +267,7 @@ public function deleteContractPath(string $contractPath): array } /** - * @param string $contractPath + * @param string $contractPath * * @return array * @throws GuzzleException @@ -272,38 +278,39 @@ public function deleteContractByPath(string $contractPath): array } /** - * @param Solidity $solidity - * @param string $contractAddress - * @param string $cnsName - * @param string $version - * @param string $signUserId + * @param Solidity $solidity + * @param string $contractAddress + * @param string $cnsName + * @param string $version + * @param string $signUserId * * @return array * @throws GuzzleException */ public function registerCns( Solidity $solidity, - string $contractAddress, - string $cnsName, - string $version, - string $signUserId - ): array { + string $contractAddress, + string $cnsName, + string $version, + string $signUserId + ): array + { return $this->http->request('POST', "contract/registerCns", [ - 'groupId' => $this->groupId, - 'contractName' => $solidity->getContractName(), - 'cnsName' => $cnsName, + 'groupId' => $this->groupId, + 'contractName' => $solidity->getContractName(), + 'cnsName' => $cnsName, 'contractAddress' => $contractAddress, - 'abiInfo' => $solidity->getSolidityAbi()->toArray(), - 'version' => $version, - 'saveEnabled' => false, - 'signUserId' => $signUserId + 'abiInfo' => $solidity->getSolidityAbi()->toArray(), + 'version' => $version, + 'saveEnabled' => false, + 'signUserId' => $signUserId ] ); } /** - * @param string $contractAddress + * @param string $contractAddress * * @return array * @throws GuzzleException @@ -311,7 +318,7 @@ public function registerCns( public function findCns(string $contractAddress): array { return $this->http->request('POST', 'contract/findCns', [ - 'groupId' => $this->groupId, + 'groupId' => $this->groupId, 'contractAddress' => $contractAddress ]); }