Refactor code for assigning address for better to make it more clear when we use the custom address and when the change address.

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2023-05-17 12:53:59 +07:00
parent 658a01e5ae
commit 6a649416c2
No known key found for this signature in database
GPG Key ID: 02AA2BAE387C8307

View File

@ -135,26 +135,32 @@ public class BurningManService {
BurningManCandidate candidate = burningManCandidatesByName.get(name);
// Issuance
compensationProposal.getBurningManReceiverAddress()
.or(() -> daoStateService.getTx(compensationProposal.getTxId())
.map(this::getAddressFromCompensationRequest))
.ifPresent(address -> {
int issuanceHeight = issuance.getChainHeight();
long issuanceAmount = getIssuanceAmountForCompensationRequest(issuance);
int cycleIndex = cyclesInDaoStateService.getCycleIndexAtChainHeight(issuanceHeight);
if (isValidCompensationRequest(name, cycleIndex, issuanceAmount)) {
long decayedIssuanceAmount = getDecayedCompensationAmount(issuanceAmount, issuanceHeight, chainHeight);
long issuanceDate = daoStateService.getBlockTime(issuanceHeight);
candidate.addCompensationModel(CompensationModel.fromCompensationRequest(address,
issuanceAmount,
decayedIssuanceAmount,
issuanceHeight,
issuance.getTxId(),
issuanceDate,
cycleIndex));
}
});
Optional<String> customAddress = compensationProposal.getBurningManReceiverAddress();
boolean isCustomAddress = customAddress.isPresent();
Optional<String> receiverAddress;
if (isCustomAddress) {
receiverAddress = customAddress;
} else {
// We take change address from compensation request
receiverAddress = daoStateService.getTx(compensationProposal.getTxId())
.map(this::getAddressFromCompensationRequest);
}
if (receiverAddress.isPresent()) {
int issuanceHeight = issuance.getChainHeight();
long issuanceAmount = getIssuanceAmountForCompensationRequest(issuance);
int cycleIndex = cyclesInDaoStateService.getCycleIndexAtChainHeight(issuanceHeight);
if (isValidCompensationRequest(name, cycleIndex, issuanceAmount)) {
long decayedIssuanceAmount = getDecayedCompensationAmount(issuanceAmount, issuanceHeight, chainHeight);
long issuanceDate = daoStateService.getBlockTime(issuanceHeight);
candidate.addCompensationModel(CompensationModel.fromCompensationRequest(receiverAddress.get(),
issuanceAmount,
decayedIssuanceAmount,
issuanceHeight,
issuance.getTxId(),
issuanceDate,
cycleIndex));
}
}
addBurnOutputModel(chainHeight, proofOfBurnOpReturnTxOutputByHash, name, candidate);
});
}
@ -211,7 +217,7 @@ public class BurningManService {
Set<BurningManCandidate> getActiveBurningManCandidates(int chainHeight) {
return getBurningManCandidatesByName(chainHeight).values().stream()
.filter(burningManCandidate -> burningManCandidate.getCappedBurnAmountShare() > 0)
.filter(candidate -> candidate.getMostRecentAddress().isPresent())
.filter(candidate -> candidate.getReceiverAddress().isPresent())
.collect(Collectors.toSet());
}