use of org.bitcoinj.core.TransactionConfidence in project bisq-desktop by bisq-network.
the class TxIdTextField method setup.
public void setup(String txID) {
if (txConfidenceListener != null)
walletService.removeTxConfidenceListener(txConfidenceListener);
txConfidenceListener = new TxConfidenceListener(txID) {
@Override
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
updateConfidence(confidence);
}
};
walletService.addTxConfidenceListener(txConfidenceListener);
updateConfidence(walletService.getConfidenceForTxId(txID));
textField.setText(txID);
textField.setOnMouseClicked(mouseEvent -> openBlockExplorer(txID));
blockExplorerIcon.setOnMouseClicked(mouseEvent -> openBlockExplorer(txID));
copyIcon.setOnMouseClicked(e -> Utilities.copyToClipboard(txID));
}
use of org.bitcoinj.core.TransactionConfidence in project bisq-api by mrosseel.
the class BisqProxy method toWalletTransaction.
@NotNull
private WalletTransaction toWalletTransaction(Wallet wallet, Transaction transaction) {
final Coin valueSentFromMe = transaction.getValueSentFromMe(wallet);
final Coin valueSentToMe = transaction.getValueSentToMe(wallet);
boolean received = false;
String addressString = null;
if (valueSentToMe.isZero()) {
for (TransactionOutput output : transaction.getOutputs()) {
if (!btcWalletService.isTransactionOutputMine(output)) {
received = false;
if (WalletService.isOutputScriptConvertibleToAddress(output)) {
addressString = WalletService.getAddressStringFromOutput(output);
break;
}
}
}
} else if (valueSentFromMe.isZero()) {
received = true;
for (TransactionOutput output : transaction.getOutputs()) {
if (btcWalletService.isTransactionOutputMine(output) && WalletService.isOutputScriptConvertibleToAddress(output)) {
addressString = WalletService.getAddressStringFromOutput(output);
break;
}
}
} else {
boolean outgoing = false;
for (TransactionOutput output : transaction.getOutputs()) {
if (!btcWalletService.isTransactionOutputMine(output)) {
if (WalletService.isOutputScriptConvertibleToAddress(output)) {
addressString = WalletService.getAddressStringFromOutput(output);
outgoing = !(BisqEnvironment.isBaseCurrencySupportingBsq() && bsqWalletService.isTransactionOutputMine(output));
break;
}
}
}
if (outgoing) {
received = false;
}
}
final TransactionConfidence confidence = transaction.getConfidence();
int confirmations = null == confidence ? 0 : confidence.getDepthInBlocks();
final WalletTransaction walletTransaction = new WalletTransaction();
walletTransaction.updateTime = transaction.getUpdateTime().getTime();
walletTransaction.hash = transaction.getHashAsString();
walletTransaction.fee = (transaction.getFee() == null) ? -1 : transaction.getFee().value;
walletTransaction.value = transaction.getValue(wallet).value;
walletTransaction.valueSentFromMe = valueSentFromMe.value;
walletTransaction.valueSentToMe = valueSentToMe.value;
walletTransaction.confirmations = confirmations;
walletTransaction.inbound = received;
walletTransaction.address = addressString;
return walletTransaction;
}
use of org.bitcoinj.core.TransactionConfidence in project bisq-core by bisq-network.
the class BuyerSetupPayoutTxListener method run.
@Override
protected void run() {
try {
runInterceptHook();
if (!trade.isPayoutPublished()) {
BtcWalletService walletService = processModel.getBtcWalletService();
final String id = processModel.getOffer().getId();
Address address = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT).getAddress();
final TransactionConfidence confidence = walletService.getConfidenceForAddress(address);
if (isInNetwork(confidence)) {
applyConfidence(confidence);
} else {
confidenceListener = new AddressConfidenceListener(address) {
@Override
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
if (isInNetwork(confidence))
applyConfidence(confidence);
}
};
walletService.addAddressConfidenceListener(confidenceListener);
tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), newValue -> {
if (trade.isPayoutPublished()) {
swapMultiSigEntry();
// hack to remove tradeStateSubscription at callback
UserThread.execute(this::unSubscribe);
}
});
}
}
// we complete immediately, our object stays alive because the balanceListener is stored in the WalletService
complete();
} catch (Throwable t) {
failed(t);
}
}
Aggregations