Skip to content

Commit a8c543f

Browse files
authored
Merge pull request #332 from web3p/feature/add-feehistory
feature: add fee history api
2 parents 31101fe + 40e166e commit a8c543f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+237
-743
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
run: |
2626
sudo apt-get update -y
2727
sudo apt-get install -y nodejs
28-
sudo npm install -g ganache-cli
28+
sudo npm install -g ganache
2929
3030
- uses: actions/checkout@v2
3131

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ composer.phar
77
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
88
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
99
composer.lock
10+
11+
*.DS_Store
12+
*.phpunit.result.cache
13+
14+
# nodejs
15+
node_modules/
16+
package-lock.json
17+
package.json

scripts/test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bash
22

3-
ganache-cli -g 0 -l 6000000 > /dev/null &
4-
ganachecli_pid=$!
5-
echo "Start ganache-cli pid: $ganachecli_pid and sleep 3 seconds"
3+
ganache -g 0 -l 6000000 --wallet.seed test,test,test,test,test,test,test,test,test,test,test,test --miner.coinbase 0x4DABDacE120050c79E355A5Ba99047B955f37fFc > /dev/null &
4+
ganache_pid=$!
5+
echo "Start ganache pid: $ganache_pid and sleep 3 seconds"
66

77
sleep 3
88

99
vendor/bin/phpunit --coverage-clover=coverage.xml
1010
ret=$?
1111

12-
kill -9 $ganachecli_pid
12+
kill -9 $ganache_pid
1313
echo "Kill ganache-cli"
1414

1515
exit $ret

src/Eth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Eth
3838
* @var array
3939
*/
4040
private $allowedMethods = [
41-
'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'
41+
'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'
4242
];
4343

4444
/**
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* This file is part of web3.php package.
5+
*
6+
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
7+
*
8+
* @author Peter Lai <alk03073135@gmail.com>
9+
* @license MIT
10+
*/
11+
12+
namespace Web3\Formatters;
13+
14+
use InvalidArgumentException;
15+
use Web3\Utils;
16+
use Web3\Formatters\IFormatter;
17+
use Web3\Formatters\BigNumberFormatter;
18+
19+
class FeeHistoryFormatter implements IFormatter
20+
{
21+
/**
22+
* format
23+
*
24+
* @param mixed $value
25+
* @return string
26+
*/
27+
public static function format($value)
28+
{
29+
if (isset($value->oldestBlock)) {
30+
$value->oldestBlock = BigNumberFormatter::format($value->oldestBlock);
31+
}
32+
if (isset($value->baseFeePerGas)) {
33+
foreach ($value->baseFeePerGas as $key => $baseFeePerGas) {
34+
$value->baseFeePerGas[$key] = BigNumberFormatter::format($baseFeePerGas);
35+
}
36+
}
37+
if (isset($value->reward)) {
38+
foreach ($value->reward as $keyOut => $rewards) {
39+
foreach ($rewards as $keyIn => $reward) {
40+
$value->reward[$keyOut][$keyIn] = BigNumberFormatter::format($reward);
41+
}
42+
}
43+
}
44+
return $value;
45+
}
46+
}

src/Formatters/NumberFormatter.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ class NumberFormatter implements IFormatter
2020
/**
2121
* format
2222
*
23-
* @param mixed $value
24-
* @return int
23+
* @param int|float $value
24+
* @return int|float
2525
*/
2626
public static function format($value)
2727
{
28-
$value = Utils::toString($value);
29-
$bn = Utils::toBn($value);
30-
$int = (int) $bn->toString();
31-
32-
return $int;
28+
return $value;
3329
}
3430
}

src/Methods/Eth/Accounts.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,4 @@ class Accounts extends EthMethod
4343
* @var array
4444
*/
4545
protected $defaultValues = [];
46-
47-
/**
48-
* construct
49-
*
50-
* @param string $method
51-
* @param array $arguments
52-
* @return void
53-
*/
54-
// public function __construct($method='', $arguments=[])
55-
// {
56-
// parent::__construct($method, $arguments);
57-
// }
5846
}

src/Methods/Eth/BlockNumber.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,4 @@ class BlockNumber extends EthMethod
4646
* @var array
4747
*/
4848
protected $defaultValues = [];
49-
50-
/**
51-
* construct
52-
*
53-
* @param string $method
54-
* @param array $arguments
55-
* @return void
56-
*/
57-
// public function __construct($method='', $arguments=[])
58-
// {
59-
// parent::__construct($method, $arguments);
60-
// }
6149
}

src/Methods/Eth/Call.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,4 @@ class Call extends EthMethod
5656
protected $defaultValues = [
5757
1 => 'latest'
5858
];
59-
60-
/**
61-
* construct
62-
*
63-
* @param string $method
64-
* @param array $arguments
65-
* @return void
66-
*/
67-
// public function __construct($method='', $arguments=[])
68-
// {
69-
// parent::__construct($method, $arguments);
70-
// }
7159
}

src/Methods/Eth/Coinbase.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,4 @@ class Coinbase extends EthMethod
4343
* @var array
4444
*/
4545
protected $defaultValues = [];
46-
47-
/**
48-
* construct
49-
*
50-
* @param string $method
51-
* @param array $arguments
52-
* @return void
53-
*/
54-
// public function __construct($method='', $arguments=[])
55-
// {
56-
// parent::__construct($method, $arguments);
57-
// }
5846
}

0 commit comments

Comments
 (0)