use of io.bitsquare.trade.Contract in project bitsquare by bitsquare.
the class PendingTradesViewModel method getMyRole.
//
String getMyRole(PendingTradesListItem item) {
Trade trade = item.getTrade();
Contract contract = trade.getContract();
if (contract != null) {
Offer offer = trade.getOffer();
return formatter.getRole(contract.isBuyerOffererAndSellerTaker(), dataModel.isOfferer(offer), offer.getCurrencyCode());
} else {
return "";
}
}
use of io.bitsquare.trade.Contract 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.trade.Contract 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.trade.Contract in project bitsquare by bitsquare.
the class DisputeSummaryWindow method addInfoPane.
private void addInfoPane() {
Contract contract = dispute.getContract();
addTitledGroupBg(gridPane, ++rowIndex, 16, "Summary");
addLabelTextField(gridPane, rowIndex, "Trade ID:", dispute.getShortTradeId(), Layout.FIRST_ROW_DISTANCE);
addLabelTextField(gridPane, ++rowIndex, "Ticket opening date:", formatter.formatDateTime(dispute.getOpeningDate()));
if (dispute.isDisputeOpenerIsOfferer()) {
if (dispute.isDisputeOpenerIsBuyer())
role = "BTC Buyer/offerer";
else
role = "BTC Seller/offerer";
} else {
if (dispute.isDisputeOpenerIsBuyer())
role = "BTC Buyer/taker";
else
role = "BTC Seller/taker";
}
addLabelTextField(gridPane, ++rowIndex, "Trader's role:", role);
addLabelTextField(gridPane, ++rowIndex, "Trade amount:", formatter.formatCoinWithCode(contract.getTradeAmount()));
addLabelTextField(gridPane, ++rowIndex, "Trade price:", formatter.formatPrice(contract.getTradePrice()));
addLabelTextField(gridPane, ++rowIndex, "Trade volume:", formatter.formatVolumeWithCode(new ExchangeRate(contract.getTradePrice()).coinToFiat(contract.getTradeAmount())));
}
use of io.bitsquare.trade.Contract in project bitsquare by bitsquare.
the class DisputeSummaryWindow method calculatePayoutAmounts.
private void calculatePayoutAmounts(DisputeResult.DisputeFeePolicy feePayment) {
Contract contract = dispute.getContract();
Coin refund = FeePolicy.getSecurityDeposit(dispute.getContract().offer);
Coin winnerRefund;
Coin loserRefund;
switch(feePayment) {
case SPLIT:
winnerRefund = refund.divide(2L);
loserRefund = winnerRefund;
arbitratorPayoutAmount = refund;
break;
case WAIVE:
winnerRefund = refund;
loserRefund = refund;
arbitratorPayoutAmount = Coin.ZERO;
break;
case LOSER:
default:
winnerRefund = refund;
loserRefund = Coin.ZERO;
arbitratorPayoutAmount = refund;
break;
}
winnerPayoutAmount = contract.getTradeAmount().add(winnerRefund);
loserPayoutAmount = loserRefund;
stalematePayoutAmount = contract.getTradeAmount().divide(2L).add(winnerRefund);
}
Aggregations