Skip to content

Commit 9063433

Browse files
committed
minor fix to handle nullable values and test
Signed-off-by: Manish Dait <[email protected]>
1 parent 5de0989 commit 9063433

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

hiero-enterprise-base/src/main/java/com/openelements/hiero/base/data/TransactionInfo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public record TransactionInfo(
3737
Objects.requireNonNull(maxFee, "maxFee must not be null");
3838
Objects.requireNonNull(name, "name must not be null");
3939
Objects.requireNonNull(nftTransfers, "nftTransfers must not be null");
40-
Objects.requireNonNull(parentConsensusTimestamp, "parentConsensusTimestamp must not be null");
4140
Objects.requireNonNull(stakingRewardTransfers, "stakingRewardTransfers must not be null");
4241
Objects.requireNonNull(tokenTransfers, "tokenTransfers must not be null");
4342
Objects.requireNonNull(transfers, "transfers must not be null");

hiero-enterprise-microprofile/src/main/java/com/openelements/hiero/microprofile/implementation/MirrorNodeJsonConverterImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ public class MirrorNodeJsonConverterImpl implements MirrorNodeJsonConverter<Json
169169
if (jsonObject.isEmpty()) {
170170
return Optional.empty();
171171
}
172+
173+
if (jsonObject.containsKey("transactions")) {
174+
jsonObject = jsonArrayToStream(jsonObject.getJsonArray("transactions")).findFirst().get().asJsonObject();
175+
}
176+
172177
try {
173178
final String transactionId = jsonObject.getString("transaction_id");
174179
final byte[] bytes = jsonObject.getString("bytes").getBytes();
@@ -180,7 +185,8 @@ public class MirrorNodeJsonConverterImpl implements MirrorNodeJsonConverter<Json
180185
final TransactionType name = TransactionType.from(jsonObject.getString("name"));
181186
final String _node = jsonObject.getString("node");
182187
final int nonce = jsonObject.getInt("nonce");
183-
final Instant parentConsensusTimestamp = Instant.ofEpochSecond((long) Double.parseDouble(jsonObject.getString("parent_consensus_timestamp")));
188+
final Instant parentConsensusTimestamp = jsonObject.get("parent_consensus_timestamp").asJsonObject() == null ? null :
189+
Instant.ofEpochSecond((long) Double.parseDouble(jsonObject.getString("parent_consensus_timestamp")));
184190
final String result = jsonObject.getString("result");
185191
final boolean scheduled = jsonObject.getBoolean("scheduled");
186192
final byte[] transactionHash = jsonObject.getString("transaction_hash").getBytes();

hiero-enterprise-spring/src/main/java/com/openelements/hiero/spring/implementation/MirrorNodeJsonConverterImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ public List<NetworkFee> toNetworkFees(final JsonNode node) {
201201
final TransactionType name = TransactionType.from(node.get("name").asText());
202202
final String _node = node.get("node").asText();
203203
final int nonce = node.get("nonce").asInt();
204-
final Instant parentConsensusTimestamp = Instant.ofEpochSecond(node.get("parent_consensus_timestamp").asLong());
204+
final Instant parentConsensusTimestamp = node.get("parent_consensus_timestamp").isNull()? null :
205+
Instant.ofEpochSecond(node.get("parent_consensus_timestamp").asLong());
205206
final String result = node.get("result").asText();
206207
final boolean scheduled = node.get("scheduled").asBoolean();
207208
final byte[] transactionHash = node.get("transaction_hash").asText().getBytes();

hiero-enterprise-spring/src/test/java/com/openelements/hiero/spring/test/TransactionRepositoryTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class TransactionRepositoryTest {
3232
@Test
3333
void testFindTransactionByAccountId() throws HieroException {
3434
final Account account = accountClient.createAccount(1);
35-
35+
hieroTestUtils.waitForMirrorNodeRecords();
3636
final Page<TransactionInfo> page = transactionRepository.findByAccount(account.accountId());
3737
Assertions.assertNotNull(page);
3838

@@ -43,6 +43,7 @@ void testFindTransactionByAccountId() throws HieroException {
4343
@Test
4444
void testFindTransactionByAccountIdGiveEmptyListForAccountIdWithZeroTransaction() throws HieroException {
4545
final AccountId accountId = AccountId.fromString("0.0.0");
46+
hieroTestUtils.waitForMirrorNodeRecords();
4647
final Page<TransactionInfo> page = transactionRepository.findByAccount(accountId);
4748
Assertions.assertNotNull(page);
4849

@@ -53,7 +54,7 @@ void testFindTransactionByAccountIdGiveEmptyListForAccountIdWithZeroTransaction(
5354
@Test
5455
void testFindTransactionByAccountIdAndType() throws HieroException {
5556
final Account account = accountClient.createAccount(1);
56-
57+
hieroTestUtils.waitForMirrorNodeRecords();
5758
final Page<TransactionInfo> page = transactionRepository.findByAccountAndType(account.accountId(),
5859
TransactionType.ACCOUNT_CREATE);
5960
Assertions.assertNotNull(page);
@@ -62,7 +63,7 @@ void testFindTransactionByAccountIdAndType() throws HieroException {
6263
@Test
6364
void testFindTransactionByAccountIdAndResult() throws HieroException {
6465
final Account account = accountClient.createAccount(1);
65-
66+
hieroTestUtils.waitForMirrorNodeRecords();
6667
final Page<TransactionInfo> page = transactionRepository.findByAccountAndResult(account.accountId(),
6768
Result.SUCCESS);
6869
Assertions.assertNotNull(page);
@@ -71,7 +72,7 @@ void testFindTransactionByAccountIdAndResult() throws HieroException {
7172
@Test
7273
void testFindTransactionByAccountIdAndBalanceModification() throws HieroException {
7374
final Account account = accountClient.createAccount(1);
74-
75+
hieroTestUtils.waitForMirrorNodeRecords();
7576
final Page<TransactionInfo> page = transactionRepository.findByAccountAndModification(account.accountId(),
7677
BalanceModification.DEBIT);
7778
Assertions.assertNotNull(page);

0 commit comments

Comments
 (0)