Search in sources :

Example 1 with TxType

use of bisq.core.dao.blockchain.vo.TxType in project bisq-core by bisq-network.

the class JsonBlockChainExporter method maybeExport.

public void maybeExport() {
    if (dumpBlockchainData) {
        ListenableFuture<Void> future = executor.submit(() -> {
            final BsqBlockChain bsqBlockChainClone = readableBsqBlockChain.getClone();
            for (Tx tx : bsqBlockChainClone.getTxMap().values()) {
                String txId = tx.getId();
                JsonTxType txType = tx.getTxType() != TxType.UNDEFINED_TX_TYPE ? JsonTxType.valueOf(tx.getTxType().name()) : null;
                List<JsonTxOutput> outputs = new ArrayList<>();
                tx.getOutputs().stream().forEach(txOutput -> {
                    final JsonTxOutput outputForJson = new JsonTxOutput(txId, txOutput.getIndex(), txOutput.isVerified() ? txOutput.getValue() : 0, !txOutput.isVerified() ? txOutput.getValue() : 0, txOutput.getBlockHeight(), txOutput.isVerified(), tx.getBurntFee(), txOutput.getAddress(), new JsonScriptPubKey(txOutput.getPubKeyScript()), txOutput.getSpentInfo() != null ? new JsonSpentInfo(txOutput.getSpentInfo()) : null, tx.getTime(), txType, txType != null ? txType.getDisplayString() : "", txOutput.getOpReturnData() != null ? Utils.HEX.encode(txOutput.getOpReturnData()) : null);
                    outputs.add(outputForJson);
                    txOutputFileManager.writeToDisc(Utilities.objectToJson(outputForJson), outputForJson.getId());
                });
                List<JsonTxInput> inputs = tx.getInputs().stream().map(txInput -> {
                    final TxOutput connectedTxOutput = txInput.getConnectedTxOutput();
                    return new JsonTxInput(txInput.getConnectedTxOutputIndex(), txInput.getConnectedTxOutputTxId(), connectedTxOutput != null ? connectedTxOutput.getValue() : 0, connectedTxOutput != null && connectedTxOutput.isVerified(), connectedTxOutput != null ? connectedTxOutput.getAddress() : null, tx.getTime());
                }).collect(Collectors.toList());
                final JsonTx jsonTx = new JsonTx(txId, tx.getBlockHeight(), tx.getBlockHash(), tx.getTime(), inputs, outputs, txType, txType != null ? txType.getDisplayString() : "", tx.getBurntFee());
                txFileManager.writeToDisc(Utilities.objectToJson(jsonTx), txId);
            }
            bsqBlockChainFileManager.writeToDisc(Utilities.objectToJson(bsqBlockChainClone), "BsqBlockChain");
            return null;
        });
        Futures.addCallback(future, new FutureCallback<Void>() {

            public void onSuccess(Void ignore) {
                log.trace("onSuccess");
            }

            public void onFailure(@NotNull Throwable throwable) {
                log.error(throwable.toString());
                throwable.printStackTrace();
            }
        });
    }
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Utilities(bisq.common.util.Utilities) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) Inject(com.google.inject.Inject) DaoOptionKeys(bisq.core.dao.DaoOptionKeys) ArrayList(java.util.ArrayList) JsonFileManager(bisq.common.storage.JsonFileManager) Named(javax.inject.Named) BsqBlockChain(bisq.core.dao.blockchain.BsqBlockChain) Tx(bisq.core.dao.blockchain.vo.Tx) Utils(org.bitcoinj.core.Utils) IOException(java.io.IOException) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) TxType(bisq.core.dao.blockchain.vo.TxType) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) FileUtil(bisq.common.storage.FileUtil) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Paths(java.nio.file.Paths) Storage(bisq.common.storage.Storage) NotNull(org.jetbrains.annotations.NotNull) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) Tx(bisq.core.dao.blockchain.vo.Tx) ArrayList(java.util.ArrayList) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) BsqBlockChain(bisq.core.dao.blockchain.BsqBlockChain)

Example 2 with TxType

use of bisq.core.dao.blockchain.vo.TxType in project bisq-core by bisq-network.

the class BsqTxController method getTxType.

// TODO add tests
@SuppressWarnings("WeakerAccess")
@VisibleForTesting
TxType getTxType(Tx tx, Model model) {
    TxType txType;
    // We need to have at least one BSQ output
    Optional<OpReturnType> optionalOpReturnType = getOptionalOpReturnType(tx, model);
    final boolean bsqFeesBurnt = model.isInputValuePositive();
    // noinspection OptionalIsPresent
    if (optionalOpReturnType.isPresent()) {
        txType = getTxTypeForOpReturn(tx, optionalOpReturnType.get());
    } else {
        if (bsqFeesBurnt) {
            // Burned fee but no opReturn
            txType = TxType.PAY_TRADE_FEE;
        } else {
            // No burned fee and no opReturn.
            txType = TxType.TRANSFER_BSQ;
        }
    }
    return txType;
}
Also used : TxType(bisq.core.dao.blockchain.vo.TxType) OpReturnType(bisq.core.dao.consensus.OpReturnType) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with TxType

use of bisq.core.dao.blockchain.vo.TxType in project bisq-core by bisq-network.

the class BsqTxController method getTxTypeForOpReturn.

@NotNull
private TxType getTxTypeForOpReturn(Tx tx, OpReturnType opReturnType) {
    TxType txType;
    switch(opReturnType) {
        case COMPENSATION_REQUEST:
            checkArgument(tx.getOutputs().size() >= 3, "Compensation request tx need to have at least 3 outputs");
            final TxOutput issuanceTxOutput = tx.getOutputs().get(1);
            checkArgument(issuanceTxOutput.getTxOutputType() == TxOutputType.ISSUANCE_CANDIDATE_OUTPUT, "Compensation request txOutput type need to be COMPENSATION_REQUEST_ISSUANCE_CANDIDATE_OUTPUT");
            // second output is issuance candidate
            if (issuanceTxOutput.isVerified()) {
                // TODO can that even happen as the voting will be applied later then the parsing of the tx
                // If he have the issuance candidate already accepted by voting it gets the verified flag set
                txType = TxType.ISSUANCE;
            } else {
                // Otherwise we have an open or rejected compensation request
                txType = TxType.COMPENSATION_REQUEST;
            }
            break;
        case PROPOSAL:
            txType = TxType.PROPOSAL;
            break;
        case BLIND_VOTE:
            txType = TxType.BLIND_VOTE;
            break;
        case VOTE_REVEAL:
            txType = TxType.VOTE_REVEAL;
            break;
        case LOCK_UP:
            // TODO
            txType = TxType.LOCK_UP;
            break;
        case UNLOCK:
            // TODO
            txType = TxType.UN_LOCK;
            break;
        default:
            log.warn("We got a BSQ tx with fee and unknown OP_RETURN. tx={}", tx);
            txType = TxType.INVALID;
    }
    return txType;
}
Also used : TxOutput(bisq.core.dao.blockchain.vo.TxOutput) TxType(bisq.core.dao.blockchain.vo.TxType) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TxType

use of bisq.core.dao.blockchain.vo.TxType in project bisq-desktop by bisq-network.

the class BsqTxView method addInformationColumn.

