Skip to content

Commit

Permalink
Merge pull request #21 from AElfProject/dev
Browse files Browse the repository at this point in the history
Release v1.2.3
jason-aelf authored Mar 9, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents b24fab7 + a2e3f12 commit a01f6ac
Showing 293 changed files with 99,984 additions and 43,277 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/vendor/
/.idea/
145 changes: 143 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,143 @@
# aelf-sdk.php
AElf php SDK
# AElf-sdk.php

#Introduction

This is a PHP client library, used to communicate with the [AElf](https://github.com/AElfProject/AElf) API.

## Installation
AElf php SDK

In order to install this library via composer run the following command in the console:

```lang=bash
$ composer require aelf/aelf-sdk
```
composer require curl/curl

If you directly clone the sdk You must install composer and execute it in the root directory

```lang=bash
"aelf/aelf-sdk": "dev-dev"
```

## Environment configuration And extensions that need to be turned on

```lang=bash
1. PHP => 7.0
2. gmp
3. curl
```

## Basic usage

```php
require_once 'vendor/autoload.php';
use AElf\AElf;
$url = '127.0.0.1:8000';
$aelfClient = new AElf($url);
$height = $aelfClient->GetBlockHeight();
```
### Examples

You can also see full examples in `./example`;

### Interface

Interface methods can be easily available by the instance "aelfClient" shown in basic usage. The following is a list of input parameters and output for each method. Check out the [Web api reference](https://docs.aelf.io/v/dev/reference) for detailed Interface description.

#### IBlockAppService

```php
public function getBlockHeight();

public function getBlockByHash($blockHash,$includeTransactions = false);

public function getBlockByHeight($blockHeight,$includeTransactions = false);

```

#### IChainAppService

```php
public function getChainStatus();

public function getContractFileDescriptorSet($address);

public function getCurrentRoundInformationAsync();

public function getTaskQueueStatusAsync();

public function getChainIdAsync();
```
#### INetAppService

```php
public function addPeer($address);

public function removePeer($address);

public function getPeers($withMetrics);

public function getNetworkInfo();
```
#### ITransactionAppService

```php
public function getTransactionPoolStatus();

public function executeTransaction($input);

public function executeRawTransaction($input);

public function createRawTransaction($input);

public function sendRawTransaction($input);

public function sendTransaction($input);

public function sendTransactions($input);

public function getTransactionResult($transactionId);

public function getTransactionResults($blockHash, $offset = 0, $limit = 10);

public function getMerklePathByTransactionId($transactionId);
```

#### IClientService

```php
public function isConnected();

public function getFormattedAddress($privateKey, $address);

public function getAddressFromPubKey($pubKey) ;

public function getGenesisContractAddress();

public function getContractAddressByName($privateKey, $contractNameHash);
```
### Test

This module contains tests for all services provided by AElf. You can see how to properly use services provided by AElf here.

You need to firstly set necessary parameters to make sure tests can run successfully.

1. Set baseUrl to your target url.


```php

$url = "Http://127.0.0.1:8001";
```


2. Give a valid privateKey of a node.

```php
$this->privateKey = 'be3abe5c1439899ac2efd0001e15715fd989a3ae11f09e1cb95d320cd4993e2a';
```

### Note

You need to run a local or remote AElf node to run the unit test successfully. If you're not familiar with how to run a node or multiple nodes, please see [Running a node](https://docs.AElf.io/v/dev/main/main/run-node) / [Running multiple nodes](https://docs.AElf.io/v/dev/main/main/multi-nodes) for more information.
87 changes: 87 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
jobs:
# All tasks on window
- job: build_all_window
pool:
vmImage: 'windows-2019'
variables:
phpVersion: 8.2
steps:
- task: UseDotNet@2
inputs:
version: '6.0.x'
- script: |
cp scripts/aelf-node/php.ini /c/tools/php/php.ini
php -c /c/tools/php/php.ini
- script: |
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php composer.phar config -g repo.packagist composer https://packagist.phpcomposer.com
php composer.phar install --no-interaction --prefer-dist --ignore-platform-reqs
displayName: 'composer install'
- powershell: ./scripts/aelf-node/start-window.ps1
displayName: 'deploy and test'
# All tasks on Linux
- job: build_all_linux
displayName: Build all tasks (Linux)
services:
redis:
image: redis
ports:
- 6379:6379
pool:
vmImage: ubuntu-latest
variables:
phpVersion: 8.2
steps:
- task: UseDotNet@2
inputs:
version: '6.0.x'
- script: cd scripts/aelf-node && bash start.sh
displayName: 'Deploy a full node'
- script: |
sudo update-alternatives --set php /usr/bin/php$(phpVersion)
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
php -version
displayName: 'Use PHP version $(phpVersion)'
- script: |
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer
composer config -g repo.packagist composer https://packagist.phpcomposer.com
composer install --no-interaction --prefer-dist --ignore-platform-reqs
displayName: 'composer install'
- script: php phpunit.phar --bootstrap bootstrap.php tests/AElfTest.php
displayName: 'test'
- job: build_all_macos
# All tasks on macOS
displayName: Build all tasks (macos)
pool:
vmImage: macOS-latest
variables:
phpVersion: 8.2
steps:
- task: UseDotNet@2
inputs:
version: '6.0.x'
- script: cd scripts/aelf-node && bash start-mac.sh
displayName: 'Deploy a full node'
- script: |
sudo update-alternatives --set php /usr/bin/php$(phpVersion)
sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
php -version
displayName: 'Use PHP version $(phpVersion)'
- script: |
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer
composer config -g repo.packagist composer https://packagist.phpcomposer.com
composer install --no-interaction --prefer-dist --ignore-platform-reqs
- script: php phpunit.phar --bootstrap bootstrap.php tests/AElfTest.php
displayName: 'test'

2 changes: 2 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
require __DIR__ . '/vendor/autoload.php';
86 changes: 43 additions & 43 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
{
"name": "aelf/aelf-sdk",
"type": "library",
"description": "AElf php SDK",
"keywords": ["aelf-sdk","aelf","AElf php SDK"],
"license": "MIT",
"authors": [

],
"homepage": "https://github.com/AElfProject/aelf-sdk.php",
"require": {
"php": ">=5.6",
"ext-gmp": "*",
"ext-curl": "*",
"kornrunner/secp256k1": "^0.1.2"
},
"require-dev": {
"phpunit/phpunit": "^6.2"
},
"autoload": {
"classmap": [
"src/helper"
],
"files":["src/helper/Sha.php"],
"psr-4": {
"Aelf\\": "src/",
"Aelf\\Api\\":"src/sdk/",
"Hhxsv5\\PhpMultiCurl\\": "src/helper",
"StephenHill\\": "src/helper",
"StephenHill\\Benchmarks\\": "benchmarks/",
"Aelf\\AelfECDSA\\": "src/helper/",
"Google\\Protobuf\\": "src/pro/Google/Protobuf",
"GPBMetadata\\Google\\Protobuf\\": "src/GPBMetadata/Google/Protobuf",
"Aelf\\Protobuf\\Generated\\": "src/pro/Aelf/Protobuf/Generated/",
"GPBMetadata\\": "src/pro/GPBMetadata/"
}
},
"autoload-dev": {
"psr-4": {
"Aelf\\example\\": "example/"
}
}
}
{
"name": "aelf/aelf-sdk",
"type": "library",
"description": "AElf php SDK",
"keywords": ["aelf-sdk","aelf","AElf php SDK"],
"license": "MIT",
"authors": [

],
"homepage": "https://github.com/AElfProject/aelf-sdk.php",
"require": {
"php": ">=5.6",
"ext-gmp": "*",
"ext-curl": "*",
"kornrunner/secp256k1": "^0.1.2",
"hhxsv5/php-multi-curl": "~1.0",
"stephenhill/base58": "^1.1",
"bitcoin-php/bitcoin-ecdsa" : "^1.3",
"google/protobuf": "^3.11",
"tuupola/base58": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^10"
},
"autoload": {
"classmap": [
"src/helper"
],
"files":["src/helper/Sha.php","src/helper/CurlUniversalRequest.php"],
"psr-4": {
"AElf\\": "src/",
"AElf\\Api\\":"src/sdk/",
"Google\\Protobuf\\": "src/protobuf/Google/Protobuf",
"AElf\\Protobuf\\Generated\\": "src/protobuf/AElf/Protobuf/Generated/",
"GPBMetadata\\":"src/protobuf/GPBMetadata"
}
},
"autoload-dev": {
"psr-4": {
"AElf\\example\\": "example/"
}
}
}
Loading

0 comments on commit a01f6ac

Please sign in to comment.