Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where AccountInfo could fail if there were no pendingchange for a delegator or validator. #307

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

# Unreleased changes
- Fix a bug that caused `getAccountInfo` to fail for delegator and baker accounts if they had no stake pending changes.
This change is also propagated to the type level such that `Baker` and `AccountDelegation` retains an `Optional<PendingChange>`
as opposed to just `PendingChange`.

## 6.1.0
- Purge remaining usages of V1 GRPC API.
- Added support for android through an AAR artifact.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.concordium.sdk.crypto.elgamal.ElgamalPublicKey;
import com.concordium.sdk.crypto.pedersencommitment.PedersenCommitmentKey;
import com.concordium.sdk.crypto.pointchevalsanders.PSPublicKey;
import com.concordium.sdk.crypto.wallet.credential.CredentialDeploymentDetails;
import com.concordium.sdk.requests.AccountQuery;
import com.concordium.sdk.requests.BlockQuery;
import com.concordium.sdk.requests.EpochQuery;
Expand Down Expand Up @@ -325,7 +324,7 @@ static com.concordium.sdk.types.AccountAddress to(AccountAddress address) {
@Nullable
static AccountDelegation to(com.concordium.grpc.v2.AccountStakingInfo.Delegator stake) {
return AccountDelegation.builder()
.pendingChange(to(stake.getPendingChange()))
.pendingChange(stake.hasPendingChange() ? Optional.of(to(stake.getPendingChange())) : Optional.empty())
.restakeEarnings(stake.getRestakeEarnings())
.stakedAmount(to(stake.getStakedAmount()))
.target(to(stake.getTarget()))
Expand All @@ -343,7 +342,7 @@ static DelegationTarget to(com.concordium.grpc.v2.DelegationTarget target) {

static Baker to(com.concordium.grpc.v2.AccountStakingInfo.Baker stake) {
return Baker.builder()
.pendingChange(to(stake.getPendingChange()))
.pendingChange(stake.hasPendingChange() ? Optional.of(to(stake.getPendingChange())) : Optional.empty())
.restakeEarnings(stake.getRestakeEarnings())
.stakedAmount(to(stake.getStakedAmount()))
.bakerPoolInfo(to(stake.getPoolInfo()))
Expand All @@ -369,7 +368,7 @@ static PendingChange to(StakePendingChange pendingChange) {
.build();
default:
case CHANGE_NOT_SET:
MilkywayPirate marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalArgumentException();
throw new IllegalArgumentException("Expected PendingChange to be set.");
}
}

Expand Down Expand Up @@ -874,13 +873,13 @@ static SendBlockItemRequest to(CredentialDeploymentTransaction credentialDeploym
TransactionTime time = to(credentialDeploymentTransaction.getExpiry().getValue());

return SendBlockItemRequest.newBuilder()
.setCredentialDeployment(
CredentialDeployment.newBuilder()
.setMessageExpiry(time)
.setRawPayload(ByteString.copyFrom(credentialDeploymentTransaction.getPayloadBytes()))
.build()
.setCredentialDeployment(
CredentialDeployment.newBuilder()
.setMessageExpiry(time)
.setRawPayload(ByteString.copyFrom(credentialDeploymentTransaction.getPayloadBytes()))
.build()
)
.build();
.build();
MilkywayPirate marked this conversation as resolved.
Show resolved Hide resolved
}

static AccountTransactionSignature to(TransactionSignature signature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import java.util.Optional;

/**
* If the account is delegating.
*/
Expand All @@ -32,6 +34,7 @@ public final class AccountDelegation {

/**
* The pending changes for the delegator.
* Only present if there is a {@link PendingChange} for the delegator.
*/
private final PendingChange pendingChange;
private final Optional<PendingChange> pendingChange;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

import java.util.Optional;

@ToString
@EqualsAndHashCode
@Jacksonized
Expand All @@ -43,9 +45,10 @@ public final class Baker {

/**
* The pending changes for the baker.
* Only present if there is a pending change for the baker.
*/
@Getter
private final PendingChange pendingChange;
private final Optional<PendingChange> pendingChange;

/**
* The baker pool info
Expand Down
Loading
Loading