Skip to content

Commit 625f3be

Browse files
Merge pull request #143 from manishdait/issue-98
feat: Implemented TokenRepository to interact with MirrorNodeClient API
2 parents 1eaf6e3 + 01c1e86 commit 625f3be

File tree

23 files changed

+1464
-5
lines changed

23 files changed

+1464
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.openelements.hiero.base.data;
2+
3+
import org.jspecify.annotations.NonNull;
4+
5+
import java.util.List;
6+
import java.util.Objects;
7+
8+
public record CustomFee(
9+
@NonNull List<FixedFee> fixedFees,
10+
@NonNull List<FractionalFee> fractionalFees,
11+
@NonNull List<RoyaltyFee> royaltyFees
12+
) {
13+
public CustomFee {
14+
Objects.requireNonNull(fixedFees, "fixedFees must not be null");
15+
Objects.requireNonNull(fractionalFees, "fractionalFees must not be null");
16+
Objects.requireNonNull(royaltyFees, "royaltyFees must not be null");
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
public FixedFee {}
9+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
public FractionalFee {
14+
if (numeratorAmount < 0) {
15+
throw new IllegalArgumentException("numeratorAmount must be greater than or equal to 0");
16+
}
17+
if (denominatorAmount < 0) {
18+
throw new IllegalArgumentException("denominatorAmount must be greater than or equal to 0");
19+
}
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
public RoyaltyFee {
15+
if (numeratorAmount < 0) {
16+
throw new IllegalArgumentException("numeratorAmount must be greater than or equal to 0");
17+
}
18+
if (denominatorAmount < 0) {
19+
throw new IllegalArgumentException("denominatorAmount must be greater than or equal to 0");
20+
}
21+
}
22+
}
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)