use of bisq.core.btc.wallet.BtcWalletService in project bisq-core by bisq-network.
the class MakerCreateAndSignContract method run.
@Override
protected void run() {
try {
runInterceptHook();
Preconditions.checkNotNull(trade.getTakerFeeTxId(), "trade.getTakeOfferFeeTxId() must not be null");
TradingPeer taker = processModel.getTradingPeer();
PaymentAccountPayload makerPaymentAccountPayload = processModel.getPaymentAccountPayload(trade);
checkNotNull(makerPaymentAccountPayload, "makerPaymentAccountPayload must not be null");
PaymentAccountPayload takerPaymentAccountPayload = taker.getPaymentAccountPayload();
boolean isBuyerMakerAndSellerTaker = trade instanceof BuyerAsMakerTrade;
NodeAddress buyerNodeAddress = isBuyerMakerAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
NodeAddress sellerNodeAddress = isBuyerMakerAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
BtcWalletService walletService = processModel.getBtcWalletService();
String id = processModel.getOffer().getId();
checkArgument(!walletService.getAddressEntry(id, AddressEntry.Context.MULTI_SIG).isPresent(), "addressEntry must not be set here.");
AddressEntry makerAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG);
byte[] makerMultiSigPubKey = makerAddressEntry.getPubKey();
AddressEntry takerAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT);
checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
Contract contract = new Contract(processModel.getOffer().getOfferPayload(), trade.getTradeAmount().value, trade.getTradePrice().getValue(), trade.getTakerFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), trade.getMediatorNodeAddress(), isBuyerMakerAndSellerTaker, processModel.getAccountId(), taker.getAccountId(), makerPaymentAccountPayload, takerPaymentAccountPayload, processModel.getPubKeyRing(), taker.getPubKeyRing(), takerAddressEntry.getAddressString(), taker.getPayoutAddressString(), makerMultiSigPubKey, taker.getMultiSigPubKey());
String contractAsJson = Utilities.objectToJson(contract);
log.trace("Contract as json:{}", contractAsJson);
String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
trade.setContract(contract);
trade.setContractAsJson(contractAsJson);
trade.setMakerContractSignature(signature);
processModel.setMyMultiSigPubKey(makerMultiSigPubKey);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of bisq.core.btc.wallet.BtcWalletService 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.btc.wallet.BtcWalletService in project bisq-core by bisq-network.
the class MakerSetupDepositTxListener method run.
@Override
protected void run() {
try {
runInterceptHook();
if (trade.getDepositTx() == null && processModel.getPreparedDepositTx() != null) {
BtcWalletService walletService = processModel.getBtcWalletService();
final NetworkParameters params = walletService.getParams();
Transaction preparedDepositTx = new Transaction(params, processModel.getPreparedDepositTx());
checkArgument(!preparedDepositTx.getOutputs().isEmpty(), "preparedDepositTx.getOutputs() must not be empty");
Address depositTxAddress = preparedDepositTx.getOutput(0).getAddressFromP2SH(params);
final TransactionConfidence confidence = walletService.getConfidenceForAddress(depositTxAddress);
if (isInNetwork(confidence)) {
applyConfidence(confidence);
} else {
confidenceListener = new AddressConfidenceListener(depositTxAddress) {
@Override
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
if (isInNetwork(confidence))
applyConfidence(confidence);
}
};
walletService.addAddressConfidenceListener(confidenceListener);
tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), newValue -> {
if (trade.isDepositPublished()) {
swapReservedForTradeEntry();
// 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);
}
}
use of bisq.core.btc.wallet.BtcWalletService in project bisq-core by bisq-network.
the class SellerSignAndFinalizePayoutTx method run.
@Override
protected void run() {
try {
runInterceptHook();
checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
Offer offer = trade.getOffer();
TradingPeer tradingPeer = processModel.getTradingPeer();
BtcWalletService walletService = processModel.getBtcWalletService();
String id = processModel.getOffer().getId();
final byte[] buyerSignature = tradingPeer.getSignature();
Coin buyerPayoutAmount = offer.getBuyerSecurityDeposit().add(trade.getTradeAmount());
Coin sellerPayoutAmount = offer.getSellerSecurityDeposit();
final String buyerPayoutAddressString = tradingPeer.getPayoutAddressString();
String sellerPayoutAddressString = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT).getAddressString();
final byte[] buyerMultiSigPubKey = tradingPeer.getMultiSigPubKey();
byte[] sellerMultiSigPubKey = processModel.getMyMultiSigPubKey();
Optional<AddressEntry> MultiSigAddressEntryOptional = walletService.getAddressEntry(id, AddressEntry.Context.MULTI_SIG);
checkArgument(MultiSigAddressEntryOptional.isPresent() && Arrays.equals(sellerMultiSigPubKey, MultiSigAddressEntryOptional.get().getPubKey()), "sellerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
DeterministicKey multiSigKeyPair = walletService.getMultiSigKeyPair(id, sellerMultiSigPubKey);
Transaction transaction = processModel.getTradeWalletService().sellerSignsAndFinalizesPayoutTx(trade.getDepositTx(), buyerSignature, buyerPayoutAmount, sellerPayoutAmount, buyerPayoutAddressString, sellerPayoutAddressString, multiSigKeyPair, buyerMultiSigPubKey, sellerMultiSigPubKey, trade.getArbitratorBtcPubKey());
trade.setPayoutTx(transaction);
walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.MULTI_SIG);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of bisq.core.btc.wallet.BtcWalletService in project bisq-core by bisq-network.
the class SellerAsTakerCreatesDepositTxInputs method run.
@Override
protected void run() {
try {
runInterceptHook();
if (trade.getTradeAmount() != null) {
Coin txFee = trade.getTxFee();
Coin takerInputAmount = trade.getOffer().getSellerSecurityDeposit().add(txFee).add(txFee).add(trade.getTradeAmount());
BtcWalletService walletService = processModel.getBtcWalletService();
Address takersAddress = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.RESERVED_FOR_TRADE).getAddress();
Address takersChangeAddress = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE).getAddress();
InputsAndChangeOutput result = processModel.getTradeWalletService().takerCreatesDepositsTxInputs(takerInputAmount, txFee, takersAddress, takersChangeAddress);
processModel.setRawTransactionInputs(result.rawTransactionInputs);
processModel.setChangeOutputValue(result.changeOutputValue);
processModel.setChangeOutputAddress(result.changeOutputAddress);
complete();
} else {
failed("trade.getTradeAmount() = null");
}
} catch (Throwable t) {
failed(t);
}
}
Aggregations