Search in sources :

Example 21 with AddressEntry

use of bisq.core.btc.AddressEntry in project bisq-desktop by bisq-network.

the class ArbitratorRegistrationViewModel method onRegister.

void onRegister(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
    updateDisableStates();
    if (allDataValid) {
        AddressEntry arbitratorDepositAddressEntry = walletService.getOrCreateAddressEntry(AddressEntry.Context.ARBITRATOR);
        String registrationSignature = arbitratorManager.signStorageSignaturePubKey(registrationKey);
        // TODO not impl in UI
        String emailAddress = null;
        @SuppressWarnings("ConstantConditions") Arbitrator arbitrator = new Arbitrator(p2PService.getAddress(), arbitratorDepositAddressEntry.getPubKey(), arbitratorDepositAddressEntry.getAddressString(), keyRing.getPubKeyRing(), new ArrayList<>(languageCodes), new Date().getTime(), registrationKey.getPubKey(), registrationSignature, emailAddress, null, null);
        arbitratorManager.addArbitrator(arbitrator, () -> {
            updateDisableStates();
            resultHandler.handleResult();
        }, (errorMessage) -> {
            updateDisableStates();
            errorMessageHandler.handleErrorMessage(errorMessage);
        });
    }
}
Also used : AddressEntry(bisq.core.btc.AddressEntry) Arbitrator(bisq.core.arbitration.Arbitrator) Date(java.util.Date)

Example 22 with AddressEntry

use of bisq.core.btc.AddressEntry in project bisq-desktop by bisq-network.

the class DisputeSummaryWindow method addButtons.

private void addButtons(Contract contract) {
    Tuple2<Button, Button> tuple = add2ButtonsAfterGroup(gridPane, ++rowIndex, Res.get("disputeSummaryWindow.close.button"), Res.get("shared.cancel"));
    Button closeTicketButton = tuple.first;
    closeTicketButton.disableProperty().bind(Bindings.createBooleanBinding(() -> tradeAmountToggleGroup.getSelectedToggle() == null || summaryNotesTextArea.getText() == null || summaryNotesTextArea.getText().length() == 0 || !isPayoutAmountValid(), tradeAmountToggleGroup.selectedToggleProperty(), summaryNotesTextArea.textProperty(), buyerPayoutAmountInputTextField.textProperty(), sellerPayoutAmountInputTextField.textProperty()));
    Button cancelButton = tuple.second;
    final Dispute finalPeersDispute = peersDisputeOptional.get();
    closeTicketButton.setOnAction(e -> {
        if (dispute.getDepositTxSerialized() != null) {
            try {
                AddressEntry arbitratorAddressEntry = walletService.getOrCreateAddressEntry(AddressEntry.Context.ARBITRATOR);
                disputeResult.setArbitratorPubKey(walletService.getOrCreateAddressEntry(AddressEntry.Context.ARBITRATOR).getPubKey());
                /* byte[] depositTxSerialized,
                    Coin buyerPayoutAmount,
                    Coin sellerPayoutAmount,
                    Coin arbitratorPayoutAmount,
                    String buyerAddressString,
                    String sellerAddressString,
                    AddressEntry arbitratorAddressEntry,
                    byte[] buyerPubKey,
                    byte[] sellerPubKey,
                    byte[] arbitratorPubKey)
                    */
                byte[] arbitratorSignature = tradeWalletService.arbitratorSignsDisputedPayoutTx(dispute.getDepositTxSerialized(), disputeResult.getBuyerPayoutAmount(), disputeResult.getSellerPayoutAmount(), contract.getBuyerPayoutAddressString(), contract.getSellerPayoutAddressString(), arbitratorAddressEntry.getKeyPair(), contract.getBuyerMultiSigPubKey(), contract.getSellerMultiSigPubKey(), arbitratorAddressEntry.getPubKey());
                disputeResult.setArbitratorSignature(arbitratorSignature);
                closeTicketButton.disableProperty().unbind();
                dispute.setDisputeResult(disputeResult);
                disputeResult.setLoserPublisher(isLoserPublisherCheckBox.isSelected());
                disputeResult.setCloseDate(new Date());
                String text = Res.get("disputeSummaryWindow.close.msg", formatter.formatDateTime(disputeResult.getCloseDate()), role, formatter.booleanToYesNo(disputeResult.tamperProofEvidenceProperty().get()), role, formatter.booleanToYesNo(disputeResult.idVerificationProperty().get()), role, formatter.booleanToYesNo(disputeResult.screenCastProperty().get()), formatter.formatCoinWithCode(disputeResult.getBuyerPayoutAmount()), formatter.formatCoinWithCode(disputeResult.getSellerPayoutAmount()), disputeResult.summaryNotesProperty().get());
                dispute.setIsClosed(true);
                disputeManager.sendDisputeResultMessage(disputeResult, dispute, text);
                if (!finalPeersDispute.isClosed())
                    UserThread.runAfter(() -> new Popup<>().attention(Res.get("disputeSummaryWindow.close.closePeer")).show(), Transitions.DEFAULT_DURATION, TimeUnit.MILLISECONDS);
                hide();
                finalizeDisputeHandlerOptional.ifPresent(Runnable::run);
            } catch (AddressFormatException | TransactionVerificationException e2) {
                e2.printStackTrace();
            }
        } else {
            log.warn("dispute.getDepositTxSerialized is null");
        }
    });
    cancelButton.setOnAction(e -> {
        dispute.setDisputeResult(disputeResult);
        hide();
    });
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) Button(javafx.scene.control.Button) AutoTooltipRadioButton(bisq.desktop.components.AutoTooltipRadioButton) RadioButton(javafx.scene.control.RadioButton) AddressEntry(bisq.core.btc.AddressEntry) TransactionVerificationException(bisq.core.btc.exceptions.TransactionVerificationException) Popup(bisq.desktop.main.overlays.popups.Popup) Dispute(bisq.core.arbitration.Dispute) Date(java.util.Date)

