From 26b6844f443d3643ee5124155ca2381a25904a29 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Thu, 11 Jan 2018 16:46:08 +0800 Subject: [PATCH] Eth protocol version. --- src/Methods/Eth/ProtocolVersion.php | 91 +++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/Methods/Eth/ProtocolVersion.php diff --git a/src/Methods/Eth/ProtocolVersion.php b/src/Methods/Eth/ProtocolVersion.php new file mode 100644 index 0000000..4d937f0 --- /dev/null +++ b/src/Methods/Eth/ProtocolVersion.php @@ -0,0 +1,91 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Methods\Eth; + +use InvalidArgumentException; +use Web3\Methods\IMethod; +use Web3\Methods\JSONRPC; +use Web3\Formatters\BigNumberFormatter; + +class ProtocolVersion extends JSONRPC implements IMethod +{ + /** + * inputFormatters + * + * @var array + */ + protected $inputFormatters = []; + + /** + * outputFormatters + * + * @var array + */ + protected $outputFormatters = [ + BigNumberFormatter::class + ]; + + /** + * construct + * + * @param string $method + * @param array $arguments + * @return void + */ + // public function __construct($method='', $arguments=[]) + // { + // parent::__construct($method, $arguments); + // } + + /** + * getInputFormatters + * + * @return array + */ + public function getInputFormatters() + { + return $this->inputFormatters; + } + + /** + * getOutputFormatters + * + * @return array + */ + public function getOutputFormatters() + { + return $this->outputFormatters; + } + + /** + * transform + * + * @param array $params + * @param array $rules + * @return array + */ + public function transform($params, $rules) + { + if (!is_array($params)) { + throw new InvalidArgumentException('Please use array params when call transform.'); + } + if (!is_array($rules)) { + throw new InvalidArgumentException('Please use array rules when call transform.'); + } + foreach ($params as $key => $param) { + if (isset($rules[$key])) { + $params[$key] = call_user_func([$rules[$key], 'format'], $param); + } + } + return $params; + } +} \ No newline at end of file