diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 276a9a3d..700375ff 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -25,7 +25,7 @@ jobs: run: | sudo apt-get update -y sudo apt-get install -y nodejs - sudo npm install -g ganache-cli + sudo npm install -g ganache - uses: actions/checkout@v2 diff --git a/.gitignore b/.gitignore index 0aed48d8..f57def41 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,11 @@ composer.phar # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file composer.lock + +*.DS_Store +*.phpunit.result.cache + +# nodejs +node_modules/ +package-lock.json +package.json \ No newline at end of file diff --git a/scripts/test.sh b/scripts/test.sh index de94ecd7..65f5402e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash -ganache-cli -g 0 -l 6000000 > /dev/null & -ganachecli_pid=$! -echo "Start ganache-cli pid: $ganachecli_pid and sleep 3 seconds" +ganache -g 0 -l 6000000 --wallet.seed test,test,test,test,test,test,test,test,test,test,test,test --miner.coinbase 0x4DABDacE120050c79E355A5Ba99047B955f37fFc > /dev/null & +ganache_pid=$! +echo "Start ganache pid: $ganache_pid and sleep 3 seconds" sleep 3 vendor/bin/phpunit --coverage-clover=coverage.xml ret=$? -kill -9 $ganachecli_pid +kill -9 $ganache_pid echo "Kill ganache-cli" exit $ret \ No newline at end of file diff --git a/src/Eth.php b/src/Eth.php index 022aaa7b..95ff9a48 100644 --- a/src/Eth.php +++ b/src/Eth.php @@ -38,7 +38,7 @@ class Eth * @var array */ private $allowedMethods = [ - 'eth_protocolVersion', 'eth_syncing', 'eth_coinbase', 'eth_mining', 'eth_hashrate', 'eth_gasPrice', 'eth_accounts', 'eth_blockNumber', 'eth_getBalance', 'eth_getStorageAt', 'eth_getTransactionCount', 'eth_getBlockTransactionCountByHash', 'eth_getBlockTransactionCountByNumber', 'eth_getUncleCountByBlockHash', 'eth_getUncleCountByBlockNumber', 'eth_getUncleByBlockHashAndIndex', 'eth_getUncleByBlockNumberAndIndex', 'eth_getCode', 'eth_sign', 'eth_sendTransaction', 'eth_sendRawTransaction', 'eth_call', 'eth_estimateGas', 'eth_getBlockByHash', 'eth_getBlockByNumber', 'eth_getTransactionByHash', 'eth_getTransactionByBlockHashAndIndex', 'eth_getTransactionByBlockNumberAndIndex', 'eth_getTransactionReceipt', 'eth_compileSolidity', 'eth_compileLLL', 'eth_compileSerpent', 'eth_getWork', 'eth_newFilter', 'eth_newBlockFilter', 'eth_newPendingTransactionFilter', 'eth_uninstallFilter', 'eth_getFilterChanges', 'eth_getFilterLogs', 'eth_getLogs', 'eth_submitWork', 'eth_submitHashrate' + 'eth_protocolVersion', 'eth_syncing', 'eth_coinbase', 'eth_mining', 'eth_hashrate', 'eth_gasPrice', 'eth_accounts', 'eth_blockNumber', 'eth_getBalance', 'eth_getStorageAt', 'eth_getTransactionCount', 'eth_getBlockTransactionCountByHash', 'eth_getBlockTransactionCountByNumber', 'eth_getUncleCountByBlockHash', 'eth_getUncleCountByBlockNumber', 'eth_getUncleByBlockHashAndIndex', 'eth_getUncleByBlockNumberAndIndex', 'eth_getCode', 'eth_sign', 'eth_sendTransaction', 'eth_sendRawTransaction', 'eth_call', 'eth_estimateGas', 'eth_getBlockByHash', 'eth_getBlockByNumber', 'eth_getTransactionByHash', 'eth_getTransactionByBlockHashAndIndex', 'eth_getTransactionByBlockNumberAndIndex', 'eth_getTransactionReceipt', 'eth_compileSolidity', 'eth_compileLLL', 'eth_compileSerpent', 'eth_getWork', 'eth_newFilter', 'eth_newBlockFilter', 'eth_newPendingTransactionFilter', 'eth_uninstallFilter', 'eth_getFilterChanges', 'eth_getFilterLogs', 'eth_getLogs', 'eth_submitWork', 'eth_submitHashrate', 'eth_feeHistory' ]; /** diff --git a/src/Formatters/FeeHistoryFormatter.php b/src/Formatters/FeeHistoryFormatter.php new file mode 100644 index 00000000..cb388d2e --- /dev/null +++ b/src/Formatters/FeeHistoryFormatter.php @@ -0,0 +1,46 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Formatters; + +use InvalidArgumentException; +use Web3\Utils; +use Web3\Formatters\IFormatter; +use Web3\Formatters\BigNumberFormatter; + +class FeeHistoryFormatter implements IFormatter +{ + /** + * format + * + * @param mixed $value + * @return string + */ + public static function format($value) + { + if (isset($value->oldestBlock)) { + $value->oldestBlock = BigNumberFormatter::format($value->oldestBlock); + } + if (isset($value->baseFeePerGas)) { + foreach ($value->baseFeePerGas as $key => $baseFeePerGas) { + $value->baseFeePerGas[$key] = BigNumberFormatter::format($baseFeePerGas); + } + } + if (isset($value->reward)) { + foreach ($value->reward as $keyOut => $rewards) { + foreach ($rewards as $keyIn => $reward) { + $value->reward[$keyOut][$keyIn] = BigNumberFormatter::format($reward); + } + } + } + return $value; + } +} \ No newline at end of file diff --git a/src/Formatters/NumberFormatter.php b/src/Formatters/NumberFormatter.php index 45fd6dee..3ae2520c 100644 --- a/src/Formatters/NumberFormatter.php +++ b/src/Formatters/NumberFormatter.php @@ -20,15 +20,11 @@ class NumberFormatter implements IFormatter /** * format * - * @param mixed $value - * @return int + * @param int|float $value + * @return int|float */ public static function format($value) { - $value = Utils::toString($value); - $bn = Utils::toBn($value); - $int = (int) $bn->toString(); - - return $int; + return $value; } } \ No newline at end of file diff --git a/src/Methods/Eth/Accounts.php b/src/Methods/Eth/Accounts.php index 4b752208..736826f3 100644 --- a/src/Methods/Eth/Accounts.php +++ b/src/Methods/Eth/Accounts.php @@ -43,16 +43,4 @@ class Accounts extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/BlockNumber.php b/src/Methods/Eth/BlockNumber.php index 7d6d33c4..ba1ca67b 100644 --- a/src/Methods/Eth/BlockNumber.php +++ b/src/Methods/Eth/BlockNumber.php @@ -46,16 +46,4 @@ class BlockNumber extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/Call.php b/src/Methods/Eth/Call.php index 6a605e54..7ba4b5bd 100644 --- a/src/Methods/Eth/Call.php +++ b/src/Methods/Eth/Call.php @@ -56,16 +56,4 @@ class Call extends EthMethod protected $defaultValues = [ 1 => 'latest' ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/Coinbase.php b/src/Methods/Eth/Coinbase.php index 47027b17..abd754a0 100644 --- a/src/Methods/Eth/Coinbase.php +++ b/src/Methods/Eth/Coinbase.php @@ -43,16 +43,4 @@ class Coinbase extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/EstimateGas.php b/src/Methods/Eth/EstimateGas.php index 3f28b59e..ed6ea198 100644 --- a/src/Methods/Eth/EstimateGas.php +++ b/src/Methods/Eth/EstimateGas.php @@ -52,16 +52,4 @@ class EstimateGas extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/FeeHistory.php b/src/Methods/Eth/FeeHistory.php new file mode 100644 index 00000000..21121a91 --- /dev/null +++ b/src/Methods/Eth/FeeHistory.php @@ -0,0 +1,60 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Methods\Eth; + +use InvalidArgumentException; +use Web3\Methods\EthMethod; +use Web3\Validators\TagValidator; +use Web3\Validators\QuantityValidator; +use Web3\Validators\ArrayNumberValidator; +use Web3\Formatters\QuantityFormatter; +use Web3\Formatters\OptionalQuantityFormatter; +use Web3\Formatters\FeeHistoryFormatter; + +class FeeHistory extends EthMethod +{ + /** + * validators + * + * @var array + */ + protected $validators = [ + QuantityValidator::class, [ + TagValidator::class, QuantityValidator::class + ], ArrayNumberValidator::class + ]; + + /** + * inputFormatters + * + * @var array + */ + protected $inputFormatters = [ + QuantityFormatter::class, OptionalQuantityFormatter::class + ]; + + /** + * outputFormatters + * + * @var array + */ + protected $outputFormatters = [ + FeeHistoryFormatter::class + ]; + + /** + * defaultValues + * + * @var array + */ + protected $defaultValues = []; +} \ No newline at end of file diff --git a/src/Methods/Eth/GasPrice.php b/src/Methods/Eth/GasPrice.php index 9218cc17..2cbacf56 100644 --- a/src/Methods/Eth/GasPrice.php +++ b/src/Methods/Eth/GasPrice.php @@ -46,16 +46,4 @@ class GasPrice extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetBalance.php b/src/Methods/Eth/GetBalance.php index 007e97b3..fbf24b75 100644 --- a/src/Methods/Eth/GetBalance.php +++ b/src/Methods/Eth/GetBalance.php @@ -59,16 +59,4 @@ class GetBalance extends EthMethod protected $defaultValues = [ 1 => 'latest' ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetBlockByHash.php b/src/Methods/Eth/GetBlockByHash.php index f81eafda..b78c0ef2 100644 --- a/src/Methods/Eth/GetBlockByHash.php +++ b/src/Methods/Eth/GetBlockByHash.php @@ -51,16 +51,4 @@ class GetBlockByHash extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetBlockByNumber.php b/src/Methods/Eth/GetBlockByNumber.php index 5a19167a..8ba245c5 100644 --- a/src/Methods/Eth/GetBlockByNumber.php +++ b/src/Methods/Eth/GetBlockByNumber.php @@ -56,16 +56,4 @@ class GetBlockByNumber extends EthMethod protected $defaultValues = [ 0 => 'latest' ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetBlockTransactionCountByHash.php b/src/Methods/Eth/GetBlockTransactionCountByHash.php index c8acb879..e318475c 100644 --- a/src/Methods/Eth/GetBlockTransactionCountByHash.php +++ b/src/Methods/Eth/GetBlockTransactionCountByHash.php @@ -52,16 +52,4 @@ class GetBlockTransactionCountByHash extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetBlockTransactionCountByNumber.php b/src/Methods/Eth/GetBlockTransactionCountByNumber.php index 8b53e77e..14d8c6fe 100644 --- a/src/Methods/Eth/GetBlockTransactionCountByNumber.php +++ b/src/Methods/Eth/GetBlockTransactionCountByNumber.php @@ -54,16 +54,4 @@ class GetBlockTransactionCountByNumber extends EthMethod protected $defaultValues = [ 'latest' ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetCode.php b/src/Methods/Eth/GetCode.php index 35db4aac..9d324837 100644 --- a/src/Methods/Eth/GetCode.php +++ b/src/Methods/Eth/GetCode.php @@ -56,16 +56,4 @@ class GetCode extends EthMethod protected $defaultValues = [ 1 => 'latest' ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetFilterChanges.php b/src/Methods/Eth/GetFilterChanges.php index c3534bbd..19ecbb3a 100644 --- a/src/Methods/Eth/GetFilterChanges.php +++ b/src/Methods/Eth/GetFilterChanges.php @@ -49,16 +49,4 @@ class GetFilterChanges extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetFilterLogs.php b/src/Methods/Eth/GetFilterLogs.php index 71d9de80..a9ef66ca 100644 --- a/src/Methods/Eth/GetFilterLogs.php +++ b/src/Methods/Eth/GetFilterLogs.php @@ -49,16 +49,4 @@ class GetFilterLogs extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetLogs.php b/src/Methods/Eth/GetLogs.php index a068ebd5..693abcd9 100644 --- a/src/Methods/Eth/GetLogs.php +++ b/src/Methods/Eth/GetLogs.php @@ -46,16 +46,4 @@ class GetLogs extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetStorageAt.php b/src/Methods/Eth/GetStorageAt.php index 2d6b8da1..9e97e88f 100644 --- a/src/Methods/Eth/GetStorageAt.php +++ b/src/Methods/Eth/GetStorageAt.php @@ -57,16 +57,4 @@ class GetStorageAt extends EthMethod protected $defaultValues = [ 2 => 'latest' ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetTransactionByBlockHashAndIndex.php b/src/Methods/Eth/GetTransactionByBlockHashAndIndex.php index 4aecba9f..03aedabe 100644 --- a/src/Methods/Eth/GetTransactionByBlockHashAndIndex.php +++ b/src/Methods/Eth/GetTransactionByBlockHashAndIndex.php @@ -51,16 +51,4 @@ class GetTransactionByBlockHashAndIndex extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetTransactionByBlockNumberAndIndex.php b/src/Methods/Eth/GetTransactionByBlockNumberAndIndex.php index 5ec7e81a..9e68d2fa 100644 --- a/src/Methods/Eth/GetTransactionByBlockNumberAndIndex.php +++ b/src/Methods/Eth/GetTransactionByBlockNumberAndIndex.php @@ -53,16 +53,4 @@ class GetTransactionByBlockNumberAndIndex extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetTransactionByHash.php b/src/Methods/Eth/GetTransactionByHash.php index 8d5c60a8..211fe231 100644 --- a/src/Methods/Eth/GetTransactionByHash.php +++ b/src/Methods/Eth/GetTransactionByHash.php @@ -49,16 +49,4 @@ class GetTransactionByHash extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetTransactionCount.php b/src/Methods/Eth/GetTransactionCount.php index 468e078f..5039f6af 100644 --- a/src/Methods/Eth/GetTransactionCount.php +++ b/src/Methods/Eth/GetTransactionCount.php @@ -59,16 +59,4 @@ class GetTransactionCount extends EthMethod protected $defaultValues = [ 1 => 'latest' ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetTransactionReceipt.php b/src/Methods/Eth/GetTransactionReceipt.php index 6cd1fdf8..349eb4df 100644 --- a/src/Methods/Eth/GetTransactionReceipt.php +++ b/src/Methods/Eth/GetTransactionReceipt.php @@ -49,16 +49,4 @@ class GetTransactionReceipt extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetUncleByBlockHashAndIndex.php b/src/Methods/Eth/GetUncleByBlockHashAndIndex.php index 28c5d6d0..73318e5b 100644 --- a/src/Methods/Eth/GetUncleByBlockHashAndIndex.php +++ b/src/Methods/Eth/GetUncleByBlockHashAndIndex.php @@ -51,16 +51,4 @@ class GetUncleByBlockHashAndIndex extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetUncleByBlockNumberAndIndex.php b/src/Methods/Eth/GetUncleByBlockNumberAndIndex.php index 1b4e21b4..348e0d65 100644 --- a/src/Methods/Eth/GetUncleByBlockNumberAndIndex.php +++ b/src/Methods/Eth/GetUncleByBlockNumberAndIndex.php @@ -53,16 +53,4 @@ class GetUncleByBlockNumberAndIndex extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetUncleCountByBlockHash.php b/src/Methods/Eth/GetUncleCountByBlockHash.php index 625635ce..afda28d2 100644 --- a/src/Methods/Eth/GetUncleCountByBlockHash.php +++ b/src/Methods/Eth/GetUncleCountByBlockHash.php @@ -52,16 +52,4 @@ class GetUncleCountByBlockHash extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetUncleCountByBlockNumber.php b/src/Methods/Eth/GetUncleCountByBlockNumber.php index dc4ad9fe..9b435066 100644 --- a/src/Methods/Eth/GetUncleCountByBlockNumber.php +++ b/src/Methods/Eth/GetUncleCountByBlockNumber.php @@ -57,16 +57,4 @@ class GetUncleCountByBlockNumber extends EthMethod protected $defaultValues = [ 'latest' ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/GetWork.php b/src/Methods/Eth/GetWork.php index 092edba9..dfb6556b 100644 --- a/src/Methods/Eth/GetWork.php +++ b/src/Methods/Eth/GetWork.php @@ -43,16 +43,4 @@ class GetWork extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/Hashrate.php b/src/Methods/Eth/Hashrate.php index 478f7f50..f2f3ff23 100644 --- a/src/Methods/Eth/Hashrate.php +++ b/src/Methods/Eth/Hashrate.php @@ -46,16 +46,4 @@ class Hashrate extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/Mining.php b/src/Methods/Eth/Mining.php index 71c22f34..505e04b2 100644 --- a/src/Methods/Eth/Mining.php +++ b/src/Methods/Eth/Mining.php @@ -43,16 +43,4 @@ class Mining extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/NewBlockFilter.php b/src/Methods/Eth/NewBlockFilter.php index e9688d9c..e566d37b 100644 --- a/src/Methods/Eth/NewBlockFilter.php +++ b/src/Methods/Eth/NewBlockFilter.php @@ -45,16 +45,4 @@ class NewBlockFilter extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } diff --git a/src/Methods/Eth/NewFilter.php b/src/Methods/Eth/NewFilter.php index 17e3a096..9d8b09f2 100644 --- a/src/Methods/Eth/NewFilter.php +++ b/src/Methods/Eth/NewFilter.php @@ -46,16 +46,4 @@ class NewFilter extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/NewPendingTransactionFilter.php b/src/Methods/Eth/NewPendingTransactionFilter.php index 29657fe2..044b0d0d 100644 --- a/src/Methods/Eth/NewPendingTransactionFilter.php +++ b/src/Methods/Eth/NewPendingTransactionFilter.php @@ -43,16 +43,4 @@ class NewPendingTransactionFilter extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/ProtocolVersion.php b/src/Methods/Eth/ProtocolVersion.php index 032739ec..e9609679 100644 --- a/src/Methods/Eth/ProtocolVersion.php +++ b/src/Methods/Eth/ProtocolVersion.php @@ -46,16 +46,4 @@ class ProtocolVersion extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/SendRawTransaction.php b/src/Methods/Eth/SendRawTransaction.php index 85082007..572a3896 100644 --- a/src/Methods/Eth/SendRawTransaction.php +++ b/src/Methods/Eth/SendRawTransaction.php @@ -49,16 +49,4 @@ class SendRawTransaction extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/SendTransaction.php b/src/Methods/Eth/SendTransaction.php index 990810b3..5ee29fe9 100644 --- a/src/Methods/Eth/SendTransaction.php +++ b/src/Methods/Eth/SendTransaction.php @@ -49,16 +49,4 @@ class SendTransaction extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/Sign.php b/src/Methods/Eth/Sign.php index 05095664..22ff3558 100644 --- a/src/Methods/Eth/Sign.php +++ b/src/Methods/Eth/Sign.php @@ -51,16 +51,4 @@ class Sign extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/SubmitHashrate.php b/src/Methods/Eth/SubmitHashrate.php index b365a19d..7f1904e5 100644 --- a/src/Methods/Eth/SubmitHashrate.php +++ b/src/Methods/Eth/SubmitHashrate.php @@ -46,16 +46,4 @@ class SubmitHashrate extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/SubmitWork.php b/src/Methods/Eth/SubmitWork.php index 44200cfc..19856ca4 100644 --- a/src/Methods/Eth/SubmitWork.php +++ b/src/Methods/Eth/SubmitWork.php @@ -50,16 +50,4 @@ class SubmitWork extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/Syncing.php b/src/Methods/Eth/Syncing.php index 3713320a..3100e40f 100644 --- a/src/Methods/Eth/Syncing.php +++ b/src/Methods/Eth/Syncing.php @@ -43,16 +43,4 @@ class Syncing extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Eth/UninstallFilter.php b/src/Methods/Eth/UninstallFilter.php index a9863ef7..0b4d026d 100644 --- a/src/Methods/Eth/UninstallFilter.php +++ b/src/Methods/Eth/UninstallFilter.php @@ -49,16 +49,4 @@ class UninstallFilter extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/EthMethod.php b/src/Methods/EthMethod.php index 5240eb75..7d584864 100644 --- a/src/Methods/EthMethod.php +++ b/src/Methods/EthMethod.php @@ -46,17 +46,6 @@ class EthMethod extends JSONRPC implements IMethod */ protected $defaultValues = []; - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } /** * getInputFormatters diff --git a/src/Methods/Net/Listening.php b/src/Methods/Net/Listening.php index 8354358a..67f86928 100644 --- a/src/Methods/Net/Listening.php +++ b/src/Methods/Net/Listening.php @@ -43,16 +43,4 @@ class Listening extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Net/PeerCount.php b/src/Methods/Net/PeerCount.php index 85f6582d..49d0098f 100644 --- a/src/Methods/Net/PeerCount.php +++ b/src/Methods/Net/PeerCount.php @@ -46,16 +46,4 @@ class PeerCount extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Net/Version.php b/src/Methods/Net/Version.php index f33f64c2..43340c9c 100644 --- a/src/Methods/Net/Version.php +++ b/src/Methods/Net/Version.php @@ -43,16 +43,4 @@ class Version extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Personal/ListAccounts.php b/src/Methods/Personal/ListAccounts.php index a742767e..650acd07 100644 --- a/src/Methods/Personal/ListAccounts.php +++ b/src/Methods/Personal/ListAccounts.php @@ -43,16 +43,4 @@ class ListAccounts extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Personal/LockAccount.php b/src/Methods/Personal/LockAccount.php index 7baf6399..2ef0b35e 100644 --- a/src/Methods/Personal/LockAccount.php +++ b/src/Methods/Personal/LockAccount.php @@ -48,17 +48,5 @@ class LockAccount extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } diff --git a/src/Methods/Personal/NewAccount.php b/src/Methods/Personal/NewAccount.php index 7af5fa61..7b1b6e0c 100644 --- a/src/Methods/Personal/NewAccount.php +++ b/src/Methods/Personal/NewAccount.php @@ -49,16 +49,4 @@ class NewAccount extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Personal/SendTransaction.php b/src/Methods/Personal/SendTransaction.php index 733f1fb9..b485127b 100644 --- a/src/Methods/Personal/SendTransaction.php +++ b/src/Methods/Personal/SendTransaction.php @@ -51,16 +51,4 @@ class SendTransaction extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Personal/UnlockAccount.php b/src/Methods/Personal/UnlockAccount.php index a28143b1..17111ed1 100644 --- a/src/Methods/Personal/UnlockAccount.php +++ b/src/Methods/Personal/UnlockAccount.php @@ -55,16 +55,4 @@ class UnlockAccount extends EthMethod protected $defaultValues = [ 2 => 300 ]; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/AddToGroup.php b/src/Methods/Shh/AddToGroup.php index 11c69c11..ea91bc57 100644 --- a/src/Methods/Shh/AddToGroup.php +++ b/src/Methods/Shh/AddToGroup.php @@ -46,16 +46,4 @@ class AddToGroup extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/GetFilterChanges.php b/src/Methods/Shh/GetFilterChanges.php index 65b13fa3..1232f742 100644 --- a/src/Methods/Shh/GetFilterChanges.php +++ b/src/Methods/Shh/GetFilterChanges.php @@ -49,16 +49,4 @@ class GetFilterChanges extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/GetMessages.php b/src/Methods/Shh/GetMessages.php index dd58eadf..af107227 100644 --- a/src/Methods/Shh/GetMessages.php +++ b/src/Methods/Shh/GetMessages.php @@ -49,16 +49,4 @@ class GetMessages extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/HasIdentity.php b/src/Methods/Shh/HasIdentity.php index b166332d..a9125983 100644 --- a/src/Methods/Shh/HasIdentity.php +++ b/src/Methods/Shh/HasIdentity.php @@ -46,16 +46,4 @@ class HasIdentity extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/NewFilter.php b/src/Methods/Shh/NewFilter.php index 13b2b779..1da4da89 100644 --- a/src/Methods/Shh/NewFilter.php +++ b/src/Methods/Shh/NewFilter.php @@ -46,16 +46,4 @@ class NewFilter extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/NewGroup.php b/src/Methods/Shh/NewGroup.php index e13b0613..bcb33d60 100644 --- a/src/Methods/Shh/NewGroup.php +++ b/src/Methods/Shh/NewGroup.php @@ -43,16 +43,4 @@ class NewGroup extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/NewIdentity.php b/src/Methods/Shh/NewIdentity.php index 00954dbd..26791105 100644 --- a/src/Methods/Shh/NewIdentity.php +++ b/src/Methods/Shh/NewIdentity.php @@ -43,16 +43,4 @@ class NewIdentity extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/Post.php b/src/Methods/Shh/Post.php index a4708fba..260f04f2 100644 --- a/src/Methods/Shh/Post.php +++ b/src/Methods/Shh/Post.php @@ -49,16 +49,4 @@ class Post extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/UninstallFilter.php b/src/Methods/Shh/UninstallFilter.php index 38f586a8..4cfe3b4e 100644 --- a/src/Methods/Shh/UninstallFilter.php +++ b/src/Methods/Shh/UninstallFilter.php @@ -49,16 +49,4 @@ class UninstallFilter extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Shh/Version.php b/src/Methods/Shh/Version.php index 33e0682e..34386798 100644 --- a/src/Methods/Shh/Version.php +++ b/src/Methods/Shh/Version.php @@ -43,16 +43,4 @@ class Version extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Web3/ClientVersion.php b/src/Methods/Web3/ClientVersion.php index c119df15..bde0ca05 100644 --- a/src/Methods/Web3/ClientVersion.php +++ b/src/Methods/Web3/ClientVersion.php @@ -43,16 +43,4 @@ class ClientVersion extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Methods/Web3/Sha3.php b/src/Methods/Web3/Sha3.php index 911aa266..3061a2e7 100644 --- a/src/Methods/Web3/Sha3.php +++ b/src/Methods/Web3/Sha3.php @@ -49,16 +49,4 @@ class Sha3 extends EthMethod * @var array */ protected $defaultValues = []; - - /** - * construct - * - * @param string $method - * @param array $arguments - * @return void - */ - // public function __construct($method='', $arguments=[]) - // { - // parent::__construct($method, $arguments); - // } } \ No newline at end of file diff --git a/src/Validators/ArrayNumberValidator.php b/src/Validators/ArrayNumberValidator.php new file mode 100644 index 00000000..f360d43b --- /dev/null +++ b/src/Validators/ArrayNumberValidator.php @@ -0,0 +1,37 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Validators; + +use Web3\Validators\IValidator; + +class ArrayNumberValidator +{ + /** + * validate + * TODO: add min & max validation + * + * @param array[int|float] $value + * @return bool + */ + public static function validate($value) + { + if (!is_array($value)) { + return false; + } + foreach ($value as $val) { + if (!(is_int($val) || is_float($val))) { + return false; + } + } + return true; + } +} \ No newline at end of file diff --git a/src/Validators/TagValidator.php b/src/Validators/TagValidator.php index fd1f966e..e334b536 100644 --- a/src/Validators/TagValidator.php +++ b/src/Validators/TagValidator.php @@ -26,7 +26,7 @@ public static function validate($value) { $value = Utils::toString($value); $tags = [ - 'latest', 'earliest', 'pending' + 'latest', 'earliest', 'pending', 'safe', 'finalized' ]; return in_array($value, $tags); diff --git a/test/unit/ArrayNumberValidatorTest.php b/test/unit/ArrayNumberValidatorTest.php new file mode 100644 index 00000000..c7f6851a --- /dev/null +++ b/test/unit/ArrayNumberValidatorTest.php @@ -0,0 +1,43 @@ +validator = new ArrayNumberValidator; + } + + /** + * testValidate + * + * @return void + */ + public function testValidate() + { + $validator = $this->validator; + + $this->assertEquals(false, $validator->validate(1)); + $this->assertEquals(false, $validator->validate(0.1)); + $this->assertEquals(false, $validator->validate('test')); + $this->assertEquals(false, $validator->validate([1, 0.1, 'test'])); + $this->assertEquals(true, $validator->validate([1, 0.1])); + } +} \ No newline at end of file diff --git a/test/unit/EthApiTest.php b/test/unit/EthApiTest.php index e1d2a4c2..f7645809 100644 --- a/test/unit/EthApiTest.php +++ b/test/unit/EthApiTest.php @@ -353,7 +353,7 @@ public function testSendRawTransaction() $eth->sendRawTransaction('0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675', function ($err, $transaction) { if ($err !== null) { - return $this->assertEquals('invalid remainder', $err->getMessage()); + return $this->assertStringContainsString('Could not ', $err->getMessage()); } $this->assertTrue(is_string($transaction)); }); @@ -420,7 +420,7 @@ public function testGetBlockByHash() if ($err !== null) { return $this->assertEquals('Key not found in database', $err->getMessage()); } - $this->assertTrue($block !== null); + $this->assertTrue($block === null); }); } @@ -489,7 +489,7 @@ public function testGetTransactionByBlockNumberAndIndex() if ($err !== null) { return $this->assertStringStartsWith('LevelUpArrayAdapter named \'blocks\' index out of range', $err->getMessage()); } - $this->assertTrue($transaction !== null); + $this->assertTrue($transaction === null); }); } @@ -523,7 +523,7 @@ public function testGetUncleByBlockHashAndIndex() if ($err !== null) { return $this->fail($err->getMessage()); } - $this->assertTrue($uncle !== null); + $this->assertTrue($uncle === null); }); } @@ -540,7 +540,7 @@ public function testGetUncleByBlockNumberAndIndex() if ($err !== null) { return $this->fail($err->getMessage()); } - $this->assertTrue($uncle !== null); + $this->assertTrue($uncle === null); }); } @@ -632,8 +632,7 @@ public function testGetFilterChanges() $eth->getFilterChanges('0x01', function ($err, $changes) { if ($err !== null) { - // infura banned us to get filter changes - return $this->fail($err->getMessage()); + return $this->assertEquals('filter not found', $err->getMessage()); } $this->assertTrue(is_array($changes)); }); @@ -650,8 +649,7 @@ public function testGetFilterLogs() $eth->getFilterLogs('0x01', function ($err, $logs) { if ($err !== null) { - // infura banned us to get filter logs - return $this->fail($err->getMessage()); + return $this->assertEquals('filter not found', $err->getMessage()); } $this->assertTrue(is_array($logs)); }); @@ -720,6 +718,29 @@ public function testSubmitHashrate() }); } + /** + * testFeeHistory + * + * @return void + */ + public function testFeeHistory() + { + $eth = $this->eth; + + $eth->feeHistory(1, 'latest', [ 1, 40, 50 ], function ($err, $feeHistory) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->assertTrue($feeHistory->oldestBlock !== null); + $this->assertTrue($feeHistory->baseFeePerGas !== null); + $this->assertTrue($feeHistory->gasUsedRatio !== null); + $this->assertEquals(count($feeHistory->gasUsedRatio), 1); + $this->assertTrue($feeHistory->reward !== null); + $this->assertEquals(count($feeHistory->reward), 1); + $this->assertEquals(count($feeHistory->reward[0]), 3); + }); + } + /** * testGetBlockByNumberAsync * diff --git a/test/unit/PersonalApiTest.php b/test/unit/PersonalApiTest.php index a156ecf0..96853a28 100644 --- a/test/unit/PersonalApiTest.php +++ b/test/unit/PersonalApiTest.php @@ -175,7 +175,7 @@ public function testSendTransaction() $this->web3->eth->sendTransaction([ 'from' => $this->coinbase, 'to' => $this->newAccount, - 'value' => '0xfffffffff', + 'value' => '0xfffffffffffff', ], function ($err, $transaction) { if ($err !== null) { return $this->fail($err->getMessage()); @@ -188,6 +188,8 @@ public function testSendTransaction() 'from' => $this->newAccount, 'to' => $this->coinbase, 'value' => '0x01', + 'gasLimit' => 21000, + 'gasPrice' => 5000000000, ], '123456', function ($err, $transaction) { if ($err !== null) { return $this->fail($err->getMessage());