Skip to content

Commit

Permalink
Update return value and type
Browse files Browse the repository at this point in the history
  • Loading branch information
ranabd36 committed Jan 28, 2020
1 parent cfbdb5f commit 27655a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/Methods/EthClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public function hashRate(): int
return hexdec($response->getRpcResult());
}

public function gasPrice(): Wei
public function gasPrice(): ?Wei
{
$response = $this->client->send(
$this->client->request(73, 'eth_gasPrice', [])
);
return new Wei(hexdec($response->getRpcResult()));
return ($response->getRpcResult()) ? new Wei(hexdec($response->getRpcResult())) : null;
}

/**
Expand All @@ -90,12 +90,12 @@ public function blockNumber(): int
return hexdec($response->getRpcResult());
}

public function getBalance(Address $address, BlockNumber $blockNumber): Wei
public function getBalance(Address $address, BlockNumber $blockNumber): ?Wei
{
$response = $this->client->send(
$this->client->request(1, 'eth_getBalance', [$address->toString(), $blockNumber->toString()])
);
return new Wei(\Phlib\base_convert($response->getRpcResult(), 16, 10));
return ($response->getRpcResult()) ? new Wei(\Phlib\base_convert($response->getRpcResult(), 16, 10)) : null;
}

public function getStorageAt(Address $address, int $quantity, BlockNumber $blockNumber): string
Expand Down Expand Up @@ -164,20 +164,20 @@ public function sign(Address $address, string $msgToSign)
return $response->getRpcResult();
}

public function sendTransaction(Transaction $transaction): TransactionHash
public function sendTransaction(Transaction $transaction): ?TransactionHash
{
$response = $this->client->send(
$this->client->request(1, 'eth_sendTransaction', [$transaction->toArray()])
);
return new TransactionHash($response->getRpcResult());
return ($response->getRpcResult()) ? new TransactionHash($response->getRpcResult()) : null;
}

public function sendRawTransaction(string $data): TransactionHash
public function sendRawTransaction(string $data): ?TransactionHash
{
$response = $this->client->send(
$this->client->request(1, 'eth_sendRawTransaction', [$data])
);
return new TransactionHash($response->getRpcResult());
return ($response->getRpcResult()) ? new TransactionHash($response->getRpcResult()) : null;
}

public function call(Transaction $transaction, BlockNumber $blockNumber): string
Expand Down
12 changes: 6 additions & 6 deletions src/Methods/PersonalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public function listAccounts(): array
return $addresses;
}

public function newAccount(string $password): Address
public function newAccount(string $password): ?Address
{
$response = $this->client->send(
$this->client->request(67, 'personal_newAccount', [$password])
);

return new Address($response->getRpcResult());
return ($response->getRpcResult()) ? new Address($response->getRpcResult()) : null;
}

public function unlockAccount(Address $address, string $password, int $duration): bool
Expand All @@ -46,12 +46,12 @@ public function unlockAccount(Address $address, string $password, int $duration)
return empty($result) ? false : true;
}

public function sendTransaction(Transaction $transaction, string $password): TransactionHash
public function sendTransaction(Transaction $transaction, string $password): ?TransactionHash
{
$response = $this->client->send(
$this->client->request(1, 'personal_sendTransaction', [$transaction->toArray(), $password])
);
return new TransactionHash($response->getRpcResult());
return ($response->getRpcResult()) ? new TransactionHash($response->getRpcResult()) : null;
}

public function sign(string $message, Address $address, string $password): string
Expand All @@ -62,11 +62,11 @@ public function sign(string $message, Address $address, string $password): strin
return $response->getRpcResult();
}

public function ecRecover(string $message, string $signature): TransactionHash
public function ecRecover(string $message, string $signature): ?TransactionHash
{
$response = $this->client->send(
$this->client->request(1, 'personal_ecRecover', [$message, $signature])
);
return new Address($response->getRpcResult());
return ($response->getRpcResult()) ? new Address($response->getRpcResult()) : null;
}
}

0 comments on commit 27655a6

Please sign in to comment.