Improve logs. Add ToString annotation

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2024-06-06 20:56:57 +07:00
parent e4cdfa731a
commit cb25660b68
No known key found for this signature in database
GPG Key ID: 02AA2BAE387C8307
6 changed files with 31 additions and 9 deletions

View File

@ -18,6 +18,7 @@
package bisq.daonode.dto;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
@ -30,6 +31,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
*/
@Getter
@Slf4j
@ToString
@Schema(title = "BondedReputation")
public class BondedReputationDto {
private final long amount;

View File

@ -18,6 +18,7 @@
package bisq.daonode.dto;
import lombok.Getter;
import lombok.ToString;
@ -28,6 +29,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
* Need to be in sync with the Bisq 2 ProofOfBurnDto class.
*/
@Getter
@ToString
@Schema(title = "ProofOfBurn")
public class ProofOfBurnDto {
private final long amount;

View File

@ -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 @@ import jakarta.ws.rs.core.MediaType;
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 class AccountAgeApi {
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;
}
}

View File

@ -80,7 +80,7 @@ public class BondedReputationApi {
@PathParam("block-height")
int fromBlockHeight) {
// We only consider lock time with at least 50 000 blocks as valid
return bondedReputationRepository.getActiveBonds().stream()
List<BondedReputationDto> result = bondedReputationRepository.getActiveBonds().stream()
.filter(bondedReputation -> bondedReputation.getLockTime() >= 50_000)
.map(bondedReputation -> {
Optional<Tx> optionalTx = daoStateService.getTx(bondedReputation.getLockupTxId());
@ -102,5 +102,8 @@ public class BondedReputationApi {
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
log.info("BondedReputation result list from block height {}: {}", fromBlockHeight, result);
return result;
}
}

View File

@ -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 @@ import jakarta.ws.rs.core.MediaType;
@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 class ProofOfBurnApi {
public List<ProofOfBurnDto> getProofOfBurn(@Parameter(description = DESC_BLOCK_HEIGHT)
@PathParam("block-height")
int fromBlockHeight) {
return checkNotNull(restApi.getDaoStateService()).getProofOfBurnTxs().stream()
List<ProofOfBurnDto> 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;
}
}

View File

@ -19,6 +19,8 @@ package bisq.daonode.endpoints;
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 @@ import jakarta.ws.rs.core.MediaType;
@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 class SignedWitnessApi {
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;
}
}