Skip to content

Commit

Permalink
chore: cleanup exception behavior and add javadocs (#15364)
Browse files Browse the repository at this point in the history
Signed-off-by: lukelee-sl <[email protected]>
  • Loading branch information
lukelee-sl authored Sep 6, 2024
1 parent 81d1491 commit 011f509
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

/**
* Implements the {@code evmAddressAlias()} call of the Has system contract.
* This call will return the EVM address alias of the given long zero Hedera account number if it exists.
*/
public class EvmAddressAliasCall extends AbstractCall {
private final Address address;
Expand All @@ -61,7 +62,7 @@ public EvmAddressAliasCall(@NonNull final HasCallAttempt attempt, final Address
final var accountNum = numberOfLongZero(explicitAddress);
final var account = enhancement.nativeOperations().getAccount(accountNum);
// If the account is null or does not have an account id then return bail
if (account == null || !account.hasAccountId()) {
if (account == null) {
return gasOnly(fullResultsFor(INVALID_ACCOUNT_ID, ZERO_ADDRESS), INVALID_ACCOUNT_ID, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Implements the {@code hederaAccountNumAlias(address)} call of the HAS system contract.
* This call will return the long zero Hedera account number of the given alias if it exists.
*/
public class HederaAccountNumAliasCall extends AbstractCall {
private final Address address;

Expand All @@ -55,9 +59,11 @@ public HederaAccountNumAliasCall(@NonNull final HasCallAttempt attempt, @NonNull
return gasOnly(fullResultsFor(INVALID_SOLIDITY_ADDRESS, ZERO_ADDRESS), INVALID_SOLIDITY_ADDRESS, true);
}
final var account = enhancement.nativeOperations().getAccount(accountNum);
if (account == null
|| !account.hasAccountId()
|| !account.accountIdOrElse(AccountID.DEFAULT).hasAccountNum()) {
if (account == null) {
return gasOnly(fullResultsFor(INVALID_SOLIDITY_ADDRESS, ZERO_ADDRESS), INVALID_SOLIDITY_ADDRESS, true);
}
requireNonNull(account.accountId());
if (!account.accountIdOrElse(AccountID.DEFAULT).hasAccountNum()) {
return gasOnly(fullResultsFor(INVALID_SOLIDITY_ADDRESS, ZERO_ADDRESS), INVALID_SOLIDITY_ADDRESS, true);
}
final var accountAsAddress = asHeadlongAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.has.HasCallAttempt;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* Implements the {@code isValidAlias(address)} call of the HAS system contract.
* This call will return true if the address exists and false otherwise.
*/
public class IsValidAliasCall extends AbstractCall {

private final Address address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ void successfulCall() {
given(attempt.enhancement()).willReturn(mockEnhancement());
given(nativeOperations.getAccount(numberOfLongZero(NON_SYSTEM_BUT_IS_LONG_ZERO_ADDRESS)))
.willReturn(account);
given(account.hasAccountId()).willReturn(true);
given(account.alias()).willReturn(RECEIVER_ADDRESS);
subject = new EvmAddressAliasCall(attempt, asHeadlongAddress(NON_SYSTEM_BUT_IS_LONG_ZERO_ADDRESS.toArray()));

Expand Down

0 comments on commit 011f509

Please sign in to comment.