Search in sources :

Example 1 with SellerAsTakerTrade

use of io.bitsquare.trade.SellerAsTakerTrade 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)

Aggregations

AddressEntry (io.bitsquare.btc.AddressEntry)1 WalletService (io.bitsquare.btc.WalletService)1 NodeAddress (io.bitsquare.p2p.NodeAddress)1 PaymentAccountContractData (io.bitsquare.payment.PaymentAccountContractData)1 Contract (io.bitsquare.trade.Contract)1 SellerAsTakerTrade (io.bitsquare.trade.SellerAsTakerTrade)1 TradingPeer (io.bitsquare.trade.protocol.trade.TradingPeer)1