-
Notifications
You must be signed in to change notification settings - Fork 24
feat: Implemented TokenRepository to interact with MirrorNodeClient API #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.openelements.hiero.base.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.AccountId; | ||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public record Balance(@NonNull AccountId accountId, long balance, long decimals) { | ||
| public Balance { | ||
| Objects.requireNonNull(accountId, "accountId must not be null"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.openelements.hiero.base.data; | ||
|
|
||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public record CustomFee( | ||
| @NonNull List<FixedFee> fixedFees, | ||
| @NonNull List<FractionalFee> fractionalFees, | ||
| @NonNull List<RoyaltyFee> royaltyFees | ||
| ) { | ||
| public CustomFee { | ||
| Objects.requireNonNull(fixedFees, "fixedFees must not be null"); | ||
| Objects.requireNonNull(fractionalFees, "fractionalFees must not be null"); | ||
| Objects.requireNonNull(royaltyFees, "royaltyFees must not be null"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.openelements.hiero.base.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.AccountId; | ||
| import com.hedera.hashgraph.sdk.TokenId; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| public record FixedFee(long amount, @Nullable AccountId collectorAccountId, @Nullable TokenId denominatingTokenId) { | ||
| public FixedFee {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.openelements.hiero.base.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.AccountId; | ||
| import com.hedera.hashgraph.sdk.TokenId; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| public record FractionalFee( | ||
| long numeratorAmount, | ||
| long denominatorAmount, | ||
| @Nullable AccountId collectorAccountId, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NullChecks should be added in constructor. |
||
| @Nullable TokenId denominatingTokenId | ||
| ) { | ||
| public FractionalFee { | ||
| if (numeratorAmount < 0) { | ||
| throw new IllegalArgumentException("numeratorAmount must be greater than or equal to 0"); | ||
| } | ||
| if (denominatorAmount < 0) { | ||
| throw new IllegalArgumentException("denominatorAmount must be greater than or equal to 0"); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.openelements.hiero.base.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.AccountId; | ||
| import com.hedera.hashgraph.sdk.TokenId; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| public record RoyaltyFee( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ndacyayisenga-droid we should check if Hedera provides a documentation for those objects and add a javadoc here (we can create an issue for that)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There's hedera documentation for all that actually. I will get an issue once this is merged. |
||
| long numeratorAmount, | ||
| long denominatorAmount, | ||
| long fallbackFeeAmount, | ||
| @Nullable AccountId collectorAccountId, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NullChecks should be added in constructor.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ndacyayisenga-droid can you create an issue once the PR is merged |
||
| @Nullable TokenId denominatingTokenId | ||
| ) { | ||
| public RoyaltyFee { | ||
| if (numeratorAmount < 0) { | ||
| throw new IllegalArgumentException("numeratorAmount must be greater than or equal to 0"); | ||
| } | ||
| if (denominatorAmount < 0) { | ||
| throw new IllegalArgumentException("denominatorAmount must be greater than or equal to 0"); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.openelements.hiero.base.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.TokenId; | ||
| import com.hedera.hashgraph.sdk.TokenType; | ||
| import org.jspecify.annotations.NonNull; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public record Token( | ||
| long decimals, | ||
| byte[] metadata, | ||
| @NonNull String name, | ||
| @NonNull String symbol, | ||
| @Nullable TokenId tokenId, | ||
| @NonNull TokenType type | ||
| ) { | ||
| public Token { | ||
| Objects.requireNonNull(type, "type must not be null"); | ||
| Objects.requireNonNull(name, "name must not be null"); | ||
| Objects.requireNonNull(symbol, "symbol must not be null"); | ||
| Objects.requireNonNull(metadata, "metadata must not be null"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.openelements.hiero.base.data; | ||
|
|
||
| import com.hedera.hashgraph.sdk.AccountId; | ||
| import com.hedera.hashgraph.sdk.TokenId; | ||
| import com.hedera.hashgraph.sdk.TokenSupplyType; | ||
| import com.hedera.hashgraph.sdk.TokenType; | ||
| import org.jspecify.annotations.NonNull; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.Objects; | ||
|
|
||
| public record TokenInfo( | ||
| @NonNull TokenId tokenId, | ||
| @NonNull TokenType type, | ||
| @NonNull String name, | ||
| @NonNull String symbol, | ||
| @Nullable String memo, | ||
| long decimals, | ||
| byte[] metadata, | ||
| @NonNull Instant createdTimestamp, | ||
| @NonNull Instant modifiedTimestamp, | ||
| @Nullable Instant expiryTimestamp, | ||
| @NonNull TokenSupplyType supplyType, | ||
| @NonNull String initialSupply, | ||
| @NonNull String totalSupply, | ||
| @NonNull String maxSupply, | ||
| @NonNull AccountId treasuryAccountId, | ||
| boolean deleted, | ||
| @NonNull CustomFee customFees | ||
| ) { | ||
| public TokenInfo { | ||
| Objects.requireNonNull(tokenId, "tokenId must not be null"); | ||
| Objects.requireNonNull(type, "type must not be null"); | ||
| Objects.requireNonNull(name, "name must not be null"); | ||
| Objects.requireNonNull(symbol, "symbol must not be null"); | ||
| Objects.requireNonNull(metadata, "metadata must not be null"); | ||
| Objects.requireNonNull(createdTimestamp, "createdTimestamp must not be null"); | ||
| Objects.requireNonNull(modifiedTimestamp, "modifiedTimestamp must not be null"); | ||
| Objects.requireNonNull(supplyType, "supplyType must not be null"); | ||
| Objects.requireNonNull(initialSupply, "initialSupply must not be null"); | ||
| Objects.requireNonNull(totalSupply, "totalSupply must not be null"); | ||
| Objects.requireNonNull(maxSupply, "maxSupply must not be null"); | ||
| Objects.requireNonNull(treasuryAccountId, "treasuryAccountId must not be null"); | ||
| Objects.requireNonNull(customFees, "customFees must not be null"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package com.openelements.hiero.base.implementation; | ||
|
|
||
| import com.hedera.hashgraph.sdk.AccountId; | ||
| import com.hedera.hashgraph.sdk.TokenId; | ||
| import com.openelements.hiero.base.HieroException; | ||
| import com.openelements.hiero.base.data.Balance; | ||
| import com.openelements.hiero.base.data.Page; | ||
| import com.openelements.hiero.base.data.Token; | ||
| import com.openelements.hiero.base.data.TokenInfo; | ||
| import com.openelements.hiero.base.mirrornode.MirrorNodeClient; | ||
| import com.openelements.hiero.base.mirrornode.TokenRepository; | ||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| public class TokenRepositoryImpl implements TokenRepository { | ||
| private final MirrorNodeClient mirrorNodeClient; | ||
|
|
||
| public TokenRepositoryImpl(@NonNull final MirrorNodeClient mirrorNodeClient) { | ||
| this.mirrorNodeClient = Objects.requireNonNull(mirrorNodeClient, "mirrorNodeClient must not be null"); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<Token> findByAccount(@NonNull AccountId accountId) throws HieroException { | ||
| return mirrorNodeClient.queryTokensForAccount(accountId); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<TokenInfo> findById(@NonNull TokenId tokenId) throws HieroException { | ||
| return mirrorNodeClient.queryTokenById(tokenId); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<Balance> getBalances(@NonNull TokenId tokenId) throws HieroException { | ||
| return mirrorNodeClient.queryTokenBalances(tokenId); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<Balance> getBalancesForAccount(@NonNull TokenId tokenId, @NonNull AccountId accountId) throws HieroException { | ||
| return mirrorNodeClient.queryTokenBalancesForAccount(tokenId, accountId); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NullChecks should be added in constructor.