eth_getBalance
* eth_getBalance * AddressValidator * TagValidator
This commit is contained in:
parent
f3833e45b6
commit
31147172ec
@ -6,6 +6,8 @@ use Web3\Providers\Provider;
|
||||
use Web3\Providers\HttpProvider;
|
||||
use Web3\RequestManagers\RequestManager;
|
||||
use Web3\RequestManagers\HttpRequestManager;
|
||||
use Web3\Validators\AddressValidator;
|
||||
use Web3\Validators\TagValidator;
|
||||
|
||||
class Eth
|
||||
{
|
||||
@ -30,6 +32,12 @@ class Eth
|
||||
'eth_gasPrice' => [],
|
||||
'eth_accounts' => [],
|
||||
'eth_blockNumber' => [],
|
||||
'eth_getBalance' => [
|
||||
'params'=> [
|
||||
AddressValidator::class,
|
||||
TagValidator::class
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
22
src/Validators/AddressValidator.php
Normal file
22
src/Validators/AddressValidator.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
|
||||
class AddressValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
*
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function validate($value)
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
return (preg_match('/^0x[a-fA-F0-9]{40}$/', $value) >= 1);
|
||||
}
|
||||
}
|
24
src/Validators/TagValidator.php
Normal file
24
src/Validators/TagValidator.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
|
||||
class TagValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
*
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function validate($value)
|
||||
{
|
||||
$tags = [
|
||||
'latest', 'earliest', 'pending'
|
||||
];
|
||||
|
||||
// maybe change in_int future
|
||||
return (is_int($value) || in_array($value, $tags));
|
||||
}
|
||||
}
|
@ -199,6 +199,27 @@ class EthTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testGetBalance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetBalance()
|
||||
{
|
||||
$eth = $this->web3->eth;
|
||||
|
||||
$eth->getBalance('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest', function ($err, $balance) {
|
||||
if ($err !== null) {
|
||||
return $this->fail($err->getMessage());
|
||||
}
|
||||
if (isset($balance->result)) {
|
||||
$this->assertTrue(is_string($balance->result));
|
||||
} else {
|
||||
$this->fail($balance->error->message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testUnallowedMethod
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user