diff --git a/src/Methods/Personal/ListAccounts.php b/src/Methods/Personal/ListAccounts.php index 09ae40a..9bc4e15 100644 --- a/src/Methods/Personal/ListAccounts.php +++ b/src/Methods/Personal/ListAccounts.php @@ -12,10 +12,9 @@ namespace Web3\Methods\Personal; use InvalidArgumentException; -use Web3\Methods\IMethod; -use Web3\Methods\JSONRPC; +use Web3\Methods\EthMethod; -class ListAccounts extends JSONRPC implements IMethod +class ListAccounts extends EthMethod { /** * inputFormatters @@ -31,6 +30,13 @@ class ListAccounts extends JSONRPC implements IMethod */ protected $outputFormatters = []; + /** + * defaultValues + * + * @var array + */ + protected $defaultValues = []; + /** * construct * @@ -42,47 +48,4 @@ class ListAccounts extends JSONRPC implements IMethod // { // 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 diff --git a/src/Methods/Personal/NewAccount.php b/src/Methods/Personal/NewAccount.php index 3ac77a6..3043276 100644 --- a/src/Methods/Personal/NewAccount.php +++ b/src/Methods/Personal/NewAccount.php @@ -12,11 +12,10 @@ namespace Web3\Methods\Personal; use InvalidArgumentException; -use Web3\Methods\IMethod; -use Web3\Methods\JSONRPC; +use Web3\Methods\EthMethod; use Web3\Formatters\StringFormatter; -class NewAccount extends JSONRPC implements IMethod +class NewAccount extends EthMethod { /** * inputFormatters @@ -34,6 +33,13 @@ class NewAccount extends JSONRPC implements IMethod */ protected $outputFormatters = []; + /** + * defaultValues + * + * @var array + */ + protected $defaultValues = []; + /** * construct * @@ -45,47 +51,4 @@ class NewAccount extends JSONRPC implements IMethod // { // 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 diff --git a/src/Methods/Personal/SendTransaction.php b/src/Methods/Personal/SendTransaction.php index a5a11b7..f49c5c8 100644 --- a/src/Methods/Personal/SendTransaction.php +++ b/src/Methods/Personal/SendTransaction.php @@ -12,12 +12,11 @@ namespace Web3\Methods\Personal; use InvalidArgumentException; -use Web3\Methods\IMethod; -use Web3\Methods\JSONRPC; +use Web3\Methods\EthMethod; use Web3\Formatters\TransactionFormatter; use Web3\Formatters\StringFormatter; -class SendTransaction extends JSONRPC implements IMethod +class SendTransaction extends EthMethod { /** * inputFormatters @@ -35,6 +34,13 @@ class SendTransaction extends JSONRPC implements IMethod */ protected $outputFormatters = []; + /** + * defaultValues + * + * @var array + */ + protected $defaultValues = []; + /** * construct * @@ -46,47 +52,4 @@ class SendTransaction extends JSONRPC implements IMethod // { // 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 diff --git a/src/Methods/Personal/UnlockAccount.php b/src/Methods/Personal/UnlockAccount.php index 67ab8c7..5a0568c 100644 --- a/src/Methods/Personal/UnlockAccount.php +++ b/src/Methods/Personal/UnlockAccount.php @@ -12,13 +12,12 @@ namespace Web3\Methods\Personal; use InvalidArgumentException; -use Web3\Methods\IMethod; -use Web3\Methods\JSONRPC; +use Web3\Methods\EthMethod; use Web3\Formatters\AddressFormatter; use Web3\Formatters\StringFormatter; use Web3\Formatters\QuantityFormatter; -class UnlockAccount extends JSONRPC implements IMethod +class UnlockAccount extends EthMethod { /** * inputFormatters @@ -41,10 +40,8 @@ class UnlockAccount extends JSONRPC implements IMethod * * @var array */ - private $defaultValues = [ - 'personal_unlockAccount' => [ - 2 => 300 - ] + protected $defaultValues = [ + 2 => 300 ]; /** @@ -58,59 +55,4 @@ class UnlockAccount extends JSONRPC implements IMethod // { // 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.'); - } - if (count($params) < count($rules)) { - if (!isset($this->defaultValues[$this->method])) { - throw new \InvalidArgumentException('The params are less than inputFormatters.'); - } - $defaultValues = $this->defaultValues[$this->method]; - - foreach ($defaultValues as $key => $value) { - if (!isset($params[$key])) { - $params[$key] = $value; - } - } - } - 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