Change params in Web3\Web3

This commit is contained in:
sc0Vu 2017-12-13 17:31:11 +08:00
parent 889c846c80
commit bdfbace76b

View File

@ -34,7 +34,9 @@ class Web3
'web3_clientVersion' => [],
'web3_sha3' => [
'params' => [
HexValidator::class
[
'validators' => HexValidator::class
]
]
]
];
@ -82,14 +84,32 @@ class Web3
}
$allowedMethod = $this->methods[$method];
if (isset($allowedMethod['params'])) {
if (isset($allowedMethod['params']) && is_array($allowedMethod['params'])) {
// validate params
foreach ($allowedMethod['params'] as $key => $rule) {
foreach ($allowedMethod['params'] as $key => $param) {
if (isset($param['validators'])) {
if (is_array($param['validators'])) {
foreach ($param['validators'] as $rule) {
if (call_user_func([$rule, 'validate'], $arguments[$key]) === false) {
if (isset($param['default']) && !isset($arguments[$key])) {
$arguments[$key] = $param['default'];
} else {
throw new \RuntimeException('Wrong type of ' . $name . ' method argument ' . $key . '.');
}
}
}
} else {
if (call_user_func([$param['validators'], 'validate'], $arguments[$key]) === false) {
if (!isset($param['default']) && !isset($arguments[$key])) {
$arguments[$key] = $param['default'];
} else {
throw new \RuntimeException('Wrong type of ' . $name . ' method argument ' . $key . '.');
}
}
}
}
}
}
if ($this->provider->isBatch) {
$this->provider->send($method, $arguments, null);
} else {