Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
MilkywayPirate committed Feb 8, 2024
1 parent d936433 commit 4d8a9f4
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 144 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased changes
- Make the `energy` paramter for invoking an instance `Optional`.
- Parse the underlying reject reasons into `AccountTransactionDetails`.
- Introduced Cis2Client for interfacing with CIS2 compliant smart contracts.
- Support for deserializing contract update transactions.
Expand Down
6 changes: 6 additions & 0 deletions concordium-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
<version>3.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>

</dependencies>

<profiles>
Expand Down
59 changes: 32 additions & 27 deletions concordium-sdk/src/main/java/com/concordium/sdk/ClientV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -140,7 +141,6 @@ public Iterator<BlockIdentifier> getBlocks(int timeoutMillis) {
*
* @param timeoutMillis Timeout for the request in Milliseconds.
* @return {@link Iterator<BlockIdentifier>}
*
*/
public Iterator<BlockIdentifier> getFinalizedBlocks(int timeoutMillis) {
val grpcOutput = this.server(timeoutMillis)
Expand Down Expand Up @@ -234,7 +234,7 @@ public Hash sendTransaction(final AccountTransaction accountTransaction) {
/**
* Sends a credential deployment transaction to the Concordium Node.
*
* @param expiry the transaction expiry, i.e. the time after which the transaction is invalid
* @param expiry the transaction expiry, i.e. the time after which the transaction is invalid
* @param rawPayload the serialized bytes of the credential deployment transaction, including its signatures
* @return Transaction {@link Hash}.
*/
Expand Down Expand Up @@ -324,8 +324,8 @@ public AccountNonce getNextAccountSequenceNumber(AccountAddress address) {
* @param transactionHash The transaction {@link Hash}
* @return The {@link BlockItemStatus}
* @throws io.grpc.StatusRuntimeException with {@link io.grpc.Status.Code}: <ul>
* <li> {@link io.grpc.Status#NOT_FOUND} if the transaction is not known to the node.
* </ul>
* <li> {@link io.grpc.Status#NOT_FOUND} if the transaction is not known to the node.
* </ul>
*/
public BlockItemStatus getBlockItemStatus(Hash transactionHash) {
val grpcOutput = this.server()
Expand Down Expand Up @@ -794,9 +794,10 @@ public InvokeInstanceResult invokeInstance(InvokeInstanceRequest request) {
grpcRequest.setInstance(to(request.getInstance()))
.setAmount(to(request.getAmount()))
.setEntrypoint(to(request.getEntrypoint()))
.setParameter(to(request.getParameter()))
.setEnergy(com.concordium.grpc.v2.Energy.newBuilder().setValue(request.getEnergy().getValue().getValue()));

.setParameter(to(request.getParameter()));
if (request.getEnergy().isPresent()) {
grpcRequest.setEnergy(com.concordium.grpc.v2.Energy.newBuilder().setValue(request.getEnergy().get().getValue().getValue()));
}
val grpcResponse = this.server().invokeInstance(grpcRequest.build());
return InvokeInstanceResult.parse(grpcResponse);
}
Expand All @@ -808,7 +809,7 @@ public InvokeInstanceResult invokeInstance(InvokeInstanceRequest request) {
* @param input The block to query.
* @return {@link ImmutableList} with the {@link BakerRewardPeriodInfo} of all the bakers in the block.
* @throws io.grpc.StatusRuntimeException with {@link io.grpc.Status.Code}:
* <ul><li>{@link io.grpc.Status.Code#UNIMPLEMENTED} if the protocol does not support the endpoint.</ul>
* <ul><li>{@link io.grpc.Status.Code#UNIMPLEMENTED} if the protocol does not support the endpoint.</ul>
*/
public ImmutableList<BakerRewardPeriodInfo> getBakersRewardPeriod(BlockQuery input) {
val response = this.server().getBakersRewardPeriod(to(input));
Expand All @@ -825,9 +826,9 @@ public ImmutableList<BakerRewardPeriodInfo> getBakersRewardPeriod(BlockQuery inp
* @param block The block to query
* @return {@link BlockCertificates} of the block.
* @throws io.grpc.StatusRuntimeException with {@link io.grpc.Status.Code}:<ul>
* <li>{@link io.grpc.Status.Code#UNIMPLEMENTED} if the endpoint is not enabled by the node.
* <li>{@link io.grpc.Status.Code#INVALID_ARGUMENT} if the block being pointed to is not a product of ConcordiumBFT, i.e. created before protocol version 6.
* </ul>
* <li>{@link io.grpc.Status.Code#UNIMPLEMENTED} if the endpoint is not enabled by the node.
* <li>{@link io.grpc.Status.Code#INVALID_ARGUMENT} if the block being pointed to is not a product of ConcordiumBFT, i.e. created before protocol version 6.
* </ul>
*/
public BlockCertificates getBlockCertificates(BlockQuery block) {
val res = this.server().getBlockCertificates(to(block));
Expand All @@ -836,7 +837,7 @@ public BlockCertificates getBlockCertificates(BlockQuery block) {

/**
* Get the projected earliest time at which a particular baker will be required to bake a block. <p>
*
* <p>
* If the baker is not a baker for the current reward period, this returns a timestamp at the
* start of the next reward period. <p>
* If the baker is a baker for the current reward period, the
Expand All @@ -849,10 +850,11 @@ public BlockCertificates getBlockCertificates(BlockQuery block) {
* epoch. This is because the seed for the leader election is updated at the epoch boundary, and
* so the winners cannot be predicted beyond that. <p>
* Note that in some circumstances the returned timestamp can be in the past, especially at the end of an epoch.
*
* @param bakerId id of the baker to query.
* @return {@link Timestamp} as described in the method documentation.
* @throws io.grpc.StatusRuntimeException with {@link io.grpc.Status.Code}:
* <ul><li>{@link io.grpc.Status.Code#UNIMPLEMENTED} if the current consensus version is 0, as the endpoint is only supported by consensus version 1.</ul>
* <ul><li>{@link io.grpc.Status.Code#UNIMPLEMENTED} if the current consensus version is 0, as the endpoint is only supported by consensus version 1.</ul>
*/
public Timestamp getBakerEarliestWinTime(BakerId bakerId) {
val res = this.server().getBakerEarliestWinTime(to(bakerId));
Expand All @@ -865,12 +867,12 @@ public Timestamp getBakerEarliestWinTime(BakerId bakerId) {
* @param epochQuery {@link EpochQuery} representing the specific epoch to query.
* @return {@link Hash} of the first finalized block in the epoch.
* @throws io.grpc.StatusRuntimeException with {@link io.grpc.Status.Code}: <ul>
* <li> {@link io.grpc.Status#NOT_FOUND} if the query specifies an unknown block.
* <li> {@link io.grpc.Status#UNAVAILABLE} if the query is for an epoch that is not finalized in the current genesis index, or is for a future genesis index.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the query is for an epoch with no finalized blocks for a past genesis index.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the input {@link EpochQuery} is malformed.
* <li> {@link io.grpc.Status#UNIMPLEMENTED} if the endpoint is disabled on the node.
* </ul>
* <li> {@link io.grpc.Status#NOT_FOUND} if the query specifies an unknown block.
* <li> {@link io.grpc.Status#UNAVAILABLE} if the query is for an epoch that is not finalized in the current genesis index, or is for a future genesis index.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the query is for an epoch with no finalized blocks for a past genesis index.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the input {@link EpochQuery} is malformed.
* <li> {@link io.grpc.Status#UNIMPLEMENTED} if the endpoint is disabled on the node.
* </ul>
*/
public Hash getFirstBlockEpoch(EpochQuery epochQuery) {
val res = this.server().getFirstBlockEpoch(to(epochQuery));
Expand All @@ -881,16 +883,17 @@ public Hash getFirstBlockEpoch(EpochQuery epochQuery) {
* Get the list of bakers that won the lottery in a particular historical epoch (i.e. the last finalized block is in a later epoch). <p>
* This lists the winners for each round in the epoch, starting from the round after the last block in the previous epoch, running to the round before the first block in the next epoch. <p>
* It also indicates if a block in each round was included in the finalized chain.
*
* @param epochQuery {@link EpochQuery} representing the specific epoch to query.
* @return {@link ImmutableList} of bakers that won the lottery in the specified epoch.
* @throws io.grpc.StatusRuntimeException with {@link io.grpc.Status.Code}: <ul>
* <li> {@link io.grpc.Status#NOT_FOUND} if the query specifies an unknown block.
* <li> {@link io.grpc.Status#UNAVAILABLE} if the query is for an epoch that is not finalized in the current genesis index, or is for a future genesis index.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the query is for an epoch that is not finalized for a past genesis index.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the query is for a genesis index at consensus version 0.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the input {@link EpochQuery} is malformed.
* <li> {@link io.grpc.Status#UNIMPLEMENTED} if the endpoint is disabled on the node.
* </ul>
* <li> {@link io.grpc.Status#NOT_FOUND} if the query specifies an unknown block.
* <li> {@link io.grpc.Status#UNAVAILABLE} if the query is for an epoch that is not finalized in the current genesis index, or is for a future genesis index.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the query is for an epoch that is not finalized for a past genesis index.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the query is for a genesis index at consensus version 0.
* <li> {@link io.grpc.Status#INVALID_ARGUMENT} if the input {@link EpochQuery} is malformed.
* <li> {@link io.grpc.Status#UNIMPLEMENTED} if the endpoint is disabled on the node.
* </ul>
*/
public ImmutableList<WinningBaker> getWinningBakersEpoch(EpochQuery epochQuery) {
val res = this.server().getWinningBakersEpoch(to(epochQuery));
Expand All @@ -905,8 +908,9 @@ public ImmutableList<WinningBaker> getWinningBakersEpoch(EpochQuery epochQuery)
* Waits until a given transaction is finalized and returns the corresponding {@link Optional<FinalizedBlockItem>}.
* If the transaction is unknown to the node or not finalized, the client starts listening for newly finalized blocks,
* and returns the corresponding {@link Optional<FinalizedBlockItem>} once the transaction is finalized.
*
* @param transactionHash the {@link Hash} of the transaction to wait for.
* @param timeoutMillis the number of milliseconds to listen for newly finalized blocks.
* @param timeoutMillis the number of milliseconds to listen for newly finalized blocks.
* @return {@link Optional<FinalizedBlockItem>} of the transaction if it was finalized before exceeding the timeout, Empty otherwise.
*/
public Optional<FinalizedBlockItem> waitUntilFinalized(Hash transactionHash, int timeoutMillis) {
Expand Down Expand Up @@ -940,6 +944,7 @@ public Optional<FinalizedBlockItem> waitUntilFinalized(Hash transactionHash, int

/**
* Helper function for {@link ClientV2#waitUntilFinalized(Hash, int)}. Retrieves the {@link Optional<FinalizedBlockItem>} of the transaction if it is finalized.
*
* @param transactionHash the {@link Hash} of the transaction to wait for.
* @return {@link Optional<FinalizedBlockItem>} of the transaction if it is finalized, Empty otherwise.
*/
Expand Down
Loading

0 comments on commit 4d8a9f4

Please sign in to comment.