From e397c97f1ead971a4b41bdf6d97d21ccf9bcc52e Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 6 Jun 2024 20:56:57 +0700 Subject: [PATCH] Improve logs. Add ToString annotation Signed-off-by: HenrikJannsen --- .../java/bisq/daonode/dto/BondedReputationDto.java | 2 ++ .../main/java/bisq/daonode/dto/ProofOfBurnDto.java | 2 ++ .../java/bisq/daonode/endpoints/AccountAgeApi.java | 9 ++++++++- .../bisq/daonode/endpoints/BondedReputationApi.java | 5 ++++- .../java/bisq/daonode/endpoints/ProofOfBurnApi.java | 10 +++++++--- .../bisq/daonode/endpoints/SignedWitnessApi.java | 12 ++++++++---- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/restapi/src/main/java/bisq/daonode/dto/BondedReputationDto.java b/restapi/src/main/java/bisq/daonode/dto/BondedReputationDto.java index 0cc3d737f44..e79883fb75d 100644 --- a/restapi/src/main/java/bisq/daonode/dto/BondedReputationDto.java +++ b/restapi/src/main/java/bisq/daonode/dto/BondedReputationDto.java @@ -18,6 +18,7 @@ package bisq.daonode.dto; import lombok.Getter; +import lombok.ToString; import lombok.extern.slf4j.Slf4j; @@ -30,6 +31,7 @@ */ @Getter @Slf4j +@ToString @Schema(title = "BondedReputation") public class BondedReputationDto { private final long amount; diff --git a/restapi/src/main/java/bisq/daonode/dto/ProofOfBurnDto.java b/restapi/src/main/java/bisq/daonode/dto/ProofOfBurnDto.java index aa16b103961..64f45eabadf 100644 --- a/restapi/src/main/java/bisq/daonode/dto/ProofOfBurnDto.java +++ b/restapi/src/main/java/bisq/daonode/dto/ProofOfBurnDto.java @@ -18,6 +18,7 @@ package bisq.daonode.dto; import lombok.Getter; +import lombok.ToString; @@ -28,6 +29,7 @@ * Need to be in sync with the Bisq 2 ProofOfBurnDto class. */ @Getter +@ToString @Schema(title = "ProofOfBurn") public class ProofOfBurnDto { private final long amount; diff --git a/restapi/src/main/java/bisq/daonode/endpoints/AccountAgeApi.java b/restapi/src/main/java/bisq/daonode/endpoints/AccountAgeApi.java index 4bb7ffcd40f..6871a580146 100644 --- a/restapi/src/main/java/bisq/daonode/endpoints/AccountAgeApi.java +++ b/restapi/src/main/java/bisq/daonode/endpoints/AccountAgeApi.java @@ -18,6 +18,9 @@ package bisq.daonode.endpoints; import bisq.core.account.witness.AccountAgeWitness; +import bisq.core.account.witness.AccountAgeWitnessService; + +import java.util.Date; import lombok.extern.slf4j.Slf4j; @@ -54,9 +57,11 @@ public class AccountAgeApi { private static final String DESC_HASH = "The hash of the account age witness as hex string"; private final RestApi restApi; + private final AccountAgeWitnessService accountAgeWitnessService; public AccountAgeApi(@Context Application application) { restApi = ((RestApiMain) application).getRestApi(); + accountAgeWitnessService = checkNotNull(restApi.getAccountAgeWitnessService()); } @Operation(description = "Request the account age date") @@ -69,8 +74,10 @@ public AccountAgeApi(@Context Application application) { public Long getDate(@Parameter(description = DESC_HASH) @PathParam("hash") String hash) { - return checkNotNull(restApi.getAccountAgeWitnessService()).getWitnessByHashAsHex(hash) + long result = accountAgeWitnessService.getWitnessByHashAsHex(hash) .map(AccountAgeWitness::getDate) .orElse(-1L); + log.info("Account age for hash {}: {} ({})", hash, result, new Date(result)); + return result; } } diff --git a/restapi/src/main/java/bisq/daonode/endpoints/BondedReputationApi.java b/restapi/src/main/java/bisq/daonode/endpoints/BondedReputationApi.java index 4a753021cbe..178eb188ef2 100644 --- a/restapi/src/main/java/bisq/daonode/endpoints/BondedReputationApi.java +++ b/restapi/src/main/java/bisq/daonode/endpoints/BondedReputationApi.java @@ -80,7 +80,7 @@ public List getBondedReputation(@Parameter(description = DE @PathParam("block-height") int fromBlockHeight) { // We only consider lock time with at least 50 000 blocks as valid - return bondedReputationRepository.getActiveBonds().stream() + List result = bondedReputationRepository.getActiveBonds().stream() .filter(bondedReputation -> bondedReputation.getLockTime() >= 50_000) .map(bondedReputation -> { Optional optionalTx = daoStateService.getTx(bondedReputation.getLockupTxId()); @@ -102,5 +102,8 @@ public List getBondedReputation(@Parameter(description = DE }) .filter(Objects::nonNull) .collect(Collectors.toList()); + + log.info("BondedReputation result list from block height {}: {}", fromBlockHeight, result); + return result; } } diff --git a/restapi/src/main/java/bisq/daonode/endpoints/ProofOfBurnApi.java b/restapi/src/main/java/bisq/daonode/endpoints/ProofOfBurnApi.java index 6658d3a48c6..98df0694cca 100644 --- a/restapi/src/main/java/bisq/daonode/endpoints/ProofOfBurnApi.java +++ b/restapi/src/main/java/bisq/daonode/endpoints/ProofOfBurnApi.java @@ -18,6 +18,7 @@ package bisq.daonode.endpoints; import bisq.core.dao.governance.proofofburn.ProofOfBurnService; +import bisq.core.dao.state.DaoStateService; import bisq.common.util.Hex; @@ -58,10 +59,11 @@ @Tag(name = "Proof of burn API") public class ProofOfBurnApi { private static final String DESC_BLOCK_HEIGHT = "The block height from which we request the proof of burn data"; - private final RestApi restApi; + private final DaoStateService daoStateService; public ProofOfBurnApi(@Context Application application) { - restApi = ((RestApiMain) application).getRestApi(); + RestApi restApi = ((RestApiMain) application).getRestApi(); + daoStateService = checkNotNull(restApi.getDaoStateService()); } @Operation(description = "Request the proof of burn data") @@ -74,12 +76,14 @@ public ProofOfBurnApi(@Context Application application) { public List getProofOfBurn(@Parameter(description = DESC_BLOCK_HEIGHT) @PathParam("block-height") int fromBlockHeight) { - return checkNotNull(restApi.getDaoStateService()).getProofOfBurnTxs().stream() + List result = daoStateService.getProofOfBurnTxs().stream() .filter(tx -> tx.getBlockHeight() >= fromBlockHeight) .map(tx -> new ProofOfBurnDto(tx.getBurntBsq(), tx.getTime(), Hex.encode(ProofOfBurnService.getHashFromOpReturnData(tx)), tx.getBlockHeight())) .collect(Collectors.toList()); + log.info("ProofOfBurn result list from block height {}: {}", fromBlockHeight, result); + return result; } } diff --git a/restapi/src/main/java/bisq/daonode/endpoints/SignedWitnessApi.java b/restapi/src/main/java/bisq/daonode/endpoints/SignedWitnessApi.java index 0750600b030..5b38f22d807 100644 --- a/restapi/src/main/java/bisq/daonode/endpoints/SignedWitnessApi.java +++ b/restapi/src/main/java/bisq/daonode/endpoints/SignedWitnessApi.java @@ -19,6 +19,8 @@ import bisq.core.account.witness.AccountAgeWitnessService; +import java.util.Date; + import lombok.extern.slf4j.Slf4j; import static com.google.common.base.Preconditions.checkNotNull; @@ -53,10 +55,11 @@ @Tag(name = "Signed witness API") public class SignedWitnessApi { private static final String DESC_HASH = "The hash of the signed account age witness as hex string"; - private final RestApi restApi; + private final AccountAgeWitnessService accountAgeWitnessService; public SignedWitnessApi(@Context Application application) { - restApi = ((RestApiMain) application).getRestApi(); + RestApi restApi = ((RestApiMain) application).getRestApi(); + accountAgeWitnessService = checkNotNull(restApi.getAccountAgeWitnessService()); } @Operation(description = "Request the signed witness date") @@ -69,9 +72,10 @@ public SignedWitnessApi(@Context Application application) { public Long getDate(@Parameter(description = DESC_HASH) @PathParam("hash") String hash) { - AccountAgeWitnessService accountAgeWitnessService = checkNotNull(restApi.getAccountAgeWitnessService()); - return accountAgeWitnessService.getWitnessByHashAsHex(hash) + long result = accountAgeWitnessService.getWitnessByHashAsHex(hash) .map(accountAgeWitnessService::getWitnessSignDate) .orElse(-1L); + log.info("SignedWitness sign date for hash {}: {} ({})", hash, result, new Date(result)); + return result; } }