use of io.bitsquare.payment.PaymentAccountContractData in project bitsquare by bitsquare.
the class CreateAndSignContract method run.
@Override
protected void run() {
try {
runInterceptHook();
checkNotNull(trade.getTakeOfferFeeTxId(), "trade.getTakeOfferFeeTxId() must not be null");
TradingPeer taker = processModel.tradingPeer;
PaymentAccountContractData offererPaymentAccountContractData = processModel.getPaymentAccountContractData(trade);
checkNotNull(offererPaymentAccountContractData, "offererPaymentAccountContractData must not be null");
PaymentAccountContractData takerPaymentAccountContractData = taker.getPaymentAccountContractData();
boolean isBuyerOffererAndSellerTaker = trade instanceof BuyerAsOffererTrade;
NodeAddress buyerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
NodeAddress sellerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
log.debug("isBuyerOffererAndSellerTaker " + isBuyerOffererAndSellerTaker);
log.debug("buyerAddress " + buyerNodeAddress);
log.debug("sellerAddress " + sellerNodeAddress);
WalletService walletService = processModel.getWalletService();
AddressEntry takerAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
AddressEntry offererAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
Contract contract = new Contract(processModel.getOffer(), trade.getTradeAmount(), trade.getTradePrice(), trade.getTakeOfferFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), isBuyerOffererAndSellerTaker, processModel.getAccountId(), taker.getAccountId(), offererPaymentAccountContractData, takerPaymentAccountContractData, processModel.getPubKeyRing(), taker.getPubKeyRing(), takerAddressEntry.getAddressString(), taker.getPayoutAddressString(), offererAddressEntry.getPubKey(), taker.getMultiSigPubKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
trade.setContract(contract);
trade.setContractAsJson(contractAsJson);
trade.setOffererContractSignature(signature);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.payment.PaymentAccountContractData in project bitsquare by bitsquare.
the class ProcessPayDepositRequest method run.
@Override
protected void run() {
try {
runInterceptHook();
log.debug("current trade state " + trade.getState());
PayDepositRequest payDepositRequest = (PayDepositRequest) processModel.getTradeMessage();
checkNotNull(payDepositRequest);
checkTradeId(processModel.getId(), payDepositRequest);
PaymentAccountContractData paymentAccountContractData = checkNotNull(payDepositRequest.takerPaymentAccountContractData);
final PaymentAccountFilter[] appliedPaymentAccountFilter = new PaymentAccountFilter[1];
if (processModel.isPeersPaymentAccountDataAreBanned(paymentAccountContractData, appliedPaymentAccountFilter)) {
failed("Other trader is banned by his trading account data.\n" + "paymentAccountContractData=" + paymentAccountContractData.getPaymentDetails() + "\n" + "banFilter=" + appliedPaymentAccountFilter[0].toString());
return;
}
processModel.tradingPeer.setPaymentAccountContractData(paymentAccountContractData);
processModel.tradingPeer.setRawTransactionInputs(checkNotNull(payDepositRequest.rawTransactionInputs));
checkArgument(payDepositRequest.rawTransactionInputs.size() > 0);
processModel.tradingPeer.setChangeOutputValue(payDepositRequest.changeOutputValue);
if (payDepositRequest.changeOutputAddress != null)
processModel.tradingPeer.setChangeOutputAddress(payDepositRequest.changeOutputAddress);
processModel.tradingPeer.setMultiSigPubKey(checkNotNull(payDepositRequest.takerMultiSigPubKey));
processModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(payDepositRequest.takerPayoutAddressString));
processModel.tradingPeer.setPubKeyRing(checkNotNull(payDepositRequest.takerPubKeyRing));
processModel.tradingPeer.setAccountId(nonEmptyStringOf(payDepositRequest.takerAccountId));
trade.setTakeOfferFeeTxId(nonEmptyStringOf(payDepositRequest.takeOfferFeeTxId));
processModel.setTakerAcceptedArbitratorNodeAddresses(checkNotNull(payDepositRequest.acceptedArbitratorNodeAddresses));
if (payDepositRequest.acceptedArbitratorNodeAddresses.isEmpty())
failed("acceptedArbitratorNames must not be empty");
trade.applyArbitratorNodeAddress(checkNotNull(payDepositRequest.arbitratorNodeAddress));
try {
long takersTradePrice = payDepositRequest.tradePrice;
trade.getOffer().checkTradePriceTolerance(takersTradePrice);
trade.setTradePrice(takersTradePrice);
} catch (TradePriceOutOfToleranceException e) {
failed(e.getMessage());
} catch (Throwable e2) {
failed(e2);
}
checkArgument(payDepositRequest.tradeAmount > 0);
trade.setTradeAmount(Coin.valueOf(payDepositRequest.tradeAmount));
// check and update to the latest peer address of our peer if the payDepositRequest is correct
checkArgument(payDepositRequest.getSenderNodeAddress().equals(processModel.getTempTradingPeerNodeAddress()));
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
removeMailboxMessageAfterProcessing();
complete();
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.payment.PaymentAccountContractData in project bitsquare by bitsquare.
the class VerifyAndSignContract method run.
@Override
protected void run() {
try {
runInterceptHook();
checkNotNull(trade.getTakeOfferFeeTxId(), "TakeOfferFeeTxId must not be null");
TradingPeer offerer = processModel.tradingPeer;
PaymentAccountContractData offererPaymentAccountContractData = offerer.getPaymentAccountContractData();
PaymentAccountContractData takerPaymentAccountContractData = processModel.getPaymentAccountContractData(trade);
boolean isBuyerOffererAndSellerTaker = trade instanceof SellerAsTakerTrade;
NodeAddress buyerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
NodeAddress sellerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
log.debug("isBuyerOffererAndSellerTaker " + isBuyerOffererAndSellerTaker);
log.debug("buyerAddress " + buyerNodeAddress);
log.debug("sellerAddress " + sellerNodeAddress);
WalletService walletService = processModel.getWalletService();
AddressEntry takerPayoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
String takerPayoutAddressString = takerPayoutAddressEntry.getAddressString();
AddressEntry takerMultiSigAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
byte[] takerMultiSigPubKey = takerMultiSigAddressEntry.getPubKey();
Contract contract = new Contract(processModel.getOffer(), trade.getTradeAmount(), trade.getTradePrice(), trade.getTakeOfferFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), isBuyerOffererAndSellerTaker, offerer.getAccountId(), processModel.getAccountId(), offererPaymentAccountContractData, takerPaymentAccountContractData, offerer.getPubKeyRing(), processModel.getPubKeyRing(), offerer.getPayoutAddressString(), takerPayoutAddressString, offerer.getMultiSigPubKey(), takerMultiSigPubKey);
String contractAsJson = Utilities.objectToJson(contract);
String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
trade.setContract(contract);
trade.setContractAsJson(contractAsJson);
trade.setTakerContractSignature(signature);
try {
Sig.verify(offerer.getPubKeyRing().getSignaturePubKey(), contractAsJson, offerer.getContractSignature());
} catch (Throwable t) {
failed("Signature verification failed. " + t.getMessage());
}
complete();
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.payment.PaymentAccountContractData in project bitsquare by bitsquare.
the class ProcessPublishDepositTxRequest method run.
@Override
protected void run() {
try {
runInterceptHook();
log.debug("current trade state " + trade.getState());
PublishDepositTxRequest publishDepositTxRequest = (PublishDepositTxRequest) processModel.getTradeMessage();
checkTradeId(processModel.getId(), publishDepositTxRequest);
checkNotNull(publishDepositTxRequest);
PaymentAccountContractData paymentAccountContractData = checkNotNull(publishDepositTxRequest.offererPaymentAccountContractData);
final PaymentAccountFilter[] appliedPaymentAccountFilter = new PaymentAccountFilter[1];
if (processModel.isPeersPaymentAccountDataAreBanned(paymentAccountContractData, appliedPaymentAccountFilter)) {
failed("Other trader is banned by his trading account data.\n" + "paymentAccountContractData=" + paymentAccountContractData.getPaymentDetails() + "\n" + "banFilter=" + appliedPaymentAccountFilter[0].toString());
return;
}
processModel.tradingPeer.setPaymentAccountContractData(paymentAccountContractData);
processModel.tradingPeer.setAccountId(nonEmptyStringOf(publishDepositTxRequest.offererAccountId));
processModel.tradingPeer.setMultiSigPubKey(checkNotNull(publishDepositTxRequest.offererMultiSigPubKey));
processModel.tradingPeer.setContractAsJson(nonEmptyStringOf(publishDepositTxRequest.offererContractAsJson));
processModel.tradingPeer.setContractSignature(nonEmptyStringOf(publishDepositTxRequest.offererContractSignature));
processModel.tradingPeer.setPayoutAddressString(nonEmptyStringOf(publishDepositTxRequest.offererPayoutAddressString));
processModel.tradingPeer.setRawTransactionInputs(checkNotNull(publishDepositTxRequest.offererInputs));
processModel.setPreparedDepositTx(checkNotNull(publishDepositTxRequest.preparedDepositTx));
checkArgument(publishDepositTxRequest.offererInputs.size() > 0);
// update to the latest peer address of our peer if the message is correct
trade.setTradingPeerNodeAddress(processModel.getTempTradingPeerNodeAddress());
complete();
} catch (Throwable t) {
failed(t);
}
}
use of io.bitsquare.payment.PaymentAccountContractData in project bitsquare by bitsquare.
the class ContractWindow method addContent.
private void addContent() {
Contract contract = dispute.getContract();
Offer offer = contract.offer;
List<String> acceptedBanks = offer.getAcceptedBankIds();
boolean showAcceptedBanks = acceptedBanks != null && !acceptedBanks.isEmpty();
List<String> acceptedCountryCodes = offer.getAcceptedCountryCodes();
boolean showAcceptedCountryCodes = acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty();
int rows = 16;
if (dispute.getDepositTxSerialized() != null)
rows++;
if (dispute.getPayoutTxSerialized() != null)
rows++;
if (showAcceptedCountryCodes)
rows++;
if (showAcceptedBanks)
rows++;
PaymentAccountContractData sellerPaymentAccountContractData = contract.getSellerPaymentAccountContractData();
addTitledGroupBg(gridPane, ++rowIndex, rows, "Dispute details");
addLabelTextFieldWithCopyIcon(gridPane, rowIndex, "Offer ID:", offer.getId(), Layout.FIRST_ROW_DISTANCE).second.setMouseTransparent(false);
addLabelTextField(gridPane, ++rowIndex, "Offer date / Trade date:", formatter.formatDateTime(offer.getDate()) + " / " + formatter.formatDateTime(dispute.getTradeDate()));
String currencyCode = offer.getCurrencyCode();
addLabelTextField(gridPane, ++rowIndex, "Trade type:", formatter.getDirectionBothSides(offer.getDirection(), currencyCode));
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPrice(contract.getTradePrice()));
addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
addLabelTextField(gridPane, ++rowIndex, formatter.formatVolumeLabel(currencyCode, ":"), formatter.formatVolumeWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Bitcoin address BTC buyer / BTC seller:", contract.getBuyerPayoutAddressString() + " / " + contract.getSellerPayoutAddressString()).second.setMouseTransparent(false);
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Network address BTC buyer / BTC seller:", contract.getBuyerNodeAddress().getFullAddress() + " / " + contract.getSellerNodeAddress().getFullAddress());
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "No. of disputes BTC buyer / BTC seller:", disputeManager.getNrOfDisputes(true, contract) + " / " + disputeManager.getNrOfDisputes(false, contract));
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "BTC buyer payment details:", BSResources.get(contract.getBuyerPaymentAccountContractData().getPaymentDetails())).second.setMouseTransparent(false);
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "BTC seller payment details:", BSResources.get(sellerPaymentAccountContractData.getPaymentDetails())).second.setMouseTransparent(false);
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Selected arbitrator:", contract.arbitratorNodeAddress.getFullAddress());
if (showAcceptedCountryCodes) {
String countries;
Tooltip tooltip = null;
if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) {
countries = "All Euro countries";
} else {
countries = CountryUtil.getCodesString(acceptedCountryCodes);
tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes));
}
TextField acceptedCountries = addLabelTextField(gridPane, ++rowIndex, "Accepted taker countries:", countries).second;
if (tooltip != null)
acceptedCountries.setTooltip(new Tooltip());
}
if (showAcceptedBanks) {
if (offer.getPaymentMethod().equals(PaymentMethod.SAME_BANK)) {
addLabelTextField(gridPane, ++rowIndex, "Bank name:", acceptedBanks.get(0));
} else if (offer.getPaymentMethod().equals(PaymentMethod.SPECIFIC_BANKS)) {
String value = Joiner.on(", ").join(acceptedBanks);
Tooltip tooltip = new Tooltip("Accepted banks: " + value);
TextField acceptedBanksTextField = addLabelTextField(gridPane, ++rowIndex, "Accepted banks:", value).second;
acceptedBanksTextField.setMouseTransparent(false);
acceptedBanksTextField.setTooltip(tooltip);
}
}
addLabelTxIdTextField(gridPane, ++rowIndex, "Offer fee transaction ID:", offer.getOfferFeePaymentTxID());
addLabelTxIdTextField(gridPane, ++rowIndex, "Trading fee transaction ID:", contract.takeOfferFeeTxID);
if (dispute.getDepositTxSerialized() != null)
addLabelTxIdTextField(gridPane, ++rowIndex, "Deposit transaction ID:", dispute.getDepositTxId());
if (dispute.getPayoutTxSerialized() != null)
addLabelTxIdTextField(gridPane, ++rowIndex, "Payout transaction ID:", dispute.getPayoutTxId());
addLabelTextFieldWithCopyIcon(gridPane, ++rowIndex, "Contract hash:", Utils.HEX.encode(dispute.getContractHash())).second.setMouseTransparent(false);
if (contract != null) {
Button viewContractButton = addLabelButton(gridPane, ++rowIndex, "Contract in JSON format:", "View contract in JSON format", 0).second;
viewContractButton.setDefaultButton(false);
viewContractButton.setOnAction(e -> {
TextArea textArea = new TextArea();
String contractAsJson = dispute.getContractAsJson();
contractAsJson += "\n\nBuyerMultiSigPubKeyHex: " + Utils.HEX.encode(dispute.getContract().getBuyerMultiSigPubKey());
contractAsJson += "\nSellerMultiSigPubKeyHex: " + Utils.HEX.encode(dispute.getContract().getSellerMultiSigPubKey());
textArea.setText(contractAsJson);
textArea.setPrefHeight(50);
textArea.setEditable(false);
textArea.setWrapText(true);
textArea.setPrefSize(800, 600);
Scene viewContractScene = new Scene(textArea);
Stage viewContractStage = new Stage();
viewContractStage.setTitle("Contract for trade with ID: " + dispute.getShortTradeId());
viewContractStage.setScene(viewContractScene);
if (owner == null)
owner = MainView.getRootContainer();
Scene rootScene = owner.getScene();
viewContractStage.initOwner(rootScene.getWindow());
viewContractStage.initModality(Modality.NONE);
viewContractStage.initStyle(StageStyle.UTILITY);
viewContractStage.show();
Window window = rootScene.getWindow();
double titleBarHeight = window.getHeight() - rootScene.getHeight();
viewContractStage.setX(Math.round(window.getX() + (owner.getWidth() - viewContractStage.getWidth()) / 2) + 200);
viewContractStage.setY(Math.round(window.getY() + titleBarHeight + (owner.getHeight() - viewContractStage.getHeight()) / 2) + 50);
});
}
Button cancelButton = addButtonAfterGroup(gridPane, ++rowIndex, "Close");
//TODO app wide focus
//cancelButton.requestFocus();
cancelButton.setOnAction(e -> {
closeHandlerOptional.ifPresent(closeHandler -> closeHandler.run());
hide();
});
}
Aggregations