Skip to content

Commit

Permalink
Improve logs. Add ToString annotation
Browse files Browse the repository at this point in the history
Signed-off-by: HenrikJannsen <[email protected]>
  • Loading branch information
HenrikJannsen committed Jun 6, 2024
1 parent b2c3a61 commit e397c97
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.daonode.dto;

import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;


Expand All @@ -30,6 +31,7 @@
*/
@Getter
@Slf4j
@ToString
@Schema(title = "BondedReputation")
public class BondedReputationDto {
private final long amount;
Expand Down
2 changes: 2 additions & 0 deletions restapi/src/main/java/bisq/daonode/dto/ProofOfBurnDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.daonode.dto;

import lombok.Getter;
import lombok.ToString;



Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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")
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public List<BondedReputationDto> 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<BondedReputationDto> result = bondedReputationRepository.getActiveBonds().stream()
.filter(bondedReputation -> bondedReputation.getLockTime() >= 50_000)
.map(bondedReputation -> {
Optional<Tx> optionalTx = daoStateService.getTx(bondedReputation.getLockupTxId());
Expand All @@ -102,5 +102,8 @@ public List<BondedReputationDto> getBondedReputation(@Parameter(description = DE
})
.filter(Objects::nonNull)
.collect(Collectors.toList());

log.info("BondedReputation result list from block height {}: {}", fromBlockHeight, result);
return result;
}
}
10 changes: 7 additions & 3 deletions restapi/src/main/java/bisq/daonode/endpoints/ProofOfBurnApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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")
Expand All @@ -74,12 +76,14 @@ public ProofOfBurnApi(@Context Application application) {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -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;
}
}

0 comments on commit e397c97

Please sign in to comment.