ShhFilterValidator.

This commit is contained in:
sc0Vu 2018-01-29 16:23:56 +08:00
parent f83a9c6c90
commit 85a5a20570

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\HexValidator;
use Web3\Validators\IdentityValidator;
class ShhFilterValidator
{
/**
* validate
*
* @param array $value
* @return bool
*/
public static function validate($value)
{
if (!is_array($value)) {
return false;
}
if (isset($value['to']) && IdentityValidator::validate($value['to']) === false) {
return false;
}
if (!isset($value['topics']) || !is_array($value['topics'])) {
return false;
}
foreach ($value['topics'] as $topic) {
if (is_array($topic)) {
foreach ($topic as $subTopic) {
if (HexValidator::validate($subTopic) === false) {
return false;
}
}
continue;
}
if (HexValidator::validate($topic) === false) {
if (!is_null($topic)) {
return false;
}
}
}
return true;
}
}