Change params in Web3\Web3
This commit is contained in:
parent
889c846c80
commit
bdfbace76b
26
src/Web3.php
26
src/Web3.php
@ -34,7 +34,9 @@ class Web3
|
|||||||
'web3_clientVersion' => [],
|
'web3_clientVersion' => [],
|
||||||
'web3_sha3' => [
|
'web3_sha3' => [
|
||||||
'params' => [
|
'params' => [
|
||||||
HexValidator::class
|
[
|
||||||
|
'validators' => HexValidator::class
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
@ -82,14 +84,32 @@ class Web3
|
|||||||
}
|
}
|
||||||
$allowedMethod = $this->methods[$method];
|
$allowedMethod = $this->methods[$method];
|
||||||
|
|
||||||
if (isset($allowedMethod['params'])) {
|
if (isset($allowedMethod['params']) && is_array($allowedMethod['params'])) {
|
||||||
// validate 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 (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 . '.');
|
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) {
|
if ($this->provider->isBatch) {
|
||||||
$this->provider->send($method, $arguments, null);
|
$this->provider->send($method, $arguments, null);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user