From b768eee4c66c3b691ffdd40e0da3bfe5e66672d9 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 24 Mar 2018 11:32:42 -0500 Subject: [PATCH 1/2] Add missing DaoPeriodService.Phase entries in switch cases --- .../bisq/desktop/main/dao/proposal/ProposalListItem.java | 4 ++++ .../main/dao/proposal/active/ActiveProposalsView.java | 8 +++++++- .../dao/proposal/dashboard/ProposalDashboardView.java | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/bisq/desktop/main/dao/proposal/ProposalListItem.java b/src/main/java/bisq/desktop/main/dao/proposal/ProposalListItem.java index afd4af1f8e..e17dc4d6ce 100644 --- a/src/main/java/bisq/desktop/main/dao/proposal/ProposalListItem.java +++ b/src/main/java/bisq/desktop/main/dao/proposal/ProposalListItem.java @@ -176,6 +176,10 @@ public class ProposalListItem implements BsqNode.BsqBlockChainListener { break; case BREAK3: break; + case ISSUANCE: + break; + case BREAK4: + break; } actionButton.setManaged(actionButton.isVisible()); diff --git a/src/main/java/bisq/desktop/main/dao/proposal/active/ActiveProposalsView.java b/src/main/java/bisq/desktop/main/dao/proposal/active/ActiveProposalsView.java index 8b3531041d..39c46839ca 100644 --- a/src/main/java/bisq/desktop/main/dao/proposal/active/ActiveProposalsView.java +++ b/src/main/java/bisq/desktop/main/dao/proposal/active/ActiveProposalsView.java @@ -68,6 +68,8 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import org.jetbrains.annotations.NotNull; + import javax.annotation.Nullable; import static bisq.desktop.util.FormBuilder.add3ButtonsAfterGroup; @@ -136,7 +138,7 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL } @Override - public void onFailure(Throwable t) { + public void onFailure(@NotNull Throwable t) { //TODO } }); @@ -303,6 +305,10 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL break; case BREAK3: break; + case ISSUANCE: + break; + case BREAK4: + break; case UNDEFINED: default: log.warn("Undefined phase: " + phase); diff --git a/src/main/java/bisq/desktop/main/dao/proposal/dashboard/ProposalDashboardView.java b/src/main/java/bisq/desktop/main/dao/proposal/dashboard/ProposalDashboardView.java index 23b13367bd..58d065763d 100644 --- a/src/main/java/bisq/desktop/main/dao/proposal/dashboard/ProposalDashboardView.java +++ b/src/main/java/bisq/desktop/main/dao/proposal/dashboard/ProposalDashboardView.java @@ -102,7 +102,9 @@ public class ProposalDashboardView extends ActivatableView { new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.OPEN_FOR_VOTING, true), new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.BREAK2, false), new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.VOTE_REVEAL, true), - new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.BREAK3, false)); + new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.BREAK3, false), + new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.ISSUANCE, false), + new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.BREAK4, false)); return new SeparatedPhaseBars(phaseBarsItems); } From 969f32f05ae36c06181dac28469e34e0b196bc25 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 27 Mar 2018 10:53:28 -0500 Subject: [PATCH 2/2] Implement issuance --- .../main/dao/proposal/ProposalListItem.java | 2 +- .../proposal/active/ActiveProposalsView.java | 8 +- .../dashboard/ProposalDashboardView.java | 2 +- .../main/dao/wallet/tx/BsqTxListItem.java | 11 ++- .../desktop/main/dao/wallet/tx/BsqTxView.java | 87 ++++++++++++++++--- 5 files changed, 88 insertions(+), 22 deletions(-) diff --git a/src/main/java/bisq/desktop/main/dao/proposal/ProposalListItem.java b/src/main/java/bisq/desktop/main/dao/proposal/ProposalListItem.java index e17dc4d6ce..7614329684 100644 --- a/src/main/java/bisq/desktop/main/dao/proposal/ProposalListItem.java +++ b/src/main/java/bisq/desktop/main/dao/proposal/ProposalListItem.java @@ -149,7 +149,7 @@ public class ProposalListItem implements BsqNode.BsqBlockChainListener { break; case BREAK1: break; - case OPEN_FOR_VOTING: + case BLIND_VOTE: if (!isTxInPastCycle) { actionNode = actionButtonIconView; actionButton.setVisible(false); diff --git a/src/main/java/bisq/desktop/main/dao/proposal/active/ActiveProposalsView.java b/src/main/java/bisq/desktop/main/dao/proposal/active/ActiveProposalsView.java index 39c46839ca..e5dae4e6a2 100644 --- a/src/main/java/bisq/desktop/main/dao/proposal/active/ActiveProposalsView.java +++ b/src/main/java/bisq/desktop/main/dao/proposal/active/ActiveProposalsView.java @@ -45,6 +45,8 @@ import bisq.common.crypto.CryptoException; import bisq.common.util.Tuple2; import bisq.common.util.Tuple3; +import com.google.protobuf.InvalidProtocolBufferException; + import org.bitcoinj.core.Coin; import org.bitcoinj.core.InsufficientMoneyException; import org.bitcoinj.core.Transaction; @@ -155,6 +157,8 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL e1.printStackTrace(); } catch (ChangeBelowDustException e1) { e1.printStackTrace(); + } catch (InvalidProtocolBufferException e1) { + e1.printStackTrace(); } }); } @@ -251,7 +255,7 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL protected void onPhaseChanged(DaoPeriodService.Phase phase) { super.onPhaseChanged(phase); - changeVoteViewItemsVisibility(phase == DaoPeriodService.Phase.OPEN_FOR_VOTING); + changeVoteViewItemsVisibility(phase == DaoPeriodService.Phase.BLIND_VOTE); if (removeButton != null) { removeButton.setManaged(false); @@ -276,7 +280,7 @@ public class ActiveProposalsView extends BaseProposalView implements BsqBalanceL break; case BREAK1: break; - case OPEN_FOR_VOTING: + case BLIND_VOTE: if (acceptButton == null) { Tuple3 tuple = add3ButtonsAfterGroup(detailsGridPane, proposalDisplay .incrementAndGetGridRow(), diff --git a/src/main/java/bisq/desktop/main/dao/proposal/dashboard/ProposalDashboardView.java b/src/main/java/bisq/desktop/main/dao/proposal/dashboard/ProposalDashboardView.java index 58d065763d..4625c649b4 100644 --- a/src/main/java/bisq/desktop/main/dao/proposal/dashboard/ProposalDashboardView.java +++ b/src/main/java/bisq/desktop/main/dao/proposal/dashboard/ProposalDashboardView.java @@ -99,7 +99,7 @@ public class ProposalDashboardView extends ActivatableView { phaseBarsItems = Arrays.asList( new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.PROPOSAL, true), new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.BREAK1, false), - new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.OPEN_FOR_VOTING, true), + new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.BLIND_VOTE, true), new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.BREAK2, false), new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.VOTE_REVEAL, true), new SeparatedPhaseBars.SeparatedPhaseBarsItem(DaoPeriodService.Phase.BREAK3, false), diff --git a/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java b/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java index 38d3b0e388..c9d606e675 100644 --- a/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java +++ b/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxListItem.java @@ -25,7 +25,6 @@ import bisq.core.btc.listeners.TxConfidenceListener; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletService; -import bisq.core.dao.blockchain.BsqBlockChain; import bisq.core.dao.blockchain.vo.TxType; import bisq.core.locale.Res; @@ -66,7 +65,7 @@ class BsqTxListItem { @Getter private final String direction; @Getter - private final Coin amount; + private Coin amount; @Getter private boolean received; @Getter @@ -84,17 +83,17 @@ class BsqTxListItem { BtcWalletService btcWalletService, Optional txTypeOptional, boolean isBurnedBsqTx, - BsqBlockChain bsqBlockChain, + Date date, BsqFormatter bsqFormatter) { this.transaction = transaction; this.bsqWalletService = bsqWalletService; this.btcWalletService = btcWalletService; this.txTypeOptional = txTypeOptional; this.isBurnedBsqTx = isBurnedBsqTx; + this.date = date; this.bsqFormatter = bsqFormatter; txId = transaction.getHashAsString(); - date = transaction.getUpdateTime(); setupConfidence(bsqWalletService); @@ -180,5 +179,9 @@ class BsqTxListItem { else return confirmations == 0 ? TxType.UNVERIFIED : TxType.UNDEFINED_TX_TYPE; } + + public void setAmount(Coin amount) { + this.amount = amount; + } } diff --git a/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java b/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java index bee73a971c..d4297625bd 100644 --- a/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java +++ b/src/main/java/bisq/desktop/main/dao/wallet/tx/BsqTxView.java @@ -32,7 +32,11 @@ import bisq.core.app.BisqEnvironment; import bisq.core.btc.wallet.BsqBalanceListener; import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BtcWalletService; -import bisq.core.dao.blockchain.BsqBlockChain; +import bisq.core.dao.DaoPeriodService; +import bisq.core.dao.blockchain.ReadableBsqBlockChain; +import bisq.core.dao.blockchain.vo.Tx; +import bisq.core.dao.blockchain.vo.TxOutput; +import bisq.core.dao.blockchain.vo.TxOutputType; import bisq.core.dao.blockchain.vo.TxType; import bisq.core.dao.node.BsqNode; import bisq.core.dao.node.BsqNodeProvider; @@ -73,8 +77,9 @@ import javafx.collections.transformation.SortedList; import javafx.util.Callback; import java.util.ArrayList; +import java.util.Date; import java.util.List; -import java.util.Set; +import java.util.Optional; import java.util.stream.Collectors; @FxmlView @@ -85,7 +90,8 @@ public class BsqTxView extends ActivatableView implements BsqBal private final BsqFormatter bsqFormatter; private final BsqWalletService bsqWalletService; - private final BsqBlockChain bsqBlockChain; + private final ReadableBsqBlockChain readableBsqBlockChain; + private final DaoPeriodService daoPeriodService; private final BtcWalletService btcWalletService; private final BsqBalanceUtil bsqBalanceUtil; private final BsqNode bsqNode; @@ -108,16 +114,20 @@ public class BsqTxView extends ActivatableView implements BsqBal /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private BsqTxView(BsqFormatter bsqFormatter, BsqWalletService bsqWalletService, + private BsqTxView(BsqFormatter bsqFormatter, + BsqWalletService bsqWalletService, BsqNodeProvider bsqNodeProvider, Preferences preferences, - BsqBlockChain bsqBlockChain, - BtcWalletService btcWalletService, BsqBalanceUtil bsqBalanceUtil) { + ReadableBsqBlockChain readableBsqBlockChain, + DaoPeriodService daoPeriodService, + BtcWalletService btcWalletService, + BsqBalanceUtil bsqBalanceUtil) { this.bsqFormatter = bsqFormatter; this.bsqWalletService = bsqWalletService; this.bsqNode = bsqNodeProvider.getBsqNode(); this.preferences = preferences; - this.bsqBlockChain = bsqBlockChain; + this.readableBsqBlockChain = readableBsqBlockChain; + this.daoPeriodService = daoPeriodService; this.btcWalletService = btcWalletService; this.bsqBalanceUtil = bsqBalanceUtil; } @@ -213,7 +223,7 @@ public class BsqTxView extends ActivatableView implements BsqBal private void onChainHeightChanged() { final int bsqWalletChainHeight = bsqWalletService.getChainHeightProperty().get(); - final int bsqBlockChainHeight = bsqBlockChain.getChainHeadHeight(); + final int bsqBlockChainHeight = readableBsqBlockChain.getChainHeadHeight(); if (bsqWalletChainHeight > 0) { final boolean synced = bsqWalletChainHeight == bsqBlockChainHeight; chainSyncIndicator.setVisible(!synced); @@ -242,16 +252,65 @@ public class BsqTxView extends ActivatableView implements BsqBal // copy list to avoid ConcurrentModificationException final List walletTransactions = new ArrayList<>(bsqWalletService.getWalletTransactions()); - Set items = walletTransactions.stream() + List items = walletTransactions.stream() .map(transaction -> new BsqTxListItem(transaction, bsqWalletService, btcWalletService, - bsqBlockChain.getTxType(transaction.getHashAsString()), - bsqBlockChain.hasTxBurntFee(transaction.getHashAsString()), - bsqBlockChain, + readableBsqBlockChain.getTxType(transaction.getHashAsString()), + readableBsqBlockChain.hasTxBurntFee(transaction.getHashAsString()), + transaction.getUpdateTime(), bsqFormatter) ) - .collect(Collectors.toSet()); + .collect(Collectors.toList()); + + List issuanceTxList = new ArrayList<>(); + items.stream() + .filter(item -> item.getTxType() == TxType.COMPENSATION_REQUEST) + .peek(item -> { + final Tx tx = readableBsqBlockChain.getTx(item.getTxId()).get(); + long changeValue = tx.getOutputs().get(0).getValue(); + long inputValue = tx.getInputs().stream() + .filter(input -> input.getConnectedTxOutput() != null) + .mapToLong(input -> input.getConnectedTxOutput().getValue()) + .sum(); + long fee = inputValue - changeValue; + item.setAmount(Coin.valueOf(fee)); + }) + .filter(item -> { + final Optional optionalTx = readableBsqBlockChain.getTx(item.getTxId()); + if (optionalTx.isPresent()) { + final List outputs = optionalTx.get().getOutputs(); + if (!outputs.isEmpty()) { + return outputs.get(0).getTxOutputType() == TxOutputType.BSQ_OUTPUT; + } + } + return false; + }) + .forEach(item -> { + final Tx tx = readableBsqBlockChain.getTx(item.getTxId()).get(); + final int blockHeight = tx.getBlockHeight(); + final int issuanceBlockHeight = daoPeriodService.getAbsoluteStartBlockOfPhase(blockHeight, DaoPeriodService.Phase.ISSUANCE); + log.error("blockHeight {}, issuanceBlockHeight={}", blockHeight, issuanceBlockHeight); + final long blockTimeInSec = readableBsqBlockChain.getBlockTime(issuanceBlockHeight); + + long inputValue = tx.getInputs().stream() + .filter(input -> input.getConnectedTxOutput() != null) + .mapToLong(input -> input.getConnectedTxOutput().getValue()) + .sum(); + long issuanceValue = tx.getOutputs().get(1).getValue(); + + final BsqTxListItem issuanceItem = new BsqTxListItem(item.getTransaction(), + bsqWalletService, + btcWalletService, + Optional.of(TxType.ISSUANCE), + item.isBurnedBsqTx(), + new Date(blockTimeInSec * 1000), + bsqFormatter); + issuanceItem.setAmount(Coin.valueOf(issuanceValue)); + issuanceTxList.add(issuanceItem); + + }); + items.addAll(issuanceTxList); observableList.setAll(items); } @@ -533,7 +592,7 @@ public class BsqTxView extends ActivatableView implements BsqBal style = "dao-tx-type-vote-reveal-icon"; break; case ISSUANCE: - awesomeIcon = AwesomeIcon.UMBRELLA; + awesomeIcon = AwesomeIcon.MONEY; style = "dao-tx-type-issuance-icon"; break; default: