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();
}
});
}
}
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;
}
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;
}
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);
}
Aggregations