Skip to content

Commit 516b240

Browse files
committed
feat: implement TransactionRepository for Hedera Mirror Node integration
1 parent 4ea92ba commit 516b240

File tree

3 files changed

+101
-3
lines changed

3 files changed

+101
-3
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.openelements.hedera.base;
2+
3+
import java.util.Objects;
4+
import java.util.Optional;
5+
6+
import org.jspecify.annotations.NonNull;
7+
8+
import com.hedera.hashgraph.sdk.AccountId;
9+
import com.openelements.hedera.base.mirrornode.Page;
10+
import com.openelements.hedera.base.mirrornode.TransactionInfo;
11+
12+
/**
13+
* Interface for interacting with transactions on a Hedera network.
14+
* This interface provides methods for querying transactions.
15+
*/
16+
public interface TransactionRepository {
17+
/**
18+
* Find all transactions associated with a specific account.
19+
*
20+
* @param accountId id of the account
21+
* @return page of transactions
22+
* @throws HederaException if the search fails
23+
*/
24+
@NonNull
25+
Page<TransactionInfo> findByAccount(@NonNull AccountId accountId) throws HederaException;
26+
27+
/**
28+
* Find all transactions associated with a specific account.
29+
*
30+
* @param accountId id of the account as a string
31+
* @return page of transactions
32+
* @throws HederaException if the search fails
33+
*/
34+
@NonNull
35+
default Page<TransactionInfo> findByAccount(@NonNull String accountId) throws HederaException {
36+
Objects.requireNonNull(accountId, "accountId must not be null");
37+
return findByAccount(AccountId.fromString(accountId));
38+
}
39+
40+
/**
41+
* Find a specific transaction by its ID.
42+
*
43+
* @param transactionId the transaction ID
44+
* @return Optional containing the transaction if found
45+
* @throws HederaException if the search fails
46+
*/
47+
@NonNull
48+
Optional<TransactionInfo> findById(@NonNull String transactionId) throws HederaException;
49+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.openelements.hedera.base.implementation;
2+
3+
import java.util.Objects;
4+
import java.util.Optional;
5+
6+
import org.jspecify.annotations.NonNull;
7+
8+
import com.hedera.hashgraph.sdk.AccountId;
9+
import com.openelements.hedera.base.HederaException;
10+
import com.openelements.hedera.base.TransactionRepository;
11+
import com.openelements.hedera.base.mirrornode.MirrorNodeClient;
12+
import com.openelements.hedera.base.mirrornode.Page;
13+
import com.openelements.hedera.base.mirrornode.TransactionInfo;
14+
15+
16+
public class TransactionRepositoryImpl implements TransactionRepository {
17+
private final MirrorNodeClient mirrorNodeClient;
18+
19+
public TransactionRepositoryImpl(@NonNull final MirrorNodeClient mirrorNodeClient) {
20+
this.mirrorNodeClient = Objects.requireNonNull(mirrorNodeClient, "mirrorNodeClient must not be null");
21+
}
22+
23+
@NonNull
24+
@Override
25+
public Page<TransactionInfo> findByAccount(@NonNull final AccountId accountId) throws HederaException {
26+
Objects.requireNonNull(accountId, "accountId must not be null");
27+
return this.mirrorNodeClient.queryTransactionsByAccount(accountId);
28+
}
29+
30+
@NonNull
31+
@Override
32+
public Optional<TransactionInfo> findById(@NonNull final String transactionId) throws HederaException {
33+
Objects.requireNonNull(transactionId, "transactionId must not be null");
34+
return this.mirrorNodeClient.queryTransaction(transactionId);
35+
}
36+
}

hedera-base/src/main/java/com/openelements/hedera/base/mirrornode/MirrorNodeClient.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.openelements.hedera.base.mirrornode;
22

3+
import java.util.Objects;
4+
import java.util.Optional;
5+
6+
import org.jspecify.annotations.NonNull;
7+
38
import com.hedera.hashgraph.sdk.AccountId;
49
import com.hedera.hashgraph.sdk.TokenId;
510
import com.openelements.hedera.base.HederaException;
611
import com.openelements.hedera.base.Nft;
7-
import java.util.Objects;
8-
import java.util.Optional;
9-
import org.jspecify.annotations.NonNull;
1012

1113
/**
1214
* A client for querying the Hedera Mirror Node REST API.
@@ -144,6 +146,17 @@ default Optional<Nft> queryNftsByAccountAndTokenIdAndSerial(@NonNull String acco
144146
serialNumber);
145147
}
146148

149+
/**
150+
* Queries all transactions for a specific account.
151+
*
152+
* @param accountId the account ID to query transactions for
153+
* @return a page of transaction information
154+
* @throws HederaException if an error occurs during the query
155+
*/
156+
@NonNull
157+
Page<TransactionInfo> queryTransactionsByAccount(@NonNull AccountId accountId) throws HederaException;
158+
159+
147160
/**
148161
* Queries the transaction information for a specific transaction ID.
149162
*

0 commit comments

Comments
 (0)