-
Notifications
You must be signed in to change notification settings - Fork 19
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 #143 from manishdait/issue-98
feat: Implemented TokenRepository to interact with MirrorNodeClient API
- Loading branch information
Showing
23 changed files
with
1,464 additions
and
5 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/Balance.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,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"); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/CustomFee.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,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"); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/FixedFee.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,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 {} | ||
} |
21 changes: 21 additions & 0 deletions
21
hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/FractionalFee.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,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, | ||
@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"); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/RoyaltyFee.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,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( | ||
long numeratorAmount, | ||
long denominatorAmount, | ||
long fallbackFeeAmount, | ||
@Nullable AccountId collectorAccountId, | ||
@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"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/Token.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,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"); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/TokenInfo.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.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"); | ||
} | ||
} |
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
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
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
43 changes: 43 additions & 0 deletions
43
...se-base/src/main/java/com/openelements/hiero/base/implementation/TokenRepositoryImpl.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,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); | ||
} | ||
} |
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
Oops, something went wrong.