From 5fb1167a28cabb4afdea0af63c14c1a17e2f7c4e Mon Sep 17 00:00:00 2001 From: xyzmaker123 Date: Mon, 14 Mar 2022 17:24:08 +0100 Subject: [PATCH 1/5] Show changes in BSQ Supply over time --- .../bisq/core/dao/state/DaoStateService.java | 40 +++++++++++++++++++ .../resources/i18n/displayStrings.properties | 1 + .../components/chart/ChartDataModel.java | 1 + .../desktop/components/chart/ChartView.java | 20 +++++++++- .../economy/supply/dao/DaoChartDataModel.java | 24 ++++++++++- .../dao/economy/supply/dao/DaoChartView.java | 25 +++++++++++- .../economy/supply/dao/DaoChartViewModel.java | 4 ++ 7 files changed, 112 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/state/DaoStateService.java b/core/src/main/java/bisq/core/dao/state/DaoStateService.java index 9204215a98e..c10a4253bc9 100644 --- a/core/src/main/java/bisq/core/dao/state/DaoStateService.java +++ b/core/src/main/java/bisq/core/dao/state/DaoStateService.java @@ -39,6 +39,8 @@ import bisq.core.util.ParsingUtils; import bisq.core.util.coin.BsqFormatter; +import bisq.common.util.Tuple2; + import org.bitcoinj.core.Coin; import javax.inject.Inject; @@ -1044,6 +1046,44 @@ public Set getProofOfBurnOpReturnTxOutputs() { return getTxOutputsByTxOutputType(TxOutputType.PROOF_OF_BURN_OP_RETURN_OUTPUT); } + public Set> getTotalBsqSupply() { + return new HashSet<>() {{ + add(new Tuple2<>(1555340856L, 372540100L)); // Cycle 01 - 15 APR 2019 + add(new Tuple2<>(1558083590L, 374541600L)); // Cycle 02 - 17 MAY 2019 + add(new Tuple2<>(1560771266L, 375464400L)); // Cycle 03 - 17 JUN 2019 + add(new Tuple2<>(1563347672L, 374153300L)); // Cycle 04 - 17 JUL 2019 + add(new Tuple2<>(1566009595L, 378733200L)); // Cycle 05 - 16 AUG 2019 + add(new Tuple2<>(1568643566L, 385347900L)); // Cycle 06 - 16 SEP 2019 + add(new Tuple2<>(1571349571L, 391167400L)); // Cycle 07 - 17 OCT 2019 + add(new Tuple2<>(1574180991L, 398324900L)); // Cycle 08 - 19 NOV 2019 + add(new Tuple2<>(1576966522L, 394719900L)); // Cycle 09 - 21 DEC 2019 + add(new Tuple2<>(1579613568L, 397643900L)); // Cycle 10 - 21 JAN 2020 + add(new Tuple2<>(1582399054L, 401189100L)); // Cycle 11 - 22 FEB 2020 + add(new Tuple2<>(1585342220L, 403141900L)); // Cycle 12 - 27 MAR 2020 + add(new Tuple2<>(1588025030L, 399991400L)); // Cycle 13 + add(new Tuple2<>(1591004931L, 411136400L)); // Cycle 14 + add(new Tuple2<>(1593654027L, 420908500L)); // Cycle 15 + add(new Tuple2<>(1596407074L, 421255800L)); // Cycle 16 + add(new Tuple2<>(1599175867L, 430737100L)); // Cycle 17 + add(new Tuple2<>(1601861442L, 429305600L)); // Cycle 18 + add(new Tuple2<>(1604845863L, 431446100L)); // Cycle 19 - 8 NOV 2020 + add(new Tuple2<>(1610233200L, 422663200L)); // Cycle 20 + add(new Tuple2<>(1612911600L, 449935500L)); // Cycle 21 + add(new Tuple2<>(1615762800L, 446547000L)); // Cycle 22 + add(new Tuple2<>(1618437600L, 441126800L)); // Cycle 23 + add(new Tuple2<>(1621288800L, 442629900L)); // Cycle 24 + add(new Tuple2<>(1624572000L, 434999300L)); // Cycle 25 + add(new Tuple2<>(1627596000L, 437237400L)); // Cycle 26 + add(new Tuple2<>(1630188000L, 431897700L)); // Cycle 27 + add(new Tuple2<>(1632952800L, 433282600L)); // Cycle 28 + add(new Tuple2<>(1635544800L, 431026400L)); // Cycle 29 - 29 SEP 2021 + add(new Tuple2<>(1638399600L, 424954400L)); // Cycle 30 + add(new Tuple2<>(1641078000L, 438560500L)); // Cycle 31 + add(new Tuple2<>(1643756400L, 433806200L)); // Cycle 32 + add(new Tuple2<>(1646555748L, 431667800L)); // Cycle 33 + }}; + } + /////////////////////////////////////////////////////////////////////////////////////////// // Listeners diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index 7440d9716bb..482aef0fa32 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -2600,6 +2600,7 @@ dao.factsAndFigures.supply.compRequestIssueAmount=BSQ issued for compensation re dao.factsAndFigures.supply.reimbursementAmount=BSQ issued for reimbursement requests dao.factsAndFigures.supply.totalIssued=Total issued BSQ dao.factsAndFigures.supply.totalBurned=Total burned BSQ +dao.factsAndFigures.supply.totalBsqSupply=Total BSQ supply dao.factsAndFigures.supply.chart.tradeFee.toolTip={0}\n{1} dao.factsAndFigures.supply.burnt=BSQ burnt diff --git a/desktop/src/main/java/bisq/desktop/components/chart/ChartDataModel.java b/desktop/src/main/java/bisq/desktop/components/chart/ChartDataModel.java index 610ed63b03c..0b3399f39e3 100644 --- a/desktop/src/main/java/bisq/desktop/components/chart/ChartDataModel.java +++ b/desktop/src/main/java/bisq/desktop/components/chart/ChartDataModel.java @@ -22,6 +22,7 @@ import java.time.Instant; import java.time.temporal.TemporalAdjuster; +import java.util.Comparator; import java.util.Map; import java.util.function.BinaryOperator; import java.util.function.Predicate; diff --git a/desktop/src/main/java/bisq/desktop/components/chart/ChartView.java b/desktop/src/main/java/bisq/desktop/components/chart/ChartView.java index bcc114bf9b5..2348e78f2ec 100644 --- a/desktop/src/main/java/bisq/desktop/components/chart/ChartView.java +++ b/desktop/src/main/java/bisq/desktop/components/chart/ChartView.java @@ -87,7 +87,7 @@ public abstract class ChartView chart; - private HBox timelineLabels, legendBox2; + private HBox timelineLabels, legendBox2, legendBox3; private final ToggleGroup timeIntervalToggleGroup = new ToggleGroup(); protected final Set> activeSeries = new HashSet<>(); @@ -157,6 +157,11 @@ public void initialize() { legendBox2 = initLegendsAndGetLegendBox(seriesForLegend2); } + Collection> seriesForLegend3 = getSeriesForLegend3(); + if (seriesForLegend3 != null && !seriesForLegend3.isEmpty()) { + legendBox3 = initLegendsAndGetLegendBox(seriesForLegend3); + } + // Set active series/legends defineAndAddActiveSeries(); @@ -176,6 +181,9 @@ public void initialize() { if (legendBox2 != null) { VBox.setMargin(legendBox2, new Insets(-20, rightPadding, 0, paddingLeft)); } + if (legendBox3 != null) { + VBox.setMargin(legendBox3, new Insets(-20, rightPadding, 0, paddingLeft)); + } if (model.getDividerPositions()[0] == 0 && model.getDividerPositions()[1] == 1) { resetTimeNavigation(); @@ -192,6 +200,10 @@ public void initialize() { VBox.setMargin(legendBox2, new Insets(-20, paddingRight, 0, paddingLeft)); timelineNavigationBox.getChildren().add(legendBox2); } + if (legendBox3 != null) { + VBox.setMargin(legendBox3, new Insets(-20, paddingRight, 0, paddingLeft)); + timelineNavigationBox.getChildren().add(legendBox3); + } root.getChildren().addAll(timeIntervalBox, chart, timelineNavigationBox); // Listeners @@ -241,6 +253,7 @@ public void activate() { addLegendToggleActionHandlers(getSeriesForLegend1()); addLegendToggleActionHandlers(getSeriesForLegend2()); + addLegendToggleActionHandlers(getSeriesForLegend3()); addActionHandlersToDividers(); } @@ -258,6 +271,7 @@ public void deactivate() { removeLegendToggleActionHandlers(getSeriesForLegend1()); removeLegendToggleActionHandlers(getSeriesForLegend2()); + removeLegendToggleActionHandlers(getSeriesForLegend3()); removeActionHandlersToDividers(); // clear data, reset states. We keep timeInterval state though @@ -541,6 +555,10 @@ protected Collection> getSeriesForLegend2() { return null; } + protected Collection> getSeriesForLegend3() { + return null; + } + protected abstract void defineAndAddActiveSeries(); protected void activateSeries(XYChart.Series series) { diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java index 52b90f72bab..58861e1360b 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java @@ -24,6 +24,8 @@ import bisq.core.dao.state.model.governance.Issuance; import bisq.core.dao.state.model.governance.IssuanceType; +import bisq.common.util.Tuple2; + import javax.inject.Inject; import javax.inject.Singleton; @@ -45,7 +47,7 @@ public class DaoChartDataModel extends ChartDataModel { private final DaoStateService daoStateService; private final Function blockTimeOfIssuanceFunction; - private Map totalIssuedByInterval, compensationByInterval, reimbursementByInterval, + private Map totalSupplyByInterval, totalIssuedByInterval, compensationByInterval, reimbursementByInterval, totalBurnedByInterval, bsqTradeFeeByInterval, proofOfBurnByInterval; @@ -68,6 +70,7 @@ public DaoChartDataModel(DaoStateService daoStateService) { @Override protected void invalidateCache() { + totalSupplyByInterval = null; totalIssuedByInterval = null; compensationByInterval = null; reimbursementByInterval = null; @@ -111,6 +114,19 @@ long getProofOfBurnAmount() { // Data for chart /////////////////////////////////////////////////////////////////////////////////////////// + Map getTotalSupplyByInterval() { + if (totalSupplyByInterval != null) { + return totalSupplyByInterval; + } + + totalSupplyByInterval = getTotalBsqSupplyByInterval( + daoStateService.getTotalBsqSupply(), + getDateFilter() + ); + + return totalSupplyByInterval; + } + Map getTotalIssuedByInterval() { if (totalIssuedByInterval != null) { return totalIssuedByInterval; @@ -179,6 +195,12 @@ Map getProofOfBurnByInterval() { // Aggregated collection data by interval /////////////////////////////////////////////////////////////////////////////////////////// + private Map getTotalBsqSupplyByInterval(Set> bsqSupply, Predicate dateFilter) { + return bsqSupply.stream() + .filter(i -> dateFilter.test(i.first)) + .collect(Collectors.toMap(i -> i.first, i -> i.second)); + } + private Map getIssuedBsqByInterval(Set issuanceSet, Predicate dateFilter) { return issuanceSet.stream() .collect(Collectors.groupingBy(issuance -> diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartView.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartView.java index 200777090f9..75894fafbe4 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartView.java @@ -46,7 +46,7 @@ public class DaoChartView extends ChartView { private final LongProperty proofOfBurnAmountProperty = new SimpleLongProperty(); private XYChart.Series seriesBsqTradeFee, seriesProofOfBurn, seriesCompensation, - seriesReimbursement, seriesTotalIssued, seriesTotalBurned; + seriesReimbursement, seriesTotalSupply, seriesTotalIssued, seriesTotalBurned; @Inject @@ -90,6 +90,11 @@ protected Collection> getSeriesForLegend2() { return List.of(seriesTotalBurned, seriesBsqTradeFee, seriesProofOfBurn); } + @Override + protected Collection> getSeriesForLegend3() { + return List.of(seriesTotalSupply); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Timeline navigation @@ -130,6 +135,10 @@ protected void createSeries() { seriesProofOfBurn = new XYChart.Series<>(); seriesProofOfBurn.setName(Res.get("dao.factsAndFigures.supply.proofOfBurn")); seriesIndexMap.put(getSeriesId(seriesProofOfBurn), 5); + + seriesTotalSupply = new XYChart.Series<>(); + seriesTotalSupply.setName(Res.get("dao.factsAndFigures.supply.totalBsqSupply")); + seriesIndexMap.put(getSeriesId(seriesTotalSupply), 6); } @Override @@ -176,6 +185,11 @@ protected CompletableFuture applyData() { allFutures.add(task6Done); applyProofOfBurn(task6Done); } + if (activeSeries.contains(seriesTotalSupply)) { + CompletableFuture task6ADone = new CompletableFuture<>(); + allFutures.add(task6ADone); + applyTotalSupply(task6ADone); + } CompletableFuture task7Done = new CompletableFuture<>(); allFutures.add(task7Done); @@ -216,6 +230,15 @@ protected CompletableFuture applyData() { return CompletableFutureUtils.allOf(allFutures).thenApply(e -> true); } + private void applyTotalSupply(CompletableFuture completeFuture) { + model.getTotalSupplyChartData() + .whenComplete((data, t) -> + mapToUserThread(() -> { + seriesTotalSupply.getData().setAll(data); + completeFuture.complete(true); + })); + } + private void applyTotalIssued(CompletableFuture completeFuture) { model.getTotalIssuedChartData() .whenComplete((data, t) -> diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartViewModel.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartViewModel.java index 70429d33e25..44af8d106cc 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartViewModel.java @@ -54,6 +54,10 @@ public DaoChartViewModel(DaoChartDataModel dataModel, BsqFormatter bsqFormatter) // Chart data /////////////////////////////////////////////////////////////////////////////////////////// + CompletableFuture>> getTotalSupplyChartData() { + return CompletableFuture.supplyAsync(() -> toChartData(dataModel.getTotalSupplyByInterval())); + } + CompletableFuture>> getTotalIssuedChartData() { return CompletableFuture.supplyAsync(() -> toChartData(dataModel.getTotalIssuedByInterval())); } From 219b408b6a480710bdd5db842ffdc748133c86b4 Mon Sep 17 00:00:00 2001 From: xyzmaker123 Date: Tue, 22 Mar 2022 10:25:43 +0100 Subject: [PATCH 2/5] Show changes in BSQ Supply over time - dynamic calculation --- .../bisq/core/dao/state/DaoStateService.java | 56 ++++++------------- .../model/governance/BsqSupplyChange.java | 13 +++++ .../economy/supply/dao/DaoChartDataModel.java | 31 +++++++--- 3 files changed, 54 insertions(+), 46 deletions(-) create mode 100644 core/src/main/java/bisq/core/dao/state/model/governance/BsqSupplyChange.java diff --git a/core/src/main/java/bisq/core/dao/state/DaoStateService.java b/core/src/main/java/bisq/core/dao/state/DaoStateService.java index c10a4253bc9..4fd6e1e7fc5 100644 --- a/core/src/main/java/bisq/core/dao/state/DaoStateService.java +++ b/core/src/main/java/bisq/core/dao/state/DaoStateService.java @@ -30,6 +30,7 @@ import bisq.core.dao.state.model.blockchain.TxOutputKey; import bisq.core.dao.state.model.blockchain.TxOutputType; import bisq.core.dao.state.model.blockchain.TxType; +import bisq.core.dao.state.model.governance.BsqSupplyChange; import bisq.core.dao.state.model.governance.Cycle; import bisq.core.dao.state.model.governance.DecryptedBallotsWithMerits; import bisq.core.dao.state.model.governance.EvaluatedProposal; @@ -39,13 +40,12 @@ import bisq.core.util.ParsingUtils; import bisq.core.util.coin.BsqFormatter; -import bisq.common.util.Tuple2; - import org.bitcoinj.core.Coin; import javax.inject.Inject; import java.util.ArrayList; +import java.util.Collection; import java.util.Comparator; import java.util.HashSet; import java.util.LinkedList; @@ -618,8 +618,12 @@ public void addIssuance(Issuance issuance) { daoState.getIssuanceMap().put(issuance.getTxId(), issuance); } + public Collection getIssuanceItems() { + return daoState.getIssuanceMap().values(); + } + public Set getIssuanceSetForType(IssuanceType issuanceType) { - return daoState.getIssuanceMap().values().stream() + return getIssuanceItems().stream() .filter(issuance -> issuance.getIssuanceType() == issuanceType) .collect(Collectors.toSet()); } @@ -1046,42 +1050,16 @@ public Set getProofOfBurnOpReturnTxOutputs() { return getTxOutputsByTxOutputType(TxOutputType.PROOF_OF_BURN_OP_RETURN_OUTPUT); } - public Set> getTotalBsqSupply() { - return new HashSet<>() {{ - add(new Tuple2<>(1555340856L, 372540100L)); // Cycle 01 - 15 APR 2019 - add(new Tuple2<>(1558083590L, 374541600L)); // Cycle 02 - 17 MAY 2019 - add(new Tuple2<>(1560771266L, 375464400L)); // Cycle 03 - 17 JUN 2019 - add(new Tuple2<>(1563347672L, 374153300L)); // Cycle 04 - 17 JUL 2019 - add(new Tuple2<>(1566009595L, 378733200L)); // Cycle 05 - 16 AUG 2019 - add(new Tuple2<>(1568643566L, 385347900L)); // Cycle 06 - 16 SEP 2019 - add(new Tuple2<>(1571349571L, 391167400L)); // Cycle 07 - 17 OCT 2019 - add(new Tuple2<>(1574180991L, 398324900L)); // Cycle 08 - 19 NOV 2019 - add(new Tuple2<>(1576966522L, 394719900L)); // Cycle 09 - 21 DEC 2019 - add(new Tuple2<>(1579613568L, 397643900L)); // Cycle 10 - 21 JAN 2020 - add(new Tuple2<>(1582399054L, 401189100L)); // Cycle 11 - 22 FEB 2020 - add(new Tuple2<>(1585342220L, 403141900L)); // Cycle 12 - 27 MAR 2020 - add(new Tuple2<>(1588025030L, 399991400L)); // Cycle 13 - add(new Tuple2<>(1591004931L, 411136400L)); // Cycle 14 - add(new Tuple2<>(1593654027L, 420908500L)); // Cycle 15 - add(new Tuple2<>(1596407074L, 421255800L)); // Cycle 16 - add(new Tuple2<>(1599175867L, 430737100L)); // Cycle 17 - add(new Tuple2<>(1601861442L, 429305600L)); // Cycle 18 - add(new Tuple2<>(1604845863L, 431446100L)); // Cycle 19 - 8 NOV 2020 - add(new Tuple2<>(1610233200L, 422663200L)); // Cycle 20 - add(new Tuple2<>(1612911600L, 449935500L)); // Cycle 21 - add(new Tuple2<>(1615762800L, 446547000L)); // Cycle 22 - add(new Tuple2<>(1618437600L, 441126800L)); // Cycle 23 - add(new Tuple2<>(1621288800L, 442629900L)); // Cycle 24 - add(new Tuple2<>(1624572000L, 434999300L)); // Cycle 25 - add(new Tuple2<>(1627596000L, 437237400L)); // Cycle 26 - add(new Tuple2<>(1630188000L, 431897700L)); // Cycle 27 - add(new Tuple2<>(1632952800L, 433282600L)); // Cycle 28 - add(new Tuple2<>(1635544800L, 431026400L)); // Cycle 29 - 29 SEP 2021 - add(new Tuple2<>(1638399600L, 424954400L)); // Cycle 30 - add(new Tuple2<>(1641078000L, 438560500L)); // Cycle 31 - add(new Tuple2<>(1643756400L, 433806200L)); // Cycle 32 - add(new Tuple2<>(1646555748L, 431667800L)); // Cycle 33 - }}; + public Stream getBsqSupplyChanges() { + Stream issued = getIssuanceItems() + .stream() + .map(i -> new BsqSupplyChange(getBlockTime(i.getChainHeight()), i.getAmount())); + + Stream burned = getUnorderedTxStream() + .filter(tx -> tx.getTxType() == TxType.PROOF_OF_BURN || tx.getTxType() == TxType.PAY_TRADE_FEE) + .map(i -> new BsqSupplyChange(i.getTime(), -i.getBurntBsq())); + + return Stream.concat(issued, burned); } diff --git a/core/src/main/java/bisq/core/dao/state/model/governance/BsqSupplyChange.java b/core/src/main/java/bisq/core/dao/state/model/governance/BsqSupplyChange.java new file mode 100644 index 00000000000..e46788e5308 --- /dev/null +++ b/core/src/main/java/bisq/core/dao/state/model/governance/BsqSupplyChange.java @@ -0,0 +1,13 @@ +package bisq.core.dao.state.model.governance; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +public class BsqSupplyChange { + @Getter + long time; + + @Getter + long value; +} diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java index 58861e1360b..9947825cf87 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java @@ -21,24 +21,26 @@ import bisq.core.dao.state.DaoStateService; import bisq.core.dao.state.model.blockchain.Tx; +import bisq.core.dao.state.model.governance.BsqSupplyChange; import bisq.core.dao.state.model.governance.Issuance; import bisq.core.dao.state.model.governance.IssuanceType; -import bisq.common.util.Tuple2; - import javax.inject.Inject; import javax.inject.Singleton; import java.time.Instant; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; +import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; @@ -120,7 +122,7 @@ Map getTotalSupplyByInterval() { } totalSupplyByInterval = getTotalBsqSupplyByInterval( - daoStateService.getTotalBsqSupply(), + daoStateService.getBsqSupplyChanges(), getDateFilter() ); @@ -195,10 +197,25 @@ Map getProofOfBurnByInterval() { // Aggregated collection data by interval /////////////////////////////////////////////////////////////////////////////////////////// - private Map getTotalBsqSupplyByInterval(Set> bsqSupply, Predicate dateFilter) { - return bsqSupply.stream() - .filter(i -> dateFilter.test(i.first)) - .collect(Collectors.toMap(i -> i.first, i -> i.second)); + private Map getTotalBsqSupplyByInterval(Stream bsqSupplyChanges, Predicate dateFilter) { + AtomicLong supply = new AtomicLong(372540100L); // Cycle 1 (15 APR 2019) supply + + return bsqSupplyChanges + .collect(Collectors.groupingBy(tx -> toTimeInterval(Instant.ofEpochMilli(tx.getTime())))) + .entrySet() + .stream() + .sorted(Comparator.comparingLong(e -> e.getKey())) + .map(e -> new BsqSupplyChange( + e.getKey(), + supply.addAndGet(e + .getValue() + .stream() + .mapToLong(BsqSupplyChange::getValue) + .sum() + )) + ) + .filter(t -> dateFilter.test(t.getTime())) + .collect(Collectors.toMap(BsqSupplyChange::getTime, BsqSupplyChange::getValue)); } private Map getIssuedBsqByInterval(Set issuanceSet, Predicate dateFilter) { From 5299607c35e4be8a60072f9168dd08d036f9f0a0 Mon Sep 17 00:00:00 2001 From: xyzmaker123 Date: Tue, 22 Mar 2022 12:53:50 +0100 Subject: [PATCH 3/5] Show changes in BSQ Supply over time - refactor --- .../main/dao/economy/supply/dao/DaoChartDataModel.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java index 9947825cf87..3c4ff117c95 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java @@ -198,7 +198,9 @@ Map getProofOfBurnByInterval() { /////////////////////////////////////////////////////////////////////////////////////////// private Map getTotalBsqSupplyByInterval(Stream bsqSupplyChanges, Predicate dateFilter) { - AtomicLong supply = new AtomicLong(372540100L); // Cycle 1 (15 APR 2019) supply + AtomicLong supply = new AtomicLong( + DaoEconomyHistoricalData.TOTAL_SUPPLY_BY_CYCLE_DATE.get(1555340856L) + ); return bsqSupplyChanges .collect(Collectors.groupingBy(tx -> toTimeInterval(Instant.ofEpochMilli(tx.getTime())))) @@ -275,6 +277,7 @@ private static class DaoEconomyHistoricalData { // Key is start date of the cycle in epoch seconds, value is reimbursement amount public final static Map REIMBURSEMENTS_BY_CYCLE_DATE = new HashMap<>(); public final static Map COMPENSATIONS_BY_CYCLE_DATE = new HashMap<>(); + public final static Map TOTAL_SUPPLY_BY_CYCLE_DATE = new HashMap<>(); static { REIMBURSEMENTS_BY_CYCLE_DATE.put(1571349571L, 60760L); @@ -310,6 +313,8 @@ private static class DaoEconomyHistoricalData { COMPENSATIONS_BY_CYCLE_DATE.put(1599175867L, 6086442L); COMPENSATIONS_BY_CYCLE_DATE.put(1601861442L, 5615973L); COMPENSATIONS_BY_CYCLE_DATE.put(1604845863L, 7782667L); + + TOTAL_SUPPLY_BY_CYCLE_DATE.put(1555340856L, 372540100L); } } } From 23347e6203d9de4f5410f920c0b6e76b3cd7fec7 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Tue, 10 May 2022 11:20:25 +0200 Subject: [PATCH 4/5] Add missing copyright notice --- .../state/model/governance/BsqSupplyChange.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/src/main/java/bisq/core/dao/state/model/governance/BsqSupplyChange.java b/core/src/main/java/bisq/core/dao/state/model/governance/BsqSupplyChange.java index e46788e5308..a37950f100b 100644 --- a/core/src/main/java/bisq/core/dao/state/model/governance/BsqSupplyChange.java +++ b/core/src/main/java/bisq/core/dao/state/model/governance/BsqSupplyChange.java @@ -1,3 +1,20 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + package bisq.core.dao.state.model.governance; import lombok.AllArgsConstructor; From 28332b96925ab26b3d804ae3df83e92dc22fe8c6 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Tue, 10 May 2022 11:20:52 +0200 Subject: [PATCH 5/5] Use lambda expressions where possible --- .../main/dao/economy/supply/dao/DaoChartDataModel.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java index 3c4ff117c95..c4f61c028bb 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/economy/supply/dao/DaoChartDataModel.java @@ -206,7 +206,7 @@ private Map getTotalBsqSupplyByInterval(Stream bsqS .collect(Collectors.groupingBy(tx -> toTimeInterval(Instant.ofEpochMilli(tx.getTime())))) .entrySet() .stream() - .sorted(Comparator.comparingLong(e -> e.getKey())) + .sorted(Comparator.comparingLong(Map.Entry::getKey)) .map(e -> new BsqSupplyChange( e.getKey(), supply.addAndGet(e @@ -240,7 +240,7 @@ private Map getHistoricalIssuedBsqByInterval(Map histori .filter(e -> dateFilter.test(e.getKey())) .collect(Collectors.toMap(e -> toTimeInterval(Instant.ofEpochSecond(e.getKey())), Map.Entry::getValue, - (a, b) -> a + b)); + Long::sum)); } private Map getBurntBsqByInterval(Collection txs, Predicate dateFilter) {