mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Add new fields to Tx. Remove ISSUANCE type from TxType
This commit is contained in:
parent
169f85d0c3
commit
3e0b7d360a
2 changed files with 50 additions and 108 deletions
|
@ -25,6 +25,7 @@ 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.vo.Tx;
|
||||
import bisq.core.dao.blockchain.vo.TxType;
|
||||
import bisq.core.locale.Res;
|
||||
|
||||
|
@ -38,57 +39,41 @@ import javafx.scene.control.Tooltip;
|
|||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.Data;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
||||
@ToString
|
||||
@Slf4j
|
||||
@EqualsAndHashCode
|
||||
@Data
|
||||
class BsqTxListItem {
|
||||
@Getter
|
||||
private final Transaction transaction;
|
||||
private BsqWalletService bsqWalletService;
|
||||
private BtcWalletService btcWalletService;
|
||||
@Getter
|
||||
private final Date date;
|
||||
@Getter
|
||||
private final Optional<Tx> optionalTx;
|
||||
private final BsqWalletService bsqWalletService;
|
||||
private final BtcWalletService btcWalletService;
|
||||
private Date date;
|
||||
private final String txId;
|
||||
@Getter
|
||||
private int confirmations = 0;
|
||||
@Getter
|
||||
private final String address;
|
||||
@Getter
|
||||
private final String direction;
|
||||
@Getter
|
||||
private Coin amount;
|
||||
@Getter
|
||||
private boolean received;
|
||||
@Getter
|
||||
private Optional<TxType> txTypeOptional;
|
||||
@Getter
|
||||
private boolean isBurnedBsqTx;
|
||||
private BsqFormatter bsqFormatter;
|
||||
@Getter
|
||||
private TxConfidenceIndicator txConfidenceIndicator;
|
||||
|
||||
private TxConfidenceListener txConfidenceListener;
|
||||
private boolean issuanceTx;
|
||||
|
||||
public BsqTxListItem(Transaction transaction,
|
||||
BsqWalletService bsqWalletService,
|
||||
BtcWalletService btcWalletService,
|
||||
Optional<TxType> txTypeOptional,
|
||||
boolean isBurnedBsqTx,
|
||||
Date date,
|
||||
BsqFormatter bsqFormatter) {
|
||||
BsqTxListItem(Transaction transaction,
|
||||
Optional<Tx> optionalTx,
|
||||
BsqWalletService bsqWalletService,
|
||||
BtcWalletService btcWalletService,
|
||||
boolean isBurnedBsqTx,
|
||||
Date date,
|
||||
BsqFormatter bsqFormatter) {
|
||||
this.transaction = transaction;
|
||||
this.optionalTx = optionalTx;
|
||||
this.bsqWalletService = bsqWalletService;
|
||||
this.btcWalletService = btcWalletService;
|
||||
this.txTypeOptional = txTypeOptional;
|
||||
this.isBurnedBsqTx = isBurnedBsqTx;
|
||||
this.date = date;
|
||||
this.bsqFormatter = bsqFormatter;
|
||||
|
@ -174,8 +159,8 @@ class BsqTxListItem {
|
|||
}
|
||||
|
||||
public TxType getTxType() {
|
||||
if (txTypeOptional.isPresent())
|
||||
return txTypeOptional.get();
|
||||
if (optionalTx.isPresent())
|
||||
return optionalTx.get().getTxType();
|
||||
else
|
||||
return confirmations == 0 ? TxType.UNVERIFIED : TxType.UNDEFINED_TX_TYPE;
|
||||
}
|
||||
|
|
|
@ -36,8 +36,6 @@ import bisq.core.dao.blockchain.BsqBlockChain;
|
|||
import bisq.core.dao.blockchain.ReadableBsqBlockChain;
|
||||
import bisq.core.dao.blockchain.vo.BsqBlock;
|
||||
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.vote.DaoPeriodService;
|
||||
import bisq.core.locale.Res;
|
||||
|
@ -260,71 +258,18 @@ public class BsqTxView extends ActivatableView<GridPane, Void> implements BsqBal
|
|||
// copy list to avoid ConcurrentModificationException
|
||||
final List<Transaction> walletTransactions = new ArrayList<>(bsqWalletService.getWalletTransactions());
|
||||
List<BsqTxListItem> items = walletTransactions.stream()
|
||||
.map(transaction -> new BsqTxListItem(transaction,
|
||||
bsqWalletService,
|
||||
btcWalletService,
|
||||
readableBsqBlockChain.getTxType(transaction.getHashAsString()),
|
||||
readableBsqBlockChain.hasTxBurntFee(transaction.getHashAsString()),
|
||||
transaction.getUpdateTime(),
|
||||
bsqFormatter)
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
items.addAll(getCompensationRequestTxListItems(items));
|
||||
|
||||
observableList.setAll(items);
|
||||
}
|
||||
|
||||
// We add manually a modified copy of the compensation request tx if it has become an issuance tx
|
||||
// It is a bit weird to have one tx displayed 2 times but I think it is better to show both aspects
|
||||
// separately. First the compensation request tx with the fee then after voting the issuance.
|
||||
private List<BsqTxListItem> getCompensationRequestTxListItems(List<BsqTxListItem> items) {
|
||||
List<BsqTxListItem> issuanceTxList = new ArrayList<>();
|
||||
items.stream()
|
||||
.filter(item -> item.getTxType() == TxType.COMPENSATION_REQUEST)
|
||||
.peek(item -> {
|
||||
final Tx tx = readableBsqBlockChain.getTx(item.getTxId()).get();
|
||||
// We have mandatory BSQ change at output 0
|
||||
long changeValue = tx.getOutputs().get(0).getValue();
|
||||
long inputValue = tx.getInputs().stream()
|
||||
.filter(input -> input.getConnectedTxOutput() != null)
|
||||
.mapToLong(input -> input.getConnectedTxOutput().getValue())
|
||||
.sum();
|
||||
// We want to show fee as negative number
|
||||
long fee = changeValue - inputValue;
|
||||
item.setAmount(Coin.valueOf(fee));
|
||||
})
|
||||
.filter(item -> {
|
||||
final Optional<Tx> optionalTx = readableBsqBlockChain.getTx(item.getTxId());
|
||||
if (optionalTx.isPresent()) {
|
||||
final List<TxOutput> 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);
|
||||
// We use the time of the block height of the start of the issuance period
|
||||
final long blockTimeInSec = readableBsqBlockChain.getBlockTime(issuanceBlockHeight);
|
||||
final BsqTxListItem issuanceItem = new BsqTxListItem(item.getTransaction(),
|
||||
.map(transaction -> {
|
||||
final Optional<Tx> optionalTx = readableBsqBlockChain.getTx(transaction.getHashAsString());
|
||||
return new BsqTxListItem(transaction,
|
||||
optionalTx,
|
||||
bsqWalletService,
|
||||
btcWalletService,
|
||||
Optional.of(TxType.ISSUANCE),
|
||||
item.isBurnedBsqTx(),
|
||||
new Date(blockTimeInSec * 1000),
|
||||
readableBsqBlockChain.hasTxBurntFee(transaction.getHashAsString()),
|
||||
transaction.getUpdateTime(),
|
||||
bsqFormatter);
|
||||
|
||||
// On output 1 we have the issuance candidate
|
||||
long issuanceValue = tx.getOutputs().get(1).getValue();
|
||||
issuanceItem.setAmount(Coin.valueOf(issuanceValue));
|
||||
issuanceTxList.add(issuanceItem);
|
||||
|
||||
});
|
||||
return issuanceTxList;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
observableList.setAll(items);
|
||||
}
|
||||
|
||||
private void layout() {
|
||||
|
@ -421,11 +366,19 @@ public class BsqTxView extends ActivatableView<GridPane, Void> implements BsqBal
|
|||
public void updateItem(final BsqTxListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty) {
|
||||
TxType txType = item.getTxType();
|
||||
final TxType txType = item.getTxType();
|
||||
String labelString = Res.get("dao.tx.type.enum." + txType.name());
|
||||
Label label;
|
||||
if (item.getConfirmations() > 0 && txType.ordinal() > TxType.INVALID.ordinal()) {
|
||||
if (item.isBurnedBsqTx() || item.getAmount().isZero()) {
|
||||
final Optional<Tx> optionalTx = item.getOptionalTx();
|
||||
if (txType == TxType.COMPENSATION_REQUEST && optionalTx.isPresent() && optionalTx.get().isIssuanceTx()) {
|
||||
if (field != null)
|
||||
field.setOnAction(null);
|
||||
|
||||
labelString = Res.get("dao.tx.issuance");
|
||||
label = new AutoTooltipLabel(labelString);
|
||||
setGraphic(label);
|
||||
} else if (item.isBurnedBsqTx() || item.getAmount().isZero()) {
|
||||
if (field != null)
|
||||
field.setOnAction(null);
|
||||
|
||||
|
@ -479,11 +432,12 @@ public class BsqTxView extends ActivatableView<GridPane, Void> implements BsqBal
|
|||
@Override
|
||||
public void updateItem(final BsqTxListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty)
|
||||
setText(item.getConfirmations() > 0 && item.getTxType().ordinal() > TxType.INVALID.ordinal() ?
|
||||
if (item != null && !empty) {
|
||||
TxType txType = item.getTxType();
|
||||
setText(item.getConfirmations() > 0 && txType.ordinal() > TxType.INVALID.ordinal() ?
|
||||
bsqFormatter.formatCoin(item.getAmount()) :
|
||||
Res.get("shared.na"));
|
||||
else
|
||||
} else
|
||||
setText("");
|
||||
}
|
||||
};
|
||||
|
@ -577,8 +531,15 @@ public class BsqTxView extends ActivatableView<GridPane, Void> implements BsqBal
|
|||
style = "dao-tx-type-default-icon";
|
||||
break;
|
||||
case COMPENSATION_REQUEST:
|
||||
awesomeIcon = AwesomeIcon.FILE;
|
||||
style = "dao-tx-type-fee-icon";
|
||||
if (item.getOptionalTx().isPresent() && item.getOptionalTx().get().isIssuanceTx()) {
|
||||
awesomeIcon = AwesomeIcon.MONEY;
|
||||
style = "dao-tx-type-issuance-icon";
|
||||
long blockTimeInSec = readableBsqBlockChain.getBlockTime(item.getOptionalTx().get().getIssuanceBlockHeight());
|
||||
toolTipText = Res.get("dao.tx.issuance.tooltip", bsqFormatter.formatDateTime(new Date(blockTimeInSec * 1000)));
|
||||
} else {
|
||||
awesomeIcon = AwesomeIcon.FILE;
|
||||
style = "dao-tx-type-fee-icon";
|
||||
}
|
||||
break;
|
||||
case BLIND_VOTE:
|
||||
awesomeIcon = AwesomeIcon.THUMBS_UP;
|
||||
|
@ -588,10 +549,6 @@ public class BsqTxView extends ActivatableView<GridPane, Void> implements BsqBal
|
|||
awesomeIcon = AwesomeIcon.LIGHTBULB;
|
||||
style = "dao-tx-type-vote-reveal-icon";
|
||||
break;
|
||||
case ISSUANCE:
|
||||
awesomeIcon = AwesomeIcon.MONEY;
|
||||
style = "dao-tx-type-issuance-icon";
|
||||
break;
|
||||
default:
|
||||
awesomeIcon = AwesomeIcon.QUESTION_SIGN;
|
||||
style = "dao-tx-type-unverified-icon";
|
||||
|
|
Loading…
Add table
Reference in a new issue