private void addInformationColumn() {
    TableColumn<BsqTxListItem, BsqTxListItem> column = new AutoTooltipTableColumn<>(Res.get("shared.information"));
    column.setCellValueFactory(item -> new ReadOnlyObjectWrapper<>(item.getValue()));
    column.setMinWidth(160);
    column.setCellFactory(new Callback<TableColumn<BsqTxListItem, BsqTxListItem>, TableCell<BsqTxListItem, BsqTxListItem>>() {

        @Override
        public TableCell<BsqTxListItem, BsqTxListItem> call(TableColumn<BsqTxListItem, BsqTxListItem> column) {
            return new TableCell<BsqTxListItem, BsqTxListItem>() {

                private AddressWithIconAndDirection field;

                @Override
                public void updateItem(final BsqTxListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        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()) {
                                if (field != null)
                                    field.setOnAction(null);
                                if (txType == TxType.TRANSFER_BSQ) {
                                    if (item.getAmount().isZero())
                                        labelString = Res.get("funds.tx.direction.self");
                                }
                                label = new AutoTooltipLabel(labelString);
                                setGraphic(label);
                            } else {
                                // Received
                                String addressString = item.getAddress();
                                field = new AddressWithIconAndDirection(item.getDirection(), addressString, AwesomeIcon.EXTERNAL_LINK, item.isReceived());
                                field.setOnAction(event -> openAddressInBlockExplorer(item));
                                field.setTooltip(new Tooltip(Res.get("tooltip.openBlockchainForAddress", addressString)));
                                setGraphic(field);
                            }
                        } else {
                            label = new AutoTooltipLabel(labelString);
                            setGraphic(label);
                        }
                    } else {
                        setGraphic(null);
                        if (field != null)
                            field.setOnAction(null);
                    }
                }
            };
        }
    });
    tableView.getColumns().add(column);
}
Also used : Transaction(org.bitcoinj.core.Transaction) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Coin(org.bitcoinj.core.Coin) Date(java.util.Date) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) VBox(javafx.scene.layout.VBox) BsqBalanceListener(bisq.core.btc.wallet.BsqBalanceListener) BsqNode(bisq.core.dao.node.BsqNode) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Pane(javafx.scene.layout.Pane) SortedList(javafx.collections.transformation.SortedList) HBox(javafx.scene.layout.HBox) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder(bisq.desktop.util.FormBuilder) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) Collectors(java.util.stream.Collectors) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) BsqBalanceUtil(bisq.desktop.main.dao.wallet.BsqBalanceUtil) List(java.util.List) Preferences(bisq.core.user.Preferences) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) GUIUtil(bisq.desktop.util.GUIUtil) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) ActivatableView(bisq.desktop.common.view.ActivatableView) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) BsqNodeProvider(bisq.core.dao.node.BsqNodeProvider) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) ProgressBar(javafx.scene.control.ProgressBar) Insets(javafx.geometry.Insets) AddressWithIconAndDirection(bisq.desktop.components.AddressWithIconAndDirection) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) DaoPeriodService(bisq.core.dao.DaoPeriodService) Tx(bisq.core.dao.blockchain.vo.Tx) AwesomeDude(de.jensd.fx.fontawesome.AwesomeDude) BisqEnvironment(bisq.core.app.BisqEnvironment) TxType(bisq.core.dao.blockchain.vo.TxType) BsqFormatter(bisq.desktop.util.BsqFormatter) TxOutputType(bisq.core.dao.blockchain.vo.TxOutputType) ChangeListener(javafx.beans.value.ChangeListener) TxType(bisq.core.dao.blockchain.vo.TxType) Tooltip(javafx.scene.control.Tooltip) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) AddressWithIconAndDirection(bisq.desktop.components.AddressWithIconAndDirection) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Aggregations

TxType (bisq.core.dao.blockchain.vo.TxType)4 TxOutput (bisq.core.dao.blockchain.vo.TxOutput)3 ReadableBsqBlockChain (bisq.core.dao.blockchain.ReadableBsqBlockChain)2 Tx (bisq.core.dao.blockchain.vo.Tx)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 NotNull (org.jetbrains.annotations.NotNull)2 FileUtil (bisq.common.storage.FileUtil)1 JsonFileManager (bisq.common.storage.JsonFileManager)1 Storage (bisq.common.storage.Storage)1 Utilities (bisq.common.util.Utilities)1 BisqEnvironment (bisq.core.app.BisqEnvironment)1 BsqBalanceListener (bisq.core.btc.wallet.BsqBalanceListener)1 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 DaoOptionKeys (bisq.core.dao.DaoOptionKeys)1 DaoPeriodService (bisq.core.dao.DaoPeriodService)1 BsqBlockChain (bisq.core.dao.blockchain.BsqBlockChain)1 TxOutputType (bisq.core.dao.blockchain.vo.TxOutputType)1