Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Lai committed Feb 5, 2024
1 parent ad3b573 commit 2446166
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,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(stake.hasPendingChange() ? Optional.of(to(stake.getPendingChange())) : Optional.empty())
.pendingChange(to(stake.getPendingChange()))
.restakeEarnings(stake.getRestakeEarnings())
.stakedAmount(to(stake.getStakedAmount()))
.target(to(stake.getTarget()))
Expand All @@ -342,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(stake.hasPendingChange() ? Optional.of(to(stake.getPendingChange())) : Optional.empty())
.pendingChange(to(stake.getPendingChange()))
.restakeEarnings(stake.getRestakeEarnings())
.stakedAmount(to(stake.getStakedAmount()))
.bakerPoolInfo(to(stake.getPoolInfo()))
Expand All @@ -354,21 +354,21 @@ static com.concordium.sdk.responses.BakerId to(BakerId bakerId) {
return com.concordium.sdk.responses.BakerId.from(bakerId.getValue());
}

static PendingChange to(StakePendingChange pendingChange) {
static Optional<PendingChange> to(StakePendingChange pendingChange) {
switch (pendingChange.getChangeCase()) {
case REDUCE:
StakePendingChange.Reduce reduce = pendingChange.getReduce();
return ReduceStakeChange.builder()
return Optional.of(ReduceStakeChange.builder()
.effectiveTime(Timestamp.from(reduce.getEffectiveTime()))
.newStake(to(reduce.getNewStake()))
.build();
.build());
case REMOVE:
return RemoveStakeChange.builder()
return Optional.of(RemoveStakeChange.builder()
.effectiveTime(Timestamp.from(pendingChange.getRemove()))
.build();
.build());
default:
case CHANGE_NOT_SET:
throw new IllegalArgumentException("Expected PendingChange to be set.");
return Optional.empty();
}
}

Expand Down Expand Up @@ -873,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();
}

static AccountTransactionSignature to(TransactionSignature signature) {
Expand Down Expand Up @@ -1181,9 +1181,7 @@ static com.concordium.sdk.responses.DelegatorInfo to(DelegatorInfo delegatorInfo
return com.concordium.sdk.responses.DelegatorInfo.builder()
.account(to(delegatorInfo.getAccount()))
.stake(to(delegatorInfo.getStake()))
.pendingChange(delegatorInfo.hasPendingChange()
? Optional.of(to(delegatorInfo.getPendingChange()))
: Optional.empty())
.pendingChange(to(delegatorInfo.getPendingChange()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ public void mapAccountStakeDelegationTest() {

@Test
public void mapPendingRemoveStakeChangeTest() {
var expected = RemoveStakeChange.builder()
var expected = Optional.of(RemoveStakeChange.builder()
.effectiveTime(com.concordium.sdk.types.Timestamp.newMillis(BAKER_REDUCE_STAKE_TIME))
.build();
.build());

var res = ClientV2MapperExtensions.to(StakePendingChange.newBuilder()
.setRemove(Timestamp.newBuilder().setValue(BAKER_REDUCE_STAKE_TIME).build())
Expand Down

0 comments on commit 2446166

Please sign in to comment.