Add balance fields for DAO revenue with total burned BSQ and total distributed BTC/BSQ

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2022-12-15 20:41:50 -05:00 committed by Christoph Atteneder
parent 2be5d2fbd8
commit 109c200650
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
4 changed files with 61 additions and 1 deletions

View File

@ -353,6 +353,12 @@ public class BurningManPresentationService implements DaoStateListener {
return burningManNameByAddress;
}
public long getTotalAmountOfBurnedBsq() {
return getBurningManCandidatesByName().values().stream()
.mapToLong(BurningManCandidate::getAccumulatedBurnAmount)
.sum();
}
public String getGenesisTxId() {
return daoStateService.getGenesisTxId();
}

View File

@ -21,6 +21,7 @@ import bisq.core.dao.DaoSetupService;
import bisq.core.dao.burningman.BurningManPresentationService;
import bisq.core.dao.burningman.accounting.balance.BalanceEntry;
import bisq.core.dao.burningman.accounting.balance.BalanceModel;
import bisq.core.dao.burningman.accounting.balance.BaseBalanceEntry;
import bisq.core.dao.burningman.accounting.balance.ReceivedBtcBalanceEntry;
import bisq.core.dao.burningman.accounting.blockchain.AccountingBlock;
import bisq.core.dao.burningman.accounting.blockchain.AccountingTx;
@ -35,6 +36,9 @@ import bisq.core.util.AveragePriceUtil;
import bisq.common.UserThread;
import bisq.common.config.Config;
import bisq.common.util.DateUtil;
import bisq.common.util.MathUtils;
import org.bitcoinj.core.Coin;
import javax.inject.Inject;
import javax.inject.Singleton;
@ -168,6 +172,35 @@ public class BurningManAccountingService implements DaoSetupService {
return averageBsqPriceByMonth;
}
public long getTotalAmountOfDistributedBtc() {
return balanceModelByBurningManName.values().stream()
.flatMap(balanceModel -> balanceModel.getReceivedBtcBalanceEntries().stream())
.mapToLong(BaseBalanceEntry::getAmount)
.sum();
}
public long getTotalAmountOfDistributedBsq() {
Map<Date, Price> averageBsqPriceByMonth = getAverageBsqPriceByMonth();
return balanceModelByBurningManName.values().stream()
.flatMap(balanceModel -> balanceModel.getReceivedBtcBalanceEntries().stream())
.map(balanceEntry -> {
Date month = balanceEntry.getMonth();
Optional<Price> price = Optional.ofNullable(averageBsqPriceByMonth.get(month));
long receivedBtc = balanceEntry.getAmount();
Optional<Long> receivedBtcAsBsq;
if (price.isEmpty() || price.get().getValue() == 0) {
receivedBtcAsBsq = Optional.empty();
} else {
long volume = price.get().getVolumeByAmount(Coin.valueOf(receivedBtc)).getValue();
receivedBtcAsBsq = Optional.of(MathUtils.roundDoubleToLong(MathUtils.scaleDownByPowerOf10(volume, 6)));
}
return receivedBtcAsBsq;
})
.filter(Optional::isPresent)
.mapToLong(Optional::get)
.sum();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Delegates

View File

@ -2299,6 +2299,9 @@ dao.burningman.burnTarget.fromTo={0} - {1} BSQ
dao.burningman.filter=Filter burningman candidates
dao.burningman.toggle=Show only active burningmen
dao.burningman.contributorsComboBox.prompt=Select any of my contributors
dao.burningman.daoBalance=Balance for DAO
dao.burningman.daoBalanceTotalBurned=Total amount of burned BSQ
dao.burningman.daoBalanceTotalDistributed=Total amount of distributed BTC / BSQ
dao.burningman.selectedContributor=Selected contributor
dao.burningman.selectedContributorName=Contributor name
dao.burningman.selectedContributorAddress=Receiver address

View File

@ -130,7 +130,7 @@ public class BurningManView extends ActivatableView<ScrollPane, Void> implements
private Button burnButton, exportBalanceEntriesButton;
private TitledGroupBg burnOutputsTitledGroupBg, compensationsTitledGroupBg, selectedContributorTitledGroupBg;
private AutoTooltipSlideToggleButton showOnlyActiveBurningmenToggle, showMonthlyBalanceEntryToggle;
private TextField expectedRevenueField, selectedContributorNameField, selectedContributorAddressField, burnTargetField;
private TextField expectedRevenueField, daoBalanceTotalBurnedField, daoBalanceTotalDistributedField, selectedContributorNameField, selectedContributorAddressField, burnTargetField;
private ToggleGroup balanceEntryToggleGroup;
private HBox balanceEntryHBox;
private VBox selectedContributorNameBox, selectedContributorAddressBox;
@ -312,6 +312,20 @@ public class BurningManView extends ActivatableView<ScrollPane, Void> implements
HBox.setMargin(showOnlyActiveBurningmenToggle, new Insets(-21, 0, 0, 0));
hBox.getChildren().add(2, showOnlyActiveBurningmenToggle);
// DAO balance
addTitledGroupBg(gridPane, ++gridRow, 4,
Res.get("dao.burningman.daoBalance"), Layout.COMPACT_GROUP_DISTANCE);
daoBalanceTotalBurnedField = addCompactTopLabelTextField(gridPane, ++gridRow,
Res.get("dao.burningman.daoBalanceTotalBurned"), "",
Layout.COMPACT_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE).second;
Tuple3<Label, TextField, VBox> daoBalanceTotalDistributedTuple = addCompactTopLabelTextField(gridPane, gridRow,
Res.get("dao.burningman.daoBalanceTotalDistributed"), "",
Layout.COMPACT_GROUP_DISTANCE + Layout.FLOATING_LABEL_DISTANCE);
daoBalanceTotalDistributedField = daoBalanceTotalDistributedTuple.second;
VBox daoBalanceTotalDistributedBox = daoBalanceTotalDistributedTuple.third;
GridPane.setColumnSpan(daoBalanceTotalDistributedBox, 2);
GridPane.setColumnIndex(daoBalanceTotalDistributedBox, 1);
// Selected contributor
selectedContributorTitledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 4,
Res.get("dao.burningman.selectedContributor"), Layout.COMPACT_GROUP_DISTANCE);
@ -569,6 +583,10 @@ public class BurningManView extends ActivatableView<ScrollPane, Void> implements
.sorted(Comparator.comparing(BurningManListItem::getName))
.collect(Collectors.toList());
contributorComboBox.setItems(FXCollections.observableArrayList(myBurningManListItems));
daoBalanceTotalBurnedField.setText(bsqFormatter.formatCoinWithCode(burningManPresentationService.getTotalAmountOfBurnedBsq()));
daoBalanceTotalDistributedField.setText(btcFormatter.formatCoinWithCode(burningManAccountingService.getTotalAmountOfDistributedBtc()) + " / " +
bsqFormatter.formatCoinWithCode(burningManAccountingService.getTotalAmountOfDistributedBsq()));
}
}