-
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.
Implemented TokenRepository to interact with MirrorNodeClient
Signed-off-by: Manish Dait <[email protected]>
- Loading branch information
1 parent
1eaf6e3
commit 887c6bb
Showing
23 changed files
with
1,435 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"); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
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,6 @@ | ||
package com.openelements.hiero.base.data; | ||
|
||
import java.util.List; | ||
|
||
public record CustomFee(List<FixedFee> fixedFees, List<FractionalFee> fractionalFees, List<RoyaltyFee> royaltyFees) { | ||
} |
8 changes: 8 additions & 0 deletions
8
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,8 @@ | ||
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) { | ||
} |
13 changes: 13 additions & 0 deletions
13
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,13 @@ | ||
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 | ||
) { | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
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 | ||
) { | ||
} |
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.