CallValidator.

This commit is contained in:
sc0Vu 2018-01-03 14:51:30 +08:00
parent af974a6bb4
commit 0f59ac9223
3 changed files with 58 additions and 2 deletions

View File

@ -25,6 +25,7 @@ use Web3\Validators\BooleanValidator;
use Web3\Validators\StringValidator;
use Web3\Validators\FilterValidator;
use Web3\Validators\NonceValidator;
use Web3\Validators\CallValidator;
class Eth
{
@ -159,7 +160,7 @@ class Eth
'eth_call' => [
'params' => [
[
'validators' => TransactionValidator::class
'validators' => CallValidator::class
], [
'default' => 'latest',
'validators' => [

View File

@ -0,0 +1,55 @@
<?php
/**
* This file is part of web3.php package.
*
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
*
* @author Peter Lai <alk03073135@gmail.com>
* @license MIT
*/
namespace Web3\Validators;
use Web3\Validators\IValidator;
use Web3\Validators\QuantityValidator;
use Web3\Validators\TagValidator;
use Web3\Validators\HexValidator;
class CallValidator
{
/**
* validate
*
* @param array $value
* @return bool
*/
public static function validate($value)
{
if (!is_array($value)) {
return false;
}
if (isset($value['from']) && AddressValidator::validate($value['from']) === false && $value['from'] !== '') {
return false;
}
if (isset($value['to']) && AddressValidator::validate($value['to']) === false && $value['to'] !== '') {
return false;
}
if (isset($value['gas']) && QuantityValidator::validate($value['gas']) === false) {
return false;
}
if (isset($value['gasPrice']) && QuantityValidator::validate($value['gasPrice']) === false) {
return false;
}
if (isset($value['value']) && QuantityValidator::validate($value['value']) === false) {
return false;
}
if (isset($value['data']) && HexValidator::validate($value['data']) === false) {
return false;
}
if (isset($value['nonce']) && QuantityValidator::validate($value['nonce']) === false) {
return false;
}
return true;
}
}

View File

@ -472,7 +472,7 @@ class EthApiTest extends TestCase
$eth = $this->eth;
$eth->call([
'from' => "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
// 'from' => "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
'to' => "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
'gas' => "0x76c0",
'gasPrice' => "0x9184e72a000",