Example 23 with AddressEntry

use of bisq.core.btc.AddressEntry in project bisq-core by bisq-network.

the class SellerAsMakerCreatesAndSignsDepositTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        TradingPeer tradingPeer = processModel.getTradingPeer();
        final Offer offer = trade.getOffer();
        // params
        final boolean makerIsBuyer = false;
        final byte[] contractHash = Hash.getSha256Hash(trade.getContractAsJson());
        trade.setContractHash(contractHash);
        log.debug("\n\n------------------------------------------------------------\n" + "Contract as json\n" + trade.getContractAsJson() + "\n------------------------------------------------------------\n");
        final Coin makerInputAmount = offer.getSellerSecurityDeposit().add(trade.getTradeAmount());
        Optional<AddressEntry> addressEntryOptional = walletService.getAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        checkArgument(addressEntryOptional.isPresent(), "addressEntryOptional must be present");
        AddressEntry makerMultiSigAddressEntry = addressEntryOptional.get();
        makerMultiSigAddressEntry.setCoinLockedInMultiSig(makerInputAmount);
        walletService.saveAddressEntryList();
        final Coin msOutputAmount = makerInputAmount.add(trade.getTxFee()).add(offer.getBuyerSecurityDeposit());
        final List<RawTransactionInput> takerRawTransactionInputs = tradingPeer.getRawTransactionInputs();
        final long takerChangeOutputValue = tradingPeer.getChangeOutputValue();
        final String takerChangeAddressString = tradingPeer.getChangeOutputAddress();
        final Address makerAddress = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE).getAddress();
        final Address makerChangeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
        final byte[] buyerPubKey = tradingPeer.getMultiSigPubKey();
        final byte[] sellerPubKey = processModel.getMyMultiSigPubKey();
        checkArgument(Arrays.equals(sellerPubKey, makerMultiSigAddressEntry.getPubKey()), "sellerPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
        final byte[] arbitratorBtcPubKey = trade.getArbitratorBtcPubKey();
        PreparedDepositTxAndMakerInputs result = processModel.getTradeWalletService().makerCreatesAndSignsDepositTx(makerIsBuyer, contractHash, makerInputAmount, msOutputAmount, takerRawTransactionInputs, takerChangeOutputValue, takerChangeAddressString, makerAddress, makerChangeAddress, buyerPubKey, sellerPubKey, arbitratorBtcPubKey);
        processModel.setPreparedDepositTx(result.depositTransaction);
        processModel.setRawTransactionInputs(result.rawMakerInputs);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Address(org.bitcoinj.core.Address) AddressEntry(bisq.core.btc.AddressEntry) RawTransactionInput(bisq.core.btc.data.RawTransactionInput) Coin(org.bitcoinj.core.Coin) TradingPeer(bisq.core.trade.protocol.TradingPeer) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) Offer(bisq.core.offer.Offer) PreparedDepositTxAndMakerInputs(bisq.core.btc.data.PreparedDepositTxAndMakerInputs)

