diff --git a/examples/personal.php b/examples/personal.php index e8325895..74de4e71 100644 --- a/examples/personal.php +++ b/examples/personal.php @@ -38,3 +38,16 @@ } echo 'Balance: ' . $balance->toString() . PHP_EOL; }); + +// remember to lock account after transaction +$personal->lockAccount($newAccount, function ($err, $locked) { + if ($err !== null) { + echo 'Error: ' . $err->getMessage(); + return; + } + if ($locked) { + echo 'New account is locked!' . PHP_EOL; + } else { + echo 'New account isn\'t locked' . PHP_EOL; + } +}); diff --git a/src/Methods/Personal/LockAccount.php b/src/Methods/Personal/LockAccount.php index 0d8a44e6..7baf6399 100644 --- a/src/Methods/Personal/LockAccount.php +++ b/src/Methods/Personal/LockAccount.php @@ -11,14 +11,9 @@ namespace Web3\Methods\Personal; -use InvalidArgumentException; use Web3\Methods\EthMethod; use Web3\Validators\AddressValidator; -use Web3\Validators\StringValidator; -use Web3\Validators\QuantityValidator; use Web3\Formatters\AddressFormatter; -use Web3\Formatters\StringFormatter; -use Web3\Formatters\NumberFormatter; class LockAccount extends EthMethod { diff --git a/test/unit/PersonalApiTest.php b/test/unit/PersonalApiTest.php index b665cf27..127c8d54 100644 --- a/test/unit/PersonalApiTest.php +++ b/test/unit/PersonalApiTest.php @@ -121,6 +121,39 @@ public function testUnlockAccountWithDuration() }); } + /** + * testLockAccount + * + * @return void + */ + public function testLockAccount() + { + $personal = $this->personal; + + // create account + $personal->newAccount('123456', function ($err, $account) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->newAccount = $account; + $this->assertTrue(is_string($account)); + }); + + $personal->unlockAccount($this->newAccount, '123456', function ($err, $unlocked) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->assertTrue($unlocked); + }); + + $personal->lockAccount($this->newAccount, function ($err, $locked) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->assertTrue($locked); + }); + } + /** * testSendTransaction *