Skip to content

Commit

Permalink
JAV-319 Support for Protocol 7 (#341)
Browse files Browse the repository at this point in the history
* Update concordium-base to 7.0

* Add ProtocolVersion.V7 enum entry

* Add cooldowns to AccountInfo

* Add availableBalance to AccountInfo

* Make some BakerPoolStatus fields optional

* Update the changelog

* Update version to 8.0.0-SNAPSHOT

Breaking changes in BakerPoolStatus

* Add BakerDelegationRemoved tx result event

Also remove bakerId from AbstractBakerResult.

* Add DelegationBakerRemoved tx result event

Also remove delegatorId from AbstractDelegatorResult.
  • Loading branch information
Radiokot authored Sep 2, 2024
1 parent 1594b4e commit 3032c9f
Show file tree
Hide file tree
Showing 36 changed files with 259 additions and 32 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased
- Support for Protocol 7
- Added `ProtocolVersion.V7` corresponding to Protocol version 7
- Added `cooldowns` list to `AccountInfo`
- Added `availableBalance` to `AccountInfo`
- Made optional the following `BakerPoolStatus` fields:
`bakerEquityCapital`, `delegatedCapital`, `delegatedCapitalCap`, `poolInfo`
- Added `BakerDelegationRemoved` and `DelegationBakerRemoved` transaction result events

## 7.2.0
- Added `MessageSigningDigest` class to generate digests for message signing
- Added support for company identity attributes
Expand Down
2 changes: 1 addition & 1 deletion concordium-android-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.concordium.sdk</groupId>
<artifactId>concordium-sdk-base</artifactId>
<version>7.2.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>

<artifactId>concordium-android-sdk</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion concordium-sdk-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>com.concordium.sdk</groupId>
<artifactId>concordium-sdk</artifactId>
<version>7.2.0</version>
<version>8.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion concordium-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.concordium.sdk</groupId>
<artifactId>concordium-sdk-base</artifactId>
<version>7.2.0</version>
<version>8.0.0-SNAPSHOT</version>
</parent>

<groupId>com.concordium.sdk</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.concordium.sdk;

import com.concordium.grpc.v2.AbsoluteBlockHeight;
import com.concordium.grpc.v2.AccessStructure;
import com.concordium.grpc.v2.AccountAddress;
import com.concordium.grpc.v2.AccountIndex;
Expand All @@ -9,6 +10,7 @@
import com.concordium.grpc.v2.BlockItem;
import com.concordium.grpc.v2.Commitment;
import com.concordium.grpc.v2.ContractAddress;
import com.concordium.grpc.v2.Cooldown;
import com.concordium.grpc.v2.CredentialPublicKeys;
import com.concordium.grpc.v2.CredentialRegistrationId;
import com.concordium.grpc.v2.DelegatorInfo;
Expand All @@ -21,7 +23,6 @@
import com.concordium.grpc.v2.Policy;
import com.concordium.grpc.v2.ProtocolVersion;
import com.concordium.grpc.v2.ReleaseSchedule;
import com.concordium.grpc.v2.AbsoluteBlockHeight;
import com.concordium.grpc.v2.*;
import com.concordium.sdk.crypto.bulletproof.BulletproofGenerators;
import com.concordium.sdk.crypto.ed25519.ED25519PublicKey;
Expand Down Expand Up @@ -314,6 +315,7 @@ static com.concordium.sdk.responses.accountinfo.AccountInfo to(AccountInfo accou
builder
.Nonce(to(account.getSequenceNumber()))
.accountAmount(to(account.getAmount()))
.availableBalance(to(account.getAvailableBalance()))
.accountReleaseSchedule(to(account.getSchedule()))
.accountCredentials(ImmutableMap.copyOf(to(
account.getCredsMap(),
Expand All @@ -323,7 +325,8 @@ static com.concordium.sdk.responses.accountinfo.AccountInfo to(AccountInfo accou
.accountEncryptedAmount(to(account.getEncryptedBalance()))
.accountEncryptionKey(ElgamalPublicKey.from(account.getEncryptionKey().getValue().toByteArray()))
.accountIndex(to(account.getIndex()))
.accountAddress(to(account.getAddress()));
.accountAddress(to(account.getAddress()))
.cooldowns(copyOf(to(account.getCooldownsList(), ClientV2MapperExtensions::to)));

if (account.hasStake()) {
switch (account.getStake().getStakingInfoCase()) {
Expand All @@ -344,6 +347,14 @@ static com.concordium.sdk.types.AccountAddress to(AccountAddress address) {
return com.concordium.sdk.types.AccountAddress.from(address.getValue().toByteArray());
}

static com.concordium.sdk.responses.accountinfo.Cooldown to(Cooldown cooldown) {
return com.concordium.sdk.responses.accountinfo.Cooldown.builder()
.amount(to(cooldown.getAmount()))
.endTime(Timestamp.from(cooldown.getEndTime()))
.status(com.concordium.sdk.responses.accountinfo.Cooldown.CooldownStatus.from(cooldown.getStatus()))
.build();
}

@Nullable
static AccountDelegation to(com.concordium.grpc.v2.AccountStakingInfo.Delegator stake) {
return AccountDelegation.builder()
Expand Down Expand Up @@ -1232,14 +1243,24 @@ static BakerPoolStatus to(PoolInfoResponse grpcOutput) {
return BakerPoolStatus.builder()
.bakerId(to(grpcOutput.getBaker()))
.bakerAddress(to(grpcOutput.getAddress()))
.bakerEquityCapital(to(grpcOutput.getEquityCapital()))
.delegatedCapital(to(grpcOutput.getDelegatedCapital()))
.delegatedCapitalCap(to(grpcOutput.getDelegatedCapitalCap()))
.poolInfo(to(grpcOutput.getPoolInfo()))
.bakerEquityCapital(grpcOutput.hasEquityCapital()
? to(grpcOutput.getEquityCapital())
: null)
.delegatedCapital(grpcOutput.hasDelegatedCapital()
? to(grpcOutput.getDelegatedCapital())
: null)
.delegatedCapitalCap(grpcOutput.hasDelegatedCapitalCap()
? to(grpcOutput.getDelegatedCapitalCap())
: null)
.poolInfo(grpcOutput.hasPoolInfo()
? to(grpcOutput.getPoolInfo())
: null)
.bakerStakePendingChange(grpcOutput.hasEquityPendingChange()
? to(grpcOutput.getEquityPendingChange())
: null)
.currentPaydayStatus(grpcOutput.hasCurrentPaydayInfo() ? to(grpcOutput.getCurrentPaydayInfo()) : null)
.currentPaydayStatus(grpcOutput.hasCurrentPaydayInfo()
? to(grpcOutput.getCurrentPaydayInfo())
: null)
.allPoolTotalCapital(to(grpcOutput.getAllPoolTotalCapital()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.concordium.sdk.responses;

import com.concordium.grpc.v2.DelegatorId;
import com.concordium.sdk.types.UInt16;
import com.concordium.sdk.types.UInt64;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.val;

import java.nio.ByteBuffer;

/**
* Account index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public enum ProtocolVersion {
/**
* https://github.com/Concordium/concordium-update-proposals/blob/main/updates/P6.txt
*/
V6;
V6,
/**
* https://github.com/Concordium/concordium-update-proposals/blob/main/updates/P7.txt
*/
V7,
;

/**
* Parses {@link com.concordium.grpc.v2.ProtocolVersion} to {@link ProtocolVersion}.
Expand All @@ -46,6 +51,8 @@ public static ProtocolVersion parse(com.concordium.grpc.v2.ProtocolVersion proto
return V5;
case PROTOCOL_VERSION_6:
return V6;
case PROTOCOL_VERSION_7:
return V7;
default:
throw new IllegalArgumentException("Unrecognized protocol version " + protocolVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import com.concordium.sdk.transactions.Index;
import com.concordium.sdk.types.AccountAddress;
import com.concordium.sdk.types.Nonce;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Singular;
import lombok.extern.jackson.Jacksonized;

Expand All @@ -37,6 +37,15 @@ public final class AccountInfo {
* The amount of CCD owned by this account.
*/
private final CCDAmount accountAmount;
/**
* The available (unencrypted) balance of the account (i.e. that can be transferred
* or used to pay for transactions). This is the balance ({@link AccountInfo#accountAmount})
* minus the locked amount.
* The locked amount is the maximum of the amount in the release schedule ({@link AccountInfo#accountReleaseSchedule})
* and the total amount that is actively staked or in cooldown (inactive stake, {@link AccountInfo#cooldowns}).
* This was introduced in node version 7.0.
*/
private final CCDAmount availableBalance;
/**
* The account threshold for this account i.e., how
* many credentials that needs to sign transactions for this account.
Expand Down Expand Up @@ -76,11 +85,18 @@ public final class AccountInfo {
*/
@Singular
private final ImmutableMap<Index, Credential> accountCredentials;

/**
* If the account is delegating then this is non-null.
*/
private final AccountDelegation delegation;
/**
* The stake on the account that is in cooldown.
* There can be multiple amounts in cooldown that expire at different times.
* This was introduced in protocol version 7, and so is not present in
* earlier protocol versions.
*/
@Singular
private final ImmutableList<Cooldown> cooldowns;

public boolean isBaker() {
return !Objects.isNull(bakerInfo);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.concordium.sdk.responses.accountinfo;

import com.concordium.sdk.transactions.CCDAmount;
import com.concordium.sdk.types.Timestamp;
import lombok.Builder;
import lombok.Data;
import lombok.extern.jackson.Jacksonized;

/**
* Records the amount, (expected) release time and whether it's a regular cooldown,
* pre-cooldown or pre-pre-cooldown.
*/
@Data
@Jacksonized
@Builder
public final class Cooldown {
/**
* The time in milliseconds since the Unix epoch when the cooldown period ends.
*/
private final Timestamp endTime;
/**
* The amount that is in cooldown and set to be released at the end of the
* cooldown period.
*/
private final CCDAmount amount;
/**
* The status of the cooldown.
*/
private final CooldownStatus status;

public enum CooldownStatus {
COOLDOWN,
PRE_COOLDOWN,
PRE_PRE_COOLDOWN,
;

public static CooldownStatus from(com.concordium.grpc.v2.Cooldown.CooldownStatus cooldownStatus) {
switch (cooldownStatus) {
case COOLDOWN:
return COOLDOWN;
case PRE_COOLDOWN:
return PRE_COOLDOWN;
case PRE_PRE_COOLDOWN:
return PRE_PRE_COOLDOWN;
default:
throw new IllegalArgumentException("Unrecognized cooldown status.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public static BakerConfigured from(AccountTransactionEffects.BakerConfigured bak
case BAKER_SET_FINALIZATION_REWARD_COMMISSION:
builder.event(BakerSetFinalizationRewardCommission.from(bakerEvent.getBakerSetFinalizationRewardCommission(), sender));
break;
case DELEGATION_REMOVED:
builder.event(BakerDelegationRemoved.from(bakerEvent.getDelegationRemoved(), sender));
case EVENT_NOT_SET:
throw new IllegalArgumentException("Baker event was not set.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static DelegatorConfigured from(AccountTransactionEffects.DelegationConfi
case DELEGATION_REMOVED:
builder.event(DelegationRemoved.from(delegationEvent.getDelegationRemoved(), sender));
break;
case BAKER_REMOVED:
builder.event(DelegationBakerRemoved.from(delegationEvent.getBakerRemoved(), sender));
case EVENT_NOT_SET:
throw new IllegalArgumentException("Delegation event type not set");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class BakerPoolStatus {

/**
* Any pending change to the baker's stake.
* This is not used from protocol version 7 onwards, as stake changes are immediate.
*/
private final PendingChange bakerStakePendingChange;

Expand All @@ -60,6 +61,22 @@ public class BakerPoolStatus {
*/
private final CCDAmount allPoolTotalCapital;

public Optional<CCDAmount> getBakerEquityCapital() {
return Optional.ofNullable(bakerEquityCapital);
}

public Optional<CCDAmount> getDelegatedCapital() {
return Optional.ofNullable(delegatedCapital);
}

public Optional<CCDAmount> getDelegatedCapitalCap() {
return Optional.ofNullable(delegatedCapitalCap);
}

public Optional<BakerPoolInfo> getPoolInfo() {
return Optional.ofNullable(poolInfo);
}

public Optional<PendingChange> getBakerStakePendingChange() {
return Optional.ofNullable(bakerStakePendingChange);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.concordium.sdk.responses.transactionstatus;

import com.concordium.sdk.crypto.ed25519.ED25519PublicKey;
import com.concordium.sdk.responses.BakerId;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
Expand All @@ -14,6 +15,7 @@
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public abstract class AbstractBakerChangeResult extends AbstractBakerResult {
private final BakerId bakerId;

/**
* The public VRF key of the baker.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.concordium.sdk.responses.transactionstatus;

import com.concordium.sdk.responses.BakerId;
import com.concordium.sdk.types.AccountAddress;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -12,7 +11,5 @@
@SuperBuilder
@EqualsAndHashCode
public abstract class AbstractBakerResult implements TransactionResultEvent {
private final BakerId bakerId;
private final AccountAddress account;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@
@SuperBuilder
@EqualsAndHashCode
public abstract class AbstractDelegatorResult implements TransactionResultEvent {
private final AccountIndex delegatorId;
private final AccountAddress delegatorAddress;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.concordium.sdk.responses.transactionstatus;

import com.concordium.grpc.v2.BakerEvent;
import com.concordium.sdk.responses.AccountIndex;
import com.concordium.sdk.types.AccountAddress;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;

/**
* Removed an existing delegator.
*/
@Getter
@ToString
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public class BakerDelegationRemoved extends AbstractBakerResult {

private final AccountIndex delegatorId;

public static BakerDelegationRemoved from(BakerEvent.DelegationRemoved bakerDelegationRemoved, AccountAddress sender) {
return BakerDelegationRemoved
.builder()
.delegatorId(AccountIndex.from(bakerDelegationRemoved.getDelegatorId()))
.account(sender)
.build();
}

@Override
public TransactionResultEventType getType() {
return TransactionResultEventType.BAKER_DELEGATION_REMOVED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public final class BakerRemovedResult extends AbstractBakerResult {
private final BakerId bakerId;

public static BakerRemovedResult from(com.concordium.grpc.v2.BakerId bakerRemoved, AccountAddress accountAddress) {
return BakerRemovedResult
.builder()
Expand Down
Loading

0 comments on commit 3032c9f

Please sign in to comment.