Skip to content

Commit

Permalink
Merge branch 'master' into feature/ws-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0Vu authored Dec 28, 2023
2 parents eba1833 + a8c543f commit 7142666
Show file tree
Hide file tree
Showing 72 changed files with 236 additions and 744 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ composer.phar
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock

.DS_Store
*.DS_Store
*.phpunit.result.cache

# nodejs
node_modules/
package-lock.json
package.json
8 changes: 4 additions & 4 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/Eth.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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'
];

/**
Expand Down
46 changes: 46 additions & 0 deletions src/Formatters/FeeHistoryFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* This file is part of web3.php package.
*
* (c) Kuan-Cheng,Lai <[email protected]>
*
* @author Peter Lai <[email protected]>
* @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;
}
}
10 changes: 3 additions & 7 deletions src/Formatters/NumberFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/BlockNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/Coinbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/EstimateGas.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
60 changes: 60 additions & 0 deletions src/Methods/Eth/FeeHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* This file is part of web3.php package.
*
* (c) Kuan-Cheng,Lai <[email protected]>
*
* @author Peter Lai <[email protected]>
* @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 = [];
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/GasPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/GetBalance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/GetBlockByHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/GetBlockByNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/GetBlockTransactionCountByHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/GetBlockTransactionCountByNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
12 changes: 0 additions & 12 deletions src/Methods/Eth/GetCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}
Loading

0 comments on commit 7142666

Please sign in to comment.