-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from Concordium/getBakersRewardPeriod
Get bakers reward period
- Loading branch information
Showing
6 changed files
with
389 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
concordium-sdk-examples/src/main/java/com/concordium/sdk/examples/GetBakersRewardPeriod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.concordium.sdk.examples; | ||
|
||
import com.concordium.sdk.ClientV2; | ||
import com.concordium.sdk.Connection; | ||
import com.concordium.sdk.requests.BlockQuery; | ||
import com.concordium.sdk.responses.bakersrewardperiod.BakerRewardPeriodInfo; | ||
import lombok.val; | ||
import picocli.CommandLine; | ||
|
||
import java.net.URL; | ||
import java.util.concurrent.Callable; | ||
|
||
/** | ||
* Calls {@link ClientV2#getBakersRewardPeriod(BlockQuery)} | ||
* retrieving a list of {@link BakerRewardPeriodInfo} about the bakers in the reward period of the block. | ||
* Prints the result to the terminal. | ||
*/ | ||
@CommandLine.Command(name = "GetBakersRewardPeriod", mixinStandardHelpOptions = true) | ||
public class GetBakersRewardPeriod implements Callable<Integer> { | ||
|
||
@CommandLine.Option( | ||
names = {"--endpoint"}, | ||
description = "GRPC interface of the node.", | ||
defaultValue = "http://localhost:20002") | ||
private String endpoint; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
URL endpointUrl = new URL(this.endpoint); | ||
Connection connection = Connection.newBuilder() | ||
.host(endpointUrl.getHost()) | ||
.port(endpointUrl.getPort()) | ||
.build(); | ||
|
||
ClientV2 client = ClientV2.from(connection); | ||
|
||
|
||
val bakerInfo = client.getBakersRewardPeriod(BlockQuery.BEST); | ||
bakerInfo.forEach(System.out::println); | ||
return 0; | ||
} | ||
|
||
public static void main(String[] args) { | ||
int exitCode = new CommandLine(new GetBakersRewardPeriod()).execute(args); | ||
System.exit(exitCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
concordium-sdk/src/main/java/com/concordium/sdk/responses/bakersrewardperiod/BakerInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.concordium.sdk.responses.bakersrewardperiod; | ||
|
||
import com.concordium.sdk.crypto.bls.BLSPublicKey; | ||
import com.concordium.sdk.crypto.ed25519.ED25519PublicKey; | ||
import com.concordium.sdk.crypto.vrf.VRFPublicKey; | ||
import com.concordium.sdk.responses.BakerId; | ||
import com.concordium.sdk.responses.nodeinfo.NodeInfo; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Information about a baker. | ||
*/ | ||
@Builder | ||
@Getter | ||
@EqualsAndHashCode | ||
@ToString | ||
public class BakerInfo { | ||
|
||
/** | ||
* Id of the baker. | ||
*/ | ||
private BakerId bakerId; | ||
/** | ||
* Baker's public key used to check whether they won the lottery or not. | ||
*/ | ||
private VRFPublicKey bakerElectionVerifyKey; | ||
/** | ||
* Baker's public key used to check that they are indeed the ones who produced the block. | ||
*/ | ||
private ED25519PublicKey bakerSignatureVerifyKey; | ||
/** | ||
* Baker's public key used to check signatures on finalization records. | ||
* This is only used if the baker has sufficient stake to participate in finalization. | ||
*/ | ||
private BLSPublicKey bakerAggregationVerifyKey; | ||
|
||
/** | ||
* Parses {@link com.concordium.grpc.v2.BakerInfo} to {@link BakerInfo}. | ||
* | ||
* @param bakerInfo {@link com.concordium.grpc.v2.BakerInfo} returned by the GRPC v2 API. | ||
* @return Parsed {@link BakerRewardPeriodInfo}. | ||
*/ | ||
public static BakerInfo from(com.concordium.grpc.v2.BakerInfo bakerInfo) { | ||
return BakerInfo.builder() | ||
.bakerId(BakerId.from(bakerInfo.getBakerId())) | ||
.bakerElectionVerifyKey(VRFPublicKey.from(bakerInfo.getElectionKey().getValue().toByteArray())) | ||
.bakerSignatureVerifyKey(ED25519PublicKey.from(bakerInfo.getSignatureKey().getValue().toByteArray())) | ||
.bakerAggregationVerifyKey(BLSPublicKey.from(bakerInfo.getAggregationKey().getValue().toByteArray())) | ||
.build(); | ||
} | ||
} | ||
|
||
|
63 changes: 63 additions & 0 deletions
63
.../src/main/java/com/concordium/sdk/responses/bakersrewardperiod/BakerRewardPeriodInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.concordium.sdk.responses.bakersrewardperiod; | ||
|
||
import com.concordium.sdk.responses.accountinfo.CommissionRates; | ||
import com.concordium.sdk.transactions.CCDAmount; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Information about a particular baker with respect to the current reward period. | ||
*/ | ||
@Builder | ||
@ToString | ||
@Getter | ||
@EqualsAndHashCode | ||
public class BakerRewardPeriodInfo { | ||
|
||
/** | ||
* The baker id and public keys for the baker. | ||
*/ | ||
private BakerInfo baker; | ||
/** | ||
* The effective stake of the baker for the consensus protocol. | ||
* The returned amount accounts for delegation, capital bounds and leverage bounds. | ||
*/ | ||
private CCDAmount effectiveStake; | ||
/** | ||
* The effective commission rate for the baker that applies for the reward period. | ||
*/ | ||
private CommissionRates commissionRates; | ||
/** | ||
* The amount staked by the baker itself. | ||
*/ | ||
private CCDAmount equityCapital; | ||
/** | ||
* The total amount of capital delegated to this baker pool. | ||
*/ | ||
private CCDAmount delegatedCapital; | ||
/** | ||
* Whether the baker is a finalizer or not. | ||
*/ | ||
private boolean isFinalizer; | ||
|
||
/** | ||
* Parses {@link com.concordium.grpc.v2.BakerRewardPeriodInfo} to {@link BakerRewardPeriodInfo}. | ||
* | ||
* @param info {@link com.concordium.grpc.v2.BakerRewardPeriodInfo} returned by the GRPC v2 API. | ||
* @return Parsed {@link BakerRewardPeriodInfo}. | ||
*/ | ||
public static BakerRewardPeriodInfo from(com.concordium.grpc.v2.BakerRewardPeriodInfo info) { | ||
return BakerRewardPeriodInfo.builder() | ||
.baker(BakerInfo.from(info.getBaker())) | ||
.effectiveStake(CCDAmount.from(info.getEffectiveStake())) | ||
.commissionRates(CommissionRates.from(info.getCommissionRates())) | ||
.equityCapital(CCDAmount.from(info.getEquityCapital())) | ||
.delegatedCapital(CCDAmount.from(info.getDelegatedCapital())) | ||
.isFinalizer(info.getIsFinalizer()) | ||
.build(); | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.