Example 24 with AddressEntry

use of bisq.core.btc.AddressEntry in project bisq-core by bisq-network.

the class CreateTakerFeeTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        User user = processModel.getUser();
        NodeAddress selectedArbitratorNodeAddress = ArbitratorSelectionRule.select(user.getAcceptedArbitratorAddresses(), processModel.getOffer());
        log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
        Arbitrator selectedArbitrator = user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
        checkNotNull(selectedArbitrator, "selectedArbitrator must not be null at CreateTakeOfferFeeTx");
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        AddressEntry addressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING);
        AddressEntry reservedForTradeAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
        AddressEntry changeAddressEntry = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE);
        Address fundingAddress = addressEntry.getAddress();
        Address reservedForTradeAddress = reservedForTradeAddressEntry.getAddress();
        Address changeAddress = changeAddressEntry.getAddress();
        final TradeWalletService tradeWalletService = processModel.getTradeWalletService();
        if (trade.isCurrencyForTakerFeeBtc()) {
            tradeFeeTx = tradeWalletService.createBtcTradingFeeTx(fundingAddress, reservedForTradeAddress, changeAddress, processModel.getFundsNeededForTradeAsLong(), processModel.isUseSavingsWallet(), trade.getTakerFee(), trade.getTxFee(), selectedArbitrator.getBtcAddress(), new FutureCallback<Transaction>() {

                @Override
                public void onSuccess(Transaction transaction) {
                    // we delay one render frame to be sure we don't get called before the method call has
                    // returned (tradeFeeTx would be null in that case)
                    UserThread.execute(() -> {
                        if (!completed) {
                            processModel.setTakeOfferFeeTx(tradeFeeTx);
                            trade.setTakerFeeTxId(tradeFeeTx.getHashAsString());
                            walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.OFFER_FUNDING);
                            trade.setState(Trade.State.TAKER_PUBLISHED_TAKER_FEE_TX);
                            complete();
                        } else {
                            log.warn("We got the onSuccess callback called after the timeout has been triggered a complete().");
                        }
                    });
                }

                @Override
                public void onFailure(@NotNull Throwable t) {
                    if (!completed) {
                        failed(t);
                    } else {
                        log.warn("We got the onFailure callback called after the timeout has been triggered a complete().");
                    }
                }
            });
        } else {
            final BsqWalletService bsqWalletService = processModel.getBsqWalletService();
            Transaction preparedBurnFeeTx = processModel.getBsqWalletService().getPreparedBurnFeeTx(trade.getTakerFee());
            Transaction txWithBsqFee = tradeWalletService.completeBsqTradingFeeTx(preparedBurnFeeTx, fundingAddress, reservedForTradeAddress, changeAddress, processModel.getFundsNeededForTradeAsLong(), processModel.isUseSavingsWallet(), trade.getTxFee());
            Transaction signedTx = processModel.getBsqWalletService().signTx(txWithBsqFee);
            WalletService.checkAllScriptSignaturesForTx(signedTx);
            bsqWalletService.commitTx(signedTx);
            // We need to create another instance, otherwise the tx would trigger an invalid state exception
            // if it gets committed 2 times
            tradeWalletService.commitTx(tradeWalletService.getClonedTransaction(signedTx));
            bsqWalletService.broadcastTx(signedTx, new FutureCallback<Transaction>() {

                @Override
                public void onSuccess(@Nullable Transaction transaction) {
                    if (!completed) {
                        if (transaction != null) {
                            log.debug("Successfully sent tx with id " + transaction.getHashAsString());
                            trade.setTakerFeeTxId(transaction.getHashAsString());
                            processModel.setTakeOfferFeeTx(transaction);
                            walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.OFFER_FUNDING);
                            trade.setState(Trade.State.TAKER_PUBLISHED_TAKER_FEE_TX);
                            complete();
                        }
                    } else {
                        log.warn("We got the onSuccess callback called after the timeout has been triggered a complete().");
                    }
                }

                @Override
                public void onFailure(@NotNull Throwable t) {
                    if (!completed) {
                        log.error(t.toString());
                        t.printStackTrace();
                        trade.setErrorMessage("An error occurred.\n" + "Error message:\n" + t.getMessage());
                        failed(t);
                    } else {
                        log.warn("We got the onFailure callback called after the timeout has been triggered a complete().");
                    }
                }
            });
        }
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : User(bisq.core.user.User) NodeAddress(bisq.network.p2p.NodeAddress) Address(org.bitcoinj.core.Address) AddressEntry(bisq.core.btc.AddressEntry) TradeWalletService(bisq.core.btc.wallet.TradeWalletService) Arbitrator(bisq.core.arbitration.Arbitrator) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) NotNull(org.jetbrains.annotations.NotNull) Transaction(org.bitcoinj.core.Transaction) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) NodeAddress(bisq.network.p2p.NodeAddress) FutureCallback(com.google.common.util.concurrent.FutureCallback)

