Personal use EthMethod

This commit is contained in:
sc0Vu 2018-01-11 17:58:20 +08:00
parent ce217225a9
commit ba6d50b25b
4 changed files with 31 additions and 200 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}