eth_getStorageAt

* eth_getStorageAt
* QuantityValidator
This commit is contained in:
sc0Vu 2017-12-13 17:04:07 +08:00
parent 31147172ec
commit 889c846c80
4 changed files with 51 additions and 2 deletions

View File

@ -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
]
],
];
/**

View 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);
}
}

View File

@ -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));
}
}

View File

@ -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
*