Search in sources :

Example 1 with Contract

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 "";
    }
}
Also used : Trade(io.bitsquare.trade.Trade) Offer(io.bitsquare.trade.offer.Offer) Contract(io.bitsquare.trade.Contract)

Example 2 with Contract

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);
    }
}
Also used : PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) TradingPeer(io.bitsquare.trade.protocol.trade.TradingPeer) AddressEntry(io.bitsquare.btc.AddressEntry) SellerAsTakerTrade(io.bitsquare.trade.SellerAsTakerTrade) NodeAddress(io.bitsquare.p2p.NodeAddress) Contract(io.bitsquare.trade.Contract) WalletService(io.bitsquare.btc.WalletService)

Example 3 with Contract

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);
    }
}
Also used : PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) TradingPeer(io.bitsquare.trade.protocol.trade.TradingPeer) AddressEntry(io.bitsquare.btc.AddressEntry) NodeAddress(io.bitsquare.p2p.NodeAddress) Contract(io.bitsquare.trade.Contract) BuyerAsOffererTrade(io.bitsquare.trade.BuyerAsOffererTrade) WalletService(io.bitsquare.btc.WalletService)

Example 4 with Contract

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())));
}
Also used : ExchangeRate(org.bitcoinj.utils.ExchangeRate) Contract(io.bitsquare.trade.Contract)

Example 5 with Contract

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);
}
Also used : Coin(org.bitcoinj.core.Coin) Contract(io.bitsquare.trade.Contract)

Aggregations

Contract (io.bitsquare.trade.Contract)13 NodeAddress (io.bitsquare.p2p.NodeAddress)5 PaymentAccountContractData (io.bitsquare.payment.PaymentAccountContractData)4 AddressEntry (io.bitsquare.btc.AddressEntry)3 SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)3 Offer (io.bitsquare.trade.offer.Offer)3 Button (javafx.scene.control.Button)3 Tooltip (javafx.scene.control.Tooltip)3 WalletService (io.bitsquare.btc.WalletService)2 PubKeyRing (io.bitsquare.common.crypto.PubKeyRing)2 TextFieldWithCopyIcon (io.bitsquare.gui.components.TextFieldWithCopyIcon)2 Trade (io.bitsquare.trade.Trade)2 TradingPeer (io.bitsquare.trade.protocol.trade.TradingPeer)2 Scene (javafx.scene.Scene)2 TextArea (javafx.scene.control.TextArea)2 TextField (javafx.scene.control.TextField)2 Stage (javafx.stage.Stage)2 Window (javafx.stage.Window)2 ExchangeRate (org.bitcoinj.utils.ExchangeRate)2 DisputeResult (io.bitsquare.arbitration.DisputeResult)1