-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format the response from eth_feeHistory
- Loading branch information
Showing
4 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Test\Unit; | ||
|
||
use Test\TestCase; | ||
use Web3\Validators\ArrayNumberValidator; | ||
|
||
class ArrayNumberValidatorTest extends TestCase | ||
{ | ||
/** | ||
* validator | ||
* | ||
* @var \Web3\Validators\ArrayNumberValidator | ||
*/ | ||
protected $validator; | ||
|
||
/** | ||
* setUp | ||
* | ||
* @return void | ||
*/ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->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])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters