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