Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.openelements.hedera.base;

import com.openelements.hedera.base.mirrornode.ExchangeRates;
import com.openelements.hedera.base.mirrornode.NetworkFee;
import com.openelements.hedera.base.mirrornode.NetworkStake;
import com.openelements.hedera.base.mirrornode.NetworkSupplies;

import java.util.List;
import java.util.Optional;

/**
* Interface for interacting with a Hedera network. This interface provides methods to get information related to Network.
*/
public interface NetworkRepository {
/**
* Return the ExchangeRates for network.
*
* @return {@link Optional} containing the ExchangeRates or null
* @throws HederaException if the search fails
*/
Optional<ExchangeRates> exchangeRates() throws HederaException;

/**
* Return the List of NetworkFee for network.
*
* @return {@link List} containing NetworkFee or empty list
* @throws HederaException if the search fails
*/
List<NetworkFee> fees() throws HederaException;

/**
* Return the NetworkStake for network.
*
* @return {@link Optional} containing NetworkStake or null
* @throws HederaException if the search fails
*/
Optional<NetworkStake> stake() throws HederaException;

/**
* Return the NetworkSupplies for network.
*
* @return {@link Optional} containing NetworkSupplies or null
* @throws HederaException if the search fails
*/
Optional<NetworkSupplies> supplies() throws HederaException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.openelements.hedera.base.implementation;

import com.openelements.hedera.base.HederaException;
import com.openelements.hedera.base.NetworkRepository;
import com.openelements.hedera.base.mirrornode.ExchangeRates;
import com.openelements.hedera.base.mirrornode.MirrorNodeClient;
import com.openelements.hedera.base.mirrornode.NetworkFee;
import com.openelements.hedera.base.mirrornode.NetworkStake;
import com.openelements.hedera.base.mirrornode.NetworkSupplies;
import org.jspecify.annotations.NonNull;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class NetworkRepositoryImpl implements NetworkRepository {
private final MirrorNodeClient mirrorNodeClient;

public NetworkRepositoryImpl(@NonNull final MirrorNodeClient mirrorNodeClient) {
this.mirrorNodeClient = Objects.requireNonNull(mirrorNodeClient, "mirrorNodeClient must not be null");
}

@Override
public Optional<ExchangeRates> exchangeRates() throws HederaException {
return mirrorNodeClient.queryExchangeRates();
}

@Override
public List<NetworkFee> fees() throws HederaException {
return mirrorNodeClient.queryNetworkFees();
}

@Override
public Optional<NetworkStake> stake() throws HederaException {
return mirrorNodeClient.queryNetworkStake();
}

@Override
public Optional<NetworkSupplies> supplies() throws HederaException {
return mirrorNodeClient.queryNetworkSupplies();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.openelements.hedera.base.mirrornode;

import org.jspecify.annotations.NonNull;

import java.time.Instant;
import java.util.Objects;

public record ExchangeRate(int centEquivalent, int hbarEquivalent, @NonNull Instant expirationTime) {
public ExchangeRate {
Objects.requireNonNull(expirationTime, "expirationTime must not be null");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.openelements.hedera.base.mirrornode;

import org.jspecify.annotations.NonNull;

import java.util.Objects;

public record ExchangeRates(@NonNull ExchangeRate currentRate, @NonNull ExchangeRate nextRate) {
public ExchangeRates {
Objects.requireNonNull(currentRate, "currentRate must not be null");
Objects.requireNonNull(nextRate, "nextRate must not be null");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.openelements.hedera.base.mirrornode;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -189,4 +190,40 @@ default Optional<AccountInfo> queryAccount(@NonNull String accountId) throws Hed
Objects.requireNonNull(accountId, "accountId must not be null");
return queryAccount(AccountId.fromString(accountId));
}

/**
* Queries the ExchangeRates for the network.
*
* @return the Optional of ExchangeRates for the Network
* @throws HederaException if an error occurs
*/
@NonNull
Optional<ExchangeRates> queryExchangeRates() throws HederaException;

/**
* Queries the NetworkFee for the network.
*
* @return the List of NetworkFee for the Network
* @throws HederaException if an error occurs
*/
@NonNull
List<NetworkFee> queryNetworkFees() throws HederaException;

/**
* Queries the NetworkStake for the network.
*
* @return the Optional of NetworkStake for the Network
* @throws HederaException if an error occurs
*/
@NonNull
Optional<NetworkStake> queryNetworkStake() throws HederaException;

/**
* Queries the NetworkSupplies for the network.
*
* @return the Optional of NetworkSupplies for the Network
* @throws HederaException if an error occurs
*/
@NonNull
Optional<NetworkSupplies> queryNetworkSupplies() throws HederaException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.openelements.hedera.base.mirrornode;

import org.jspecify.annotations.NonNull;

import java.util.Objects;

public record NetworkFee(long gas, @NonNull String transactionType) {
public NetworkFee {
Objects.requireNonNull(transactionType, "transactionType must not be null");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.openelements.hedera.base.mirrornode;

public record NetworkStake(
long maxStakeReward,
long maxStakeRewardPerHbar,
long maxTotalReward,
double nodeRewardFeeFraction,
long reservedStakingRewards,
long rewardBalanceThreshold,
long stakeTotal,
long stakingPeriodDuration,
long stakingPeriodsStored,
double stakingRewardFeeFraction,
long stakingRewardRate,
long stakingStartThreshold,
long unreservedStakingRewardBalance
) {
public NetworkStake {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.openelements.hedera.base.mirrornode;

import org.jspecify.annotations.NonNull;

import java.util.Objects;

public record NetworkSupplies(@NonNull String releasedSupply, @NonNull String totalSupply) {
public NetworkSupplies {
Objects.requireNonNull(releasedSupply, "releasedSupply must not be null");
Objects.requireNonNull(totalSupply, "totalSupply must not be null");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.openelements.hedera.base.NftClient;
import com.openelements.hedera.base.NftRepository;
import com.openelements.hedera.base.AccountRepository;
import com.openelements.hedera.base.NetworkRepository;
import com.openelements.hedera.base.SmartContractClient;
import com.openelements.hedera.base.implementation.AccountClientImpl;
import com.openelements.hedera.base.implementation.FileClientImpl;
Expand All @@ -19,6 +20,7 @@
import com.openelements.hedera.base.implementation.ProtocolLayerClientImpl;
import com.openelements.hedera.base.implementation.SmartContractClientImpl;
import com.openelements.hedera.base.implementation.AccountRepositoryImpl;
import com.openelements.hedera.base.implementation.NetworkRepositoryImpl;
import com.openelements.hedera.base.mirrornode.MirrorNodeClient;
import com.openelements.hedera.base.protocol.ProtocolLayerClient;
import java.net.URI;
Expand Down Expand Up @@ -209,6 +211,13 @@ AccountRepository accountRepository(final MirrorNodeClient mirrorNodeClient) {
return new AccountRepositoryImpl(mirrorNodeClient);
}

@Bean
@ConditionalOnProperty(prefix = "spring.hedera", name = "mirrorNodeSupported",
havingValue = "true", matchIfMissing = true)
NetworkRepository networkRepository(final MirrorNodeClient mirrorNodeClient) {
return new NetworkRepositoryImpl(mirrorNodeClient);
}

@Bean
ContractVerificationClient contractVerificationClient(HederaNetwork hederaNetwork) {
return new ContractVerificationClientImplementation(hederaNetwork);
Expand Down
Loading
Loading