use of org.bitcoinj.core.Transaction in project bitsquare by bitsquare.
the class LockedView method initialize.
@Override
public void initialize() {
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setPlaceholder(new Label("No funds are locked in trades"));
setDateColumnCellFactory();
setDetailsColumnCellFactory();
setAddressColumnCellFactory();
setBalanceColumnCellFactory();
addressColumn.setComparator((o1, o2) -> o1.getAddressString().compareTo(o2.getAddressString()));
detailsColumn.setComparator((o1, o2) -> o1.getTrade().getId().compareTo(o2.getTrade().getId()));
balanceColumn.setComparator((o1, o2) -> o1.getBalance().compareTo(o2.getBalance()));
dateColumn.setComparator((o1, o2) -> {
if (getTradable(o1).isPresent() && getTradable(o2).isPresent())
return getTradable(o2).get().getDate().compareTo(getTradable(o1).get().getDate());
else
return 0;
});
tableView.getSortOrder().add(dateColumn);
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
balanceListener = new BalanceListener() {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateList();
}
};
openOfferListChangeListener = c -> updateList();
tradeListChangeListener = c -> updateList();
}
use of org.bitcoinj.core.Transaction in project bitsquare by bitsquare.
the class PendingTradesDataModel method tryOpenDispute.
private void tryOpenDispute(boolean isSupportTicket) {
if (getTrade() != null) {
Transaction depositTx = getTrade().getDepositTx();
if (depositTx != null) {
doOpenDispute(isSupportTicket, getTrade().getDepositTx());
} else {
log.info("Trade.depositTx is null. We try to find the tx in our wallet.");
List<Transaction> candidates = new ArrayList<>();
List<Transaction> transactions = walletService.getWallet().getRecentTransactions(100, true);
transactions.stream().forEach(transaction -> {
Coin valueSentFromMe = transaction.getValueSentFromMe(walletService.getWallet());
if (!valueSentFromMe.isZero()) {
candidates.addAll(transaction.getOutputs().stream().filter(transactionOutput -> !transactionOutput.isMine(walletService.getWallet())).filter(transactionOutput -> transactionOutput.getScriptPubKey().isPayToScriptHash()).map(transactionOutput -> transaction).collect(Collectors.toList()));
}
});
if (candidates.size() == 1)
doOpenDispute(isSupportTicket, candidates.get(0));
else if (candidates.size() > 1)
new SelectDepositTxWindow().transactions(candidates).onSelect(transaction -> doOpenDispute(isSupportTicket, transaction)).closeButtonText("Cancel").show();
else
log.error("Trade.depositTx is null and we did not find any MultiSig transaction.");
}
} else {
log.error("Trade is null");
}
}
use of org.bitcoinj.core.Transaction in project bitsquare by bitsquare.
the class SignAndFinalizePayoutTx method run.
@Override
protected void run() {
try {
runInterceptHook();
checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
Coin sellerPayoutAmount = FeePolicy.getSecurityDeposit(trade.getOffer());
Coin buyerPayoutAmount = sellerPayoutAmount.add(trade.getTradeAmount());
WalletService walletService = processModel.getWalletService();
AddressEntry buyerAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
AddressEntry multiSigAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
Transaction transaction = processModel.getTradeWalletService().buyerSignsAndFinalizesPayoutTx(trade.getDepositTx(), processModel.tradingPeer.getSignature(), buyerPayoutAmount, sellerPayoutAmount, buyerAddressEntry.getAddressString(), processModel.tradingPeer.getPayoutAddressString(), multiSigAddressEntry.getKeyPair(), trade.getLockTimeAsBlockHeight(), multiSigAddressEntry.getPubKey(), processModel.tradingPeer.getMultiSigPubKey(), trade.getArbitratorPubKey());
trade.setPayoutTx(transaction);
trade.setState(Trade.State.BUYER_COMMITTED_PAYOUT_TX);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of org.bitcoinj.core.Transaction in project bitsquare by bitsquare.
the class ProcessDepositTxPublishedMessage method run.
@Override
protected void run() {
try {
runInterceptHook();
log.debug("current trade state " + trade.getState());
DepositTxPublishedMessage message = (DepositTxPublishedMessage) processModel.getTradeMessage();
checkTradeId(processModel.getId(), message);
checkNotNull(message);
checkArgument(message.depositTx != null);
// To access tx confidence we need to add that tx into our wallet.
Transaction transactionFromSerializedTx = processModel.getWalletService().getTransactionFromSerializedTx(message.depositTx);
// update with full tx
trade.setDepositTx(processModel.getTradeWalletService().addTransactionToWallet(transactionFromSerializedTx));
if (trade instanceof OffererTrade)
processModel.getOpenOfferManager().closeOpenOffer(trade.getOffer());
// update to the latest peer address of our peer if the message is correct
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
removeMailboxMessageAfterProcessing();
trade.setState(Trade.State.OFFERER_RECEIVED_DEPOSIT_TX_PUBLISHED_MSG);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of org.bitcoinj.core.Transaction in project bitsquare by bitsquare.
the class CreateOfferFeeTx method run.
@Override
protected void run() {
try {
runInterceptHook();
NodeAddress selectedArbitratorNodeAddress = ArbitrationSelectionRule.select(model.user.getAcceptedArbitratorAddresses(), model.offer);
log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
Arbitrator selectedArbitrator = model.user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
checkNotNull(selectedArbitrator, "selectedArbitrator must not be null at CreateOfferFeeTx");
WalletService walletService = model.walletService;
String id = model.offer.getId();
Address fundingAddress = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING).getAddress();
Address reservedForTradeAddress = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE).getAddress();
Address changeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
Transaction transaction = model.tradeWalletService.createTradingFeeTx(fundingAddress, reservedForTradeAddress, changeAddress, model.reservedFundsForOffer, model.useSavingsWallet, FeePolicy.getCreateOfferFee(), selectedArbitrator.getBtcAddress());
// We assume there will be no tx malleability. We add a check later in case the published offer has a different hash.
// As the txId is part of the offer and therefore change the hash data we need to be sure to have no
// tx malleability
model.offer.setOfferFeePaymentTxID(transaction.getHashAsString());
model.setTransaction(transaction);
complete();
} catch (Throwable t) {
model.offer.setErrorMessage("An error occurred.\n" + "Error message:\n" + t.getMessage());
failed(t);
}
}
Aggregations