From 31147172ec059c09e9a7b53a1f14eaf47e9db669 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Wed, 13 Dec 2017 16:49:26 +0800 Subject: [PATCH] eth_getBalance * eth_getBalance * AddressValidator * TagValidator --- src/Eth.php | 8 ++++++++ src/Validators/AddressValidator.php | 22 ++++++++++++++++++++++ src/Validators/TagValidator.php | 24 ++++++++++++++++++++++++ test/unit/EthTest.php | 21 +++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 src/Validators/AddressValidator.php create mode 100644 src/Validators/TagValidator.php diff --git a/src/Eth.php b/src/Eth.php index 44e237b..898156e 100644 --- a/src/Eth.php +++ b/src/Eth.php @@ -6,6 +6,8 @@ use Web3\Providers\Provider; use Web3\Providers\HttpProvider; use Web3\RequestManagers\RequestManager; use Web3\RequestManagers\HttpRequestManager; +use Web3\Validators\AddressValidator; +use Web3\Validators\TagValidator; class Eth { @@ -30,6 +32,12 @@ class Eth 'eth_gasPrice' => [], 'eth_accounts' => [], 'eth_blockNumber' => [], + 'eth_getBalance' => [ + 'params'=> [ + AddressValidator::class, + TagValidator::class + ] + ], ]; /** diff --git a/src/Validators/AddressValidator.php b/src/Validators/AddressValidator.php new file mode 100644 index 0000000..22ec3e5 --- /dev/null +++ b/src/Validators/AddressValidator.php @@ -0,0 +1,22 @@ += 1); + } +} \ No newline at end of file diff --git a/src/Validators/TagValidator.php b/src/Validators/TagValidator.php new file mode 100644 index 0000000..62850d5 --- /dev/null +++ b/src/Validators/TagValidator.php @@ -0,0 +1,24 @@ +web3->eth; + + $eth->getBalance('0x407d73d8a49eeb85d32cf465507dd71d507100c1', 'latest', function ($err, $balance) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + if (isset($balance->result)) { + $this->assertTrue(is_string($balance->result)); + } else { + $this->fail($balance->error->message); + } + }); + } + /** * testUnallowedMethod *