Example 25 with AddressEntry

use of bisq.core.btc.AddressEntry in project bisq-core by bisq-network.

the class BuyerSendCounterCurrencyTransferStartedMessage method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        BtcWalletService walletService = processModel.getBtcWalletService();
        final String id = processModel.getOfferId();
        AddressEntry payoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        final CounterCurrencyTransferStartedMessage message = new CounterCurrencyTransferStartedMessage(id, payoutAddressEntry.getAddressString(), processModel.getMyNodeAddress(), processModel.getPayoutTxSignature(), trade.getCounterCurrencyTxId(), UUID.randomUUID().toString());
        log.info("Send message to peer. tradeId={}, message{}", id, message);
        trade.setState(Trade.State.BUYER_SENT_FIAT_PAYMENT_INITIATED_MSG);
        processModel.getP2PService().sendEncryptedMailboxMessage(trade.getTradingPeerNodeAddress(), processModel.getTradingPeer().getPubKeyRing(), message, new SendMailboxMessageListener() {

            @Override
            public void onArrived() {
                log.info("Message arrived at peer. tradeId={}", id);
                trade.setState(Trade.State.BUYER_SAW_ARRIVED_FIAT_PAYMENT_INITIATED_MSG);
                complete();
            }

            @Override
            public void onStoredInMailbox() {
                log.info("Message stored in mailbox. tradeId={}", id);
                trade.setState(Trade.State.BUYER_STORED_IN_MAILBOX_FIAT_PAYMENT_INITIATED_MSG);
                complete();
            }

            @Override
            public void onFault(String errorMessage) {
                log.error("sendEncryptedMailboxMessage failed. message=" + message);
                trade.setState(Trade.State.BUYER_SEND_FAILED_FIAT_PAYMENT_INITIATED_MSG);
                appendToErrorMessage("Sending message failed: message=" + message + "\nerrorMessage=" + errorMessage);
                failed(errorMessage);
            }
        });
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : BtcWalletService(bisq.core.btc.wallet.BtcWalletService) AddressEntry(bisq.core.btc.AddressEntry) CounterCurrencyTransferStartedMessage(bisq.core.trade.messages.CounterCurrencyTransferStartedMessage) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener)

Aggregations

AddressEntry (bisq.core.btc.AddressEntry)27 Coin (org.bitcoinj.core.Coin)16 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)15 Transaction (org.bitcoinj.core.Transaction)14 Address (org.bitcoinj.core.Address)8 AddressEntryException (bisq.core.btc.AddressEntryException)7 TradingPeer (bisq.core.trade.protocol.TradingPeer)7 InsufficientFundsException (bisq.core.btc.InsufficientFundsException)6 FeeService (bisq.core.provider.fee.FeeService)6 Preferences (bisq.core.user.Preferences)6 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)5 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)5 FutureCallback (com.google.common.util.concurrent.FutureCallback)5 List (java.util.List)5 Set (java.util.Set)5 DeterministicKey (org.bitcoinj.crypto.DeterministicKey)5 AddressFormatException (org.bitcoinj.core.AddressFormatException)4 SendRequest (org.bitcoinj.wallet.SendRequest)4