eth_getStorageAt
* eth_getStorageAt * QuantityValidator
This commit is contained in:
parent
31147172ec
commit
889c846c80
@ -8,6 +8,7 @@ use Web3\RequestManagers\RequestManager;
|
||||
use Web3\RequestManagers\HttpRequestManager;
|
||||
use Web3\Validators\AddressValidator;
|
||||
use Web3\Validators\TagValidator;
|
||||
use Web3\Validators\QuantityValidator;
|
||||
|
||||
class Eth
|
||||
{
|
||||
@ -38,6 +39,13 @@ class Eth
|
||||
TagValidator::class
|
||||
]
|
||||
],
|
||||
'eth_getStorageAt' => [
|
||||
'params'=> [
|
||||
AddressValidator::class,
|
||||
QuantityValidator::class,
|
||||
TagValidator::class
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
20
src/Validators/QuantityValidator.php
Normal file
20
src/Validators/QuantityValidator.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Web3\Validators;
|
||||
|
||||
use Web3\Validators\IValidator;
|
||||
|
||||
class QuantityValidator
|
||||
{
|
||||
/**
|
||||
* validate
|
||||
*
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
public static function validate($value)
|
||||
{
|
||||
// maybe change in_int and preg_match future
|
||||
return (is_int($value) || preg_match('/^0x[a-fA-f0-9]+/', $value) >= 1);
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ class TagValidator
|
||||
'latest', 'earliest', 'pending'
|
||||
];
|
||||
|
||||
// maybe change in_int future
|
||||
return (is_int($value) || in_array($value, $tags));
|
||||
// maybe change in_int and preg_match future
|
||||
return (is_int($value) || preg_match('/^0x[a-fA-f0-9]+/', $value) >= 1 || in_array($value, $tags));
|
||||
}
|
||||
}
|
@ -220,6 +220,27 @@ class EthTest extends TestCase
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testGetStorageAt
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetStorageAt()
|
||||
{
|
||||
$eth = $this->web3->eth;
|
||||
|
||||
$eth->getStorageAt('0x407d73d8a49eeb85d32cf465507dd71d507100c1', '0x0', 'latest', function ($err, $storage) {
|
||||
if ($err !== null) {
|
||||
return $this->fail($err->getMessage());
|
||||
}
|
||||
if (isset($storage->result)) {
|
||||
$this->assertTrue(is_string($storage->result));
|
||||
} else {
|
||||
$this->fail($storage->error->message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* testUnallowedMethod
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user