Add new methods to DaoStateService and DaoFacade.

Will be used later by BurningMan domain.

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2022-11-03 13:50:27 -05:00
parent 5c7a3308a7
commit ea5662f84d
No known key found for this signature in database
GPG Key ID: 02AA2BAE387C8307
2 changed files with 44 additions and 1 deletions

View File

@ -53,6 +53,7 @@ import bisq.core.dao.governance.proposal.reimbursement.ReimbursementConsensus;
import bisq.core.dao.governance.proposal.reimbursement.ReimbursementProposalFactory;
import bisq.core.dao.governance.proposal.removeAsset.RemoveAssetProposalFactory;
import bisq.core.dao.governance.proposal.role.RoleProposalFactory;
import bisq.core.dao.governance.proposal.storage.appendonly.ProposalPayload;
import bisq.core.dao.monitoring.DaoStateMonitoringService;
import bisq.core.dao.state.DaoStateListener;
import bisq.core.dao.state.DaoStateService;
@ -65,8 +66,10 @@ import bisq.core.dao.state.model.blockchain.TxOutputKey;
import bisq.core.dao.state.model.blockchain.TxType;
import bisq.core.dao.state.model.governance.Ballot;
import bisq.core.dao.state.model.governance.BondedRoleType;
import bisq.core.dao.state.model.governance.CompensationProposal;
import bisq.core.dao.state.model.governance.Cycle;
import bisq.core.dao.state.model.governance.DaoPhase;
import bisq.core.dao.state.model.governance.Issuance;
import bisq.core.dao.state.model.governance.IssuanceType;
import bisq.core.dao.state.model.governance.Proposal;
import bisq.core.dao.state.model.governance.Role;
@ -646,6 +649,24 @@ public class DaoFacade implements DaoSetupService {
return daoStateService.getIssuanceSetForType(issuanceType).size();
}
public Set<Issuance> getIssuanceSetForType(IssuanceType issuanceType) {
return daoStateService.getIssuanceSetForType(issuanceType);
}
public Map<TxOutputKey, Optional<String>> getAddressByOutputKeyMap() {
return daoStateService.getUnorderedTxOutputStream()
.collect(Collectors.toMap(BaseTxOutput::getKey, txOutput -> Optional.ofNullable(txOutput.getAddress())));
}
public Optional<CompensationProposal> findCompensationProposal(String txId) {
return proposalService.getProposalPayloads().stream()
.map(ProposalPayload::getProposal)
.filter(proposal -> txId.equals(proposal.getTxId()))
.filter(proposal -> proposal instanceof CompensationProposal)
.map(proposal -> (CompensationProposal) proposal)
.findAny();
}
public Set<Tx> getBurntFeeTxs() {
return daoStateService.getBurntFeeTxs();
}

View File

@ -201,6 +201,28 @@ public class DaoStateService implements DaoSetupService {
return getCycle(blockHeight).map(cycle -> cycle.getHeightOfFirstBlock());
}
public Optional<Cycle> getNextCycle(Cycle cycle) {
return getCycle(cycle.getHeightOfLastBlock() + 1);
}
public Optional<Cycle> getPreviousCycle(Cycle cycle) {
return getCycle(cycle.getHeightOfFirstBlock() - 1);
}
public Optional<Cycle> getPastCycle(Cycle cycle, int numPastCycles) {
Optional<Cycle> previous = Optional.empty();
Cycle current = cycle;
for (int i = 0; i < numPastCycles; i++) {
previous = getPreviousCycle(current);
if (previous.isPresent()) {
current = previous.get();
} else {
break;
}
}
return previous;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Block
@ -440,7 +462,7 @@ public class DaoStateService implements DaoSetupService {
// TxOutput
///////////////////////////////////////////////////////////////////////////////////////////
private Stream<TxOutput> getUnorderedTxOutputStream() {
public Stream<TxOutput> getUnorderedTxOutputStream() {
return getUnorderedTxStream()
.flatMap(tx -> tx.getTxOutputs().stream());
}