Skip to content

Commit 887c6bb

Browse files
committed
Implemented TokenRepository to interact with MirrorNodeClient
Signed-off-by: Manish Dait <[email protected]>
1 parent 1eaf6e3 commit 887c6bb

File tree

23 files changed

+1435
-5
lines changed

23 files changed

+1435
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.openelements.hiero.base.data;
2+
3+
import com.hedera.hashgraph.sdk.AccountId;
4+
import org.jspecify.annotations.NonNull;
5+
6+
import java.util.Objects;
7+
8+
public record Balance(@NonNull AccountId accountId, long balance, long decimals) {
9+
public Balance {
10+
Objects.requireNonNull(accountId, "accountId must not be null");
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.openelements.hiero.base.data;
2+
3+
import java.util.List;
4+
5+
public record CustomFee(List<FixedFee> fixedFees, List<FractionalFee> fractionalFees, List<RoyaltyFee> royaltyFees) {
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.openelements.hiero.base.data;
2+
3+
import com.hedera.hashgraph.sdk.AccountId;
4+
import com.hedera.hashgraph.sdk.TokenId;
5+
import org.jspecify.annotations.Nullable;
6+
7+
public record FixedFee(long amount, @Nullable AccountId collectorAccountId, @Nullable TokenId denominatingTokenId) {
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.openelements.hiero.base.data;
2+
3+
import com.hedera.hashgraph.sdk.AccountId;
4+
import com.hedera.hashgraph.sdk.TokenId;
5+
import org.jspecify.annotations.Nullable;
6+
7+
public record FractionalFee(
8+
long numeratorAmount,
9+
long denominatorAmount,
10+
@Nullable AccountId collectorAccountId,
11+
@Nullable TokenId denominatingTokenId
12+
) {
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.openelements.hiero.base.data;
2+
3+
import com.hedera.hashgraph.sdk.AccountId;
4+
import com.hedera.hashgraph.sdk.TokenId;
5+
import org.jspecify.annotations.Nullable;
6+
7+
public record RoyaltyFee(
8+
long numeratorAmount,
9+
long denominatorAmount,
10+
long fallbackFeeAmount,
11+
@Nullable AccountId collectorAccountId,
12+
@Nullable TokenId denominatingTokenId
13+
) {
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.openelements.hiero.base.data;
2+
3+
import com.hedera.hashgraph.sdk.TokenId;
4+
import com.hedera.hashgraph.sdk.TokenType;
5+
import org.jspecify.annotations.NonNull;
6+
import org.jspecify.annotations.Nullable;
7+
8+
import java.util.Objects;
9+
10+
public record Token(
11+
long decimals,
12+
byte[] metadata,
13+
@NonNull String name,
14+
@NonNull String symbol,
15+
@Nullable TokenId tokenId,
16+
@NonNull TokenType type
17+
) {
18+
public Token {
19+
Objects.requireNonNull(type, "type must not be null");
20+
Objects.requireNonNull(name, "name must not be null");
21+
Objects.requireNonNull(symbol, "symbol must not be null");
22+
Objects.requireNonNull(metadata, "metadata must not be null");
23+
}
24+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.openelements.hiero.base.data;
2+
3+
import com.hedera.hashgraph.sdk.AccountId;
4+
import com.hedera.hashgraph.sdk.TokenId;
5+
import com.hedera.hashgraph.sdk.TokenSupplyType;
6+
import com.hedera.hashgraph.sdk.TokenType;
7+
import org.jspecify.annotations.NonNull;
8+
import org.jspecify.annotations.Nullable;
9+
10+
import java.time.Instant;
11+
import java.util.Objects;
12+
13+
public record TokenInfo(
14+
@NonNull TokenId tokenId,
15+
@NonNull TokenType type,
16+
@NonNull String name,
17+
@NonNull String symbol,
18+
@Nullable String memo,
19+
long decimals,
20+
byte[] metadata,
21+
@NonNull Instant createdTimestamp,
22+
@NonNull Instant modifiedTimestamp,
23+
@Nullable Instant expiryTimestamp,
24+
@NonNull TokenSupplyType supplyType,
25+
@NonNull String initialSupply,
26+
@NonNull String totalSupply,
27+
@NonNull String maxSupply,
28+
@NonNull AccountId treasuryAccountId,
29+
boolean deleted,
30+
@NonNull CustomFee customFees
31+
) {
32+
public TokenInfo {
33+
Objects.requireNonNull(tokenId, "tokenId must not be null");
34+
Objects.requireNonNull(type, "type must not be null");
35+
Objects.requireNonNull(name, "name must not be null");
36+
Objects.requireNonNull(symbol, "symbol must not be null");
37+
Objects.requireNonNull(metadata, "metadata must not be null");
38+
Objects.requireNonNull(createdTimestamp, "createdTimestamp must not be null");
39+
Objects.requireNonNull(modifiedTimestamp, "modifiedTimestamp must not be null");
40+
Objects.requireNonNull(supplyType, "supplyType must not be null");
41+
Objects.requireNonNull(initialSupply, "initialSupply must not be null");
42+
Objects.requireNonNull(totalSupply, "totalSupply must not be null");
43+
Objects.requireNonNull(maxSupply, "maxSupply must not be null");
44+
Objects.requireNonNull(treasuryAccountId, "treasuryAccountId must not be null");
45+
Objects.requireNonNull(customFees, "customFees must not be null");
46+
}
47+
}

hiero-enterprise-base/src/main/java/com/openelements/hiero/base/implementation/AbstractMirrorNodeClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.openelements.hiero.base.data.NetworkSupplies;
1111
import com.openelements.hiero.base.data.Nft;
1212
import com.openelements.hiero.base.data.NftMetadata;
13+
import com.openelements.hiero.base.data.TokenInfo;
1314
import com.openelements.hiero.base.mirrornode.MirrorNodeClient;
1415
import java.util.List;
1516
import java.util.Objects;
@@ -68,6 +69,12 @@ final Optional<NetworkSupplies> queryNetworkSupplies() throws HieroException {
6869
return getJsonConverter().toNetworkSupplies(json);
6970
}
7071

72+
@NonNull
73+
public final Optional<TokenInfo> queryTokenById(@NonNull TokenId tokenId) throws HieroException {
74+
final JSON json = getRestClient().queryTokenById(tokenId);
75+
return getJsonConverter().toTokenInfo(json);
76+
}
77+
7178
@Override
7279
public @NonNull Optional<NftMetadata> getNftMetadata(TokenId tokenId) throws HieroException {
7380
throw new UnsupportedOperationException("Not yet implemented");

hiero-enterprise-base/src/main/java/com/openelements/hiero/base/implementation/MirrorNodeJsonConverter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import com.openelements.hiero.base.data.NetworkSupplies;
88
import com.openelements.hiero.base.data.Nft;
99
import com.openelements.hiero.base.data.TransactionInfo;
10+
import com.openelements.hiero.base.data.Token;
11+
import com.openelements.hiero.base.data.TokenInfo;
12+
import com.openelements.hiero.base.data.Balance;
13+
1014
import java.util.List;
1115
import java.util.Optional;
1216
import org.jspecify.annotations.NonNull;
@@ -36,4 +40,9 @@ public interface MirrorNodeJsonConverter<JSON> {
3640

3741
List<Nft> toNfts(@NonNull JSON json);
3842

43+
Optional<TokenInfo> toTokenInfo(JSON json);
44+
45+
List<Balance> toBalances(JSON node);
46+
47+
List<Token> toTokens(JSON node);
3948
}

hiero-enterprise-base/src/main/java/com/openelements/hiero/base/implementation/MirrorNodeRestClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ default JSON queryNetworkSupplies() throws HieroException {
5050
return doGetCall("/api/v1/network/supply");
5151
}
5252

53+
@NonNull
54+
default JSON queryTokenById(TokenId tokenId) throws HieroException {
55+
return doGetCall("/api/v1/tokens/" + tokenId);
56+
}
57+
5358
@NonNull
5459
JSON doGetCall(@NonNull String path) throws HieroException;
5560
}

0 commit comments

Comments
 (0)