Search in sources :

Example 1 with PublishDepositTxRequest

use of bisq.core.trade.messages.PublishDepositTxRequest in project bisq-core by bisq-network.

the class MakerSendPublishDepositTxRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        Optional<AddressEntry> addressEntryOptional = walletService.getAddressEntry(id, AddressEntry.Context.MULTI_SIG);
        checkArgument(addressEntryOptional.isPresent(), "addressEntry must be set here.");
        AddressEntry makerPayoutAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
        byte[] makerMultiSigPubKey = processModel.getMyMultiSigPubKey();
        checkArgument(Arrays.equals(makerMultiSigPubKey, addressEntryOptional.get().getPubKey()), "makerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
        final byte[] preparedDepositTx = processModel.getPreparedDepositTx();
        // Maker has to use preparedDepositTx as nonce.
        // He cannot manipulate the preparedDepositTx - so we avoid to have a challenge protocol for passing the nonce we want to get signed.
        final PaymentAccountPayload paymentAccountPayload = checkNotNull(processModel.getPaymentAccountPayload(trade), "processModel.getPaymentAccountPayload(trade) must not be null");
        byte[] sig = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), preparedDepositTx);
        PublishDepositTxRequest message = new PublishDepositTxRequest(processModel.getOfferId(), paymentAccountPayload, processModel.getAccountId(), makerMultiSigPubKey, trade.getContractAsJson(), trade.getMakerContractSignature(), makerPayoutAddressEntry.getAddressString(), preparedDepositTx, processModel.getRawTransactionInputs(), processModel.getMyNodeAddress(), UUID.randomUUID().toString(), sig, new Date().getTime());
        trade.setState(Trade.State.MAKER_SENT_PUBLISH_DEPOSIT_TX_REQUEST);
        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.MAKER_SAW_ARRIVED_PUBLISH_DEPOSIT_TX_REQUEST);
                complete();
            }

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

            @Override
            public void onFault(String errorMessage) {
                log.error("sendEncryptedMailboxMessage failed. message=" + message);
                trade.setState(Trade.State.MAKER_SEND_FAILED_PUBLISH_DEPOSIT_TX_REQUEST);
                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) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) SendMailboxMessageListener(bisq.network.p2p.SendMailboxMessageListener) PublishDepositTxRequest(bisq.core.trade.messages.PublishDepositTxRequest) Date(java.util.Date)

Example 2 with PublishDepositTxRequest

use of bisq.core.trade.messages.PublishDepositTxRequest in project bisq-core by bisq-network.

the class SellerAsTakerProtocol method doApplyMailboxMessage.

// /////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
// /////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
    this.trade = trade;
    if (networkEnvelop instanceof MailboxMessage) {
        NodeAddress peerNodeAddress = ((MailboxMessage) networkEnvelop).getSenderNodeAddress();
        if (networkEnvelop instanceof PublishDepositTxRequest)
            handle((PublishDepositTxRequest) networkEnvelop, peerNodeAddress);
        else if (networkEnvelop instanceof CounterCurrencyTransferStartedMessage)
            handle((CounterCurrencyTransferStartedMessage) networkEnvelop, peerNodeAddress);
        else
            log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
    }
}
Also used : CounterCurrencyTransferStartedMessage(bisq.core.trade.messages.CounterCurrencyTransferStartedMessage) SellerProcessCounterCurrencyTransferStartedMessage(bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage) NodeAddress(bisq.network.p2p.NodeAddress) MailboxMessage(bisq.network.p2p.MailboxMessage) TakerProcessPublishDepositTxRequest(bisq.core.trade.protocol.tasks.taker.TakerProcessPublishDepositTxRequest) PublishDepositTxRequest(bisq.core.trade.messages.PublishDepositTxRequest)

Example 3 with PublishDepositTxRequest

use of bisq.core.trade.messages.PublishDepositTxRequest in project bisq-core by bisq-network.

the class TakerProcessPublishDepositTxRequest method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        log.debug("current trade state " + trade.getState());
        PublishDepositTxRequest publishDepositTxRequest = (PublishDepositTxRequest) processModel.getTradeMessage();
        checkTradeId(processModel.getOfferId(), publishDepositTxRequest);
        checkNotNull(publishDepositTxRequest);
        final TradingPeer tradingPeer = processModel.getTradingPeer();
        tradingPeer.setPaymentAccountPayload(checkNotNull(publishDepositTxRequest.getMakerPaymentAccountPayload()));
        tradingPeer.setAccountId(nonEmptyStringOf(publishDepositTxRequest.getMakerAccountId()));
        tradingPeer.setMultiSigPubKey(checkNotNull(publishDepositTxRequest.getMakerMultiSigPubKey()));
        tradingPeer.setContractAsJson(nonEmptyStringOf(publishDepositTxRequest.getMakerContractAsJson()));
        tradingPeer.setContractSignature(nonEmptyStringOf(publishDepositTxRequest.getMakerContractSignature()));
        tradingPeer.setPayoutAddressString(nonEmptyStringOf(publishDepositTxRequest.getMakerPayoutAddressString()));
        tradingPeer.setRawTransactionInputs(checkNotNull(publishDepositTxRequest.getMakerInputs()));
        final byte[] preparedDepositTx = publishDepositTxRequest.getPreparedDepositTx();
        processModel.setPreparedDepositTx(checkNotNull(preparedDepositTx));
        // Maker has to sign preparedDepositTx. He cannot manipulate the preparedDepositTx - so we avoid to have a
        // challenge protocol for passing the nonce we want to get signed.
        tradingPeer.setAccountAgeWitnessNonce(publishDepositTxRequest.getPreparedDepositTx());
        tradingPeer.setAccountAgeWitnessSignature(publishDepositTxRequest.getAccountAgeWitnessSignatureOfPreparedDepositTx());
        tradingPeer.setCurrentDate(publishDepositTxRequest.getCurrentDate());
        checkArgument(publishDepositTxRequest.getMakerInputs().size() > 0);
        // update to the latest peer address of our peer if the message is correct
        trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
        trade.setState(Trade.State.TAKER_RECEIVED_PUBLISH_DEPOSIT_TX_REQUEST);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : TradingPeer(bisq.core.trade.protocol.TradingPeer) PublishDepositTxRequest(bisq.core.trade.messages.PublishDepositTxRequest)

Example 4 with PublishDepositTxRequest

use of bisq.core.trade.messages.PublishDepositTxRequest in project bisq-core by bisq-network.

the class BuyerAsTakerProtocol method doApplyMailboxMessage.

// /////////////////////////////////////////////////////////////////////////////////////////
// Mailbox
// /////////////////////////////////////////////////////////////////////////////////////////
@Override
public void doApplyMailboxMessage(NetworkEnvelope networkEnvelop, Trade trade) {
    this.trade = trade;
    final NodeAddress senderNodeAddress = ((MailboxMessage) networkEnvelop).getSenderNodeAddress();
    if (networkEnvelop instanceof PublishDepositTxRequest)
        handle((PublishDepositTxRequest) networkEnvelop, senderNodeAddress);
    else if (networkEnvelop instanceof PayoutTxPublishedMessage) {
        handle((PayoutTxPublishedMessage) networkEnvelop, senderNodeAddress);
    } else
        log.error("We received an unhandled MailboxMessage" + networkEnvelop.toString());
}
Also used : PayoutTxPublishedMessage(bisq.core.trade.messages.PayoutTxPublishedMessage) BuyerProcessPayoutTxPublishedMessage(bisq.core.trade.protocol.tasks.buyer.BuyerProcessPayoutTxPublishedMessage) NodeAddress(bisq.network.p2p.NodeAddress) MailboxMessage(bisq.network.p2p.MailboxMessage) TakerProcessPublishDepositTxRequest(bisq.core.trade.protocol.tasks.taker.TakerProcessPublishDepositTxRequest) PublishDepositTxRequest(bisq.core.trade.messages.PublishDepositTxRequest)

Aggregations

PublishDepositTxRequest (bisq.core.trade.messages.PublishDepositTxRequest)4 TakerProcessPublishDepositTxRequest (bisq.core.trade.protocol.tasks.taker.TakerProcessPublishDepositTxRequest)2 MailboxMessage (bisq.network.p2p.MailboxMessage)2 NodeAddress (bisq.network.p2p.NodeAddress)2 AddressEntry (bisq.core.btc.AddressEntry)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 PaymentAccountPayload (bisq.core.payment.payload.PaymentAccountPayload)1 CounterCurrencyTransferStartedMessage (bisq.core.trade.messages.CounterCurrencyTransferStartedMessage)1 PayoutTxPublishedMessage (bisq.core.trade.messages.PayoutTxPublishedMessage)1 TradingPeer (bisq.core.trade.protocol.TradingPeer)1 BuyerProcessPayoutTxPublishedMessage (bisq.core.trade.protocol.tasks.buyer.BuyerProcessPayoutTxPublishedMessage)1 SellerProcessCounterCurrencyTransferStartedMessage (bisq.core.trade.protocol.tasks.seller.SellerProcessCounterCurrencyTransferStartedMessage)1 SendMailboxMessageListener (bisq.network.p2p.SendMailboxMessageListener)1 Date (java.util.